Class: AMQP::Failover::ServerDiscovery
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- AMQP::Failover::ServerDiscovery
- Defined in:
- lib/amqp/failover/server_discovery.rb
Class Attribute Summary collapse
-
.connection ⇒ Object
Returns the value of attribute connection.
Class Method Summary collapse
- .connect(conf) ⇒ Object
- .monitor(conf = {}, retry_interval = nil, &block) ⇒ Object
- .start_monitoring(conf = {}, retry_interval = nil, &block) ⇒ Object
Instance Method Summary collapse
- #connection_completed ⇒ Object
-
#initialize(args) ⇒ ServerDiscovery
constructor
A new instance of ServerDiscovery.
Constructor Details
#initialize(args) ⇒ ServerDiscovery
Returns a new instance of ServerDiscovery.
19 20 21 22 |
# File 'lib/amqp/failover/server_discovery.rb', line 19 def initialize(args) @done = args[:done] @timer = args[:timer] end |
Class Attribute Details
.connection ⇒ Object
Returns the value of attribute connection.
8 9 10 |
# File 'lib/amqp/failover/server_discovery.rb', line 8 def connection @connection end |
Class Method Details
.connect(conf) ⇒ Object
39 40 41 |
# File 'lib/amqp/failover/server_discovery.rb', line 39 def self.connect(conf) EM.connect(conf[:host], conf[:port], self, conf) end |
.monitor(conf = {}, retry_interval = nil, &block) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/amqp/failover/server_discovery.rb', line 11 def self.monitor(conf = {}, retry_interval = nil, &block) if EM.reactor_running? start_monitoring(conf, retry_interval, &block) else EM.run { start_monitoring(conf, retry_interval, &block) } end end |
.start_monitoring(conf = {}, retry_interval = nil, &block) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/amqp/failover/server_discovery.rb', line 30 def self.start_monitoring(conf = {}, retry_interval = nil, &block) conf = conf.clone retry_interval ||= 5 conf[:done] = block conf[:timer] = EM::PeriodicTimer.new(retry_interval) do @connection = connect(conf) end end |
Instance Method Details
#connection_completed ⇒ Object
24 25 26 27 28 |
# File 'lib/amqp/failover/server_discovery.rb', line 24 def connection_completed @done.call @timer.cancel close_connection end |