Class: WhoCan::Base
- Inherits:
-
Object
- Object
- WhoCan::Base
- Includes:
- Deferred::Accessors, Logging
- Defined in:
- lib/who_can/base.rb
Instance Attribute Summary collapse
-
#connection_opts ⇒ Object
Returns the value of attribute connection_opts.
Instance Method Summary collapse
- #clear_responder(ping_exchange_name) ⇒ Object
- #close!(&block) ⇒ Object
- #connection(&blk) ⇒ Object (also: #connect!)
-
#initialize(connection_opts = nil) ⇒ Base
constructor
A new instance of Base.
- #new_pinger ⇒ Object
- #new_responder(exchange_name) ⇒ Object
- #on_open(&block) ⇒ Object
- #start_monitoring!(opts = {}) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(connection_opts = nil) ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/who_can/base.rb', line 9 def initialize(connection_opts=nil) @connection_opts = connection_opts @connection = nil if @connection_opts.is_a?(AMQP::Session) @connection = @connection_opts end # logger.debug { "connection_opts: #{@connection_opts.inspect}" } @responders = {} end |
Instance Attribute Details
#connection_opts ⇒ Object
Returns the value of attribute connection_opts.
7 8 9 |
# File 'lib/who_can/base.rb', line 7 def connection_opts @connection_opts end |
Instance Method Details
#clear_responder(ping_exchange_name) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/who_can/base.rb', line 63 def clear_responder(ping_exchange_name) if resp = @responders.delete(ping_exchange_name) resp.close! true end false end |
#close!(&block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/who_can/base.rb', line 48 def close!(&block) unless @connection block.call return end cnx, @connection = @connection, nil @channel = nil on_disconnection(&block) cnx.on_disconnection do on_disconnection.succeed end cnx.close on_disconnection end |
#connection(&blk) ⇒ Object Also known as: connect!
20 21 22 23 24 |
# File 'lib/who_can/base.rb', line 20 def connection(&blk) @connection ||= AMQP.connect(connection_opts || WhoCan.connect_url) on_open(&blk) if blk @connection end |
#new_pinger ⇒ Object
40 41 42 |
# File 'lib/who_can/base.rb', line 40 def new_pinger WhoCan::Pinger.new(connection) end |
#new_responder(exchange_name) ⇒ Object
44 45 46 |
# File 'lib/who_can/base.rb', line 44 def new_responder(exchange_name) WhoCan::Responder.new(connection, exchange_name) end |
#on_open(&block) ⇒ Object
27 28 29 |
# File 'lib/who_can/base.rb', line 27 def on_open(&block) connection.on_open(&block) end |
#start_monitoring!(opts = {}) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/who_can/base.rb', line 31 def start_monitoring!(opts = {}) @ekg = Heartbeater::EKG.new(connection) @ekg.on_heartbeat_failure do on_disconnection.succeed close! end @ekg.start! end |