Class: LVS::JsonService::ConnectionManager
- Inherits:
-
Object
- Object
- LVS::JsonService::ConnectionManager
- Defined in:
- lib/lvs/json_service/connection_manager.rb
Class Method Summary collapse
- .create_connection(host, port, options) ⇒ Object
- .get_connection(host, port, options) ⇒ Object
- .reset_all_connections ⇒ Object
- .reset_connection(host, port, options) ⇒ Object
Class Method Details
.create_connection(host, port, options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lvs/json_service/connection_manager.rb', line 25 def self.create_connection(host, port, ) http = Net::HTTP.new(host, port) if [:encrypted] http.use_ssl = true # Self-signed certs give streams of "warning: peer certificate won't be verified in this SSL session" http.verify_mode = OpenSSL::SSL::VERIFY_NONE LVS::JsonService::Logger.debug "Using SSL" if [:auth_cert] LVS::JsonService::Logger.debug "Using Auth" http.cert = OpenSSL::X509::Certificate.new(File.read([:auth_cert])) http.key = OpenSSL::PKey::RSA.new(File.read([:auth_key]), [:auth_key_password]) end end http.open_timeout = [:timeout] || 1 http.read_timeout = [:timeout] || 1 LVS::JsonService::Logger.debug "Connecting" http.start http end |
.get_connection(host, port, options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/lvs/json_service/connection_manager.rb', line 4 def self.get_connection(host, port, ) @@connections ||= {} key = create_key(host, port, ) connection = @@connections[key] if connection.nil? || !connection.started? connection = create_connection(host, port, ) @@connections[key] = connection end connection end |
.reset_all_connections ⇒ Object
21 22 23 |
# File 'lib/lvs/json_service/connection_manager.rb', line 21 def self.reset_all_connections @@connections = {} end |
.reset_connection(host, port, options) ⇒ Object
15 16 17 18 19 |
# File 'lib/lvs/json_service/connection_manager.rb', line 15 def self.reset_connection(host, port, ) @@connections ||= {} key = create_key(host, port, ) @@connections.delete(key) end |