Class: WhoCan::ConnectionWrapper

Inherits:
Object
  • Object
show all
Includes:
Deferred::Accessors, Logging
Defined in:
lib/who_can/connection_wrapper.rb

Overview

encapsulates the retry and failure detection logic. Used by ConnectionManager

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #logger

Constructor Details

#initialize(config, opts = {}) ⇒ ConnectionWrapper

Returns a new instance of ConnectionWrapper.



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/who_can/connection_wrapper.rb', line 79

def initialize(config, opts={})
  @config = config
  @name             = opts[:name]
  @reconnect_delay  = opts[:reconnect_delay]  || 5
  @shutdown_timeout = opts[:shutdown_timeout] || 2.0

  @ekg          = nil
  @retry_count  = 0
  @amqp_session = nil
  @on_initial_connection_failure_cbs = []
  super()
end

Instance Attribute Details

#amqp_sessionObject (readonly)

Returns the value of attribute amqp_session.



13
14
15
# File 'lib/who_can/connection_wrapper.rb', line 13

def amqp_session
  @amqp_session
end

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/who_can/connection_wrapper.rb', line 13

def config
  @config
end

#ekgObject (readonly)

Returns the value of attribute ekg.



13
14
15
# File 'lib/who_can/connection_wrapper.rb', line 13

def ekg
  @ekg
end

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/who_can/connection_wrapper.rb', line 15

def name
  @name
end

#reconnect_delayObject

how long should we wait between reconnection attempts



18
19
20
# File 'lib/who_can/connection_wrapper.rb', line 18

def reconnect_delay
  @reconnect_delay
end

#shutdown_timeoutObject

how long should we wait between reconnection attempts



18
19
20
# File 'lib/who_can/connection_wrapper.rb', line 18

def shutdown_timeout
  @shutdown_timeout
end

Instance Method Details

#close(*a, &b) ⇒ Object



103
104
105
106
# File 'lib/who_can/connection_wrapper.rb', line 103

def close(*a, &b)
  on_close(&b) # hook deferred into this event
  super(*a)
end

#close!(*a, &b) ⇒ Object



108
109
110
111
# File 'lib/who_can/connection_wrapper.rb', line 108

def close!(*a, &b)
  on_close(&b) # hook deferred into this event
  super(*a)
end

#connect(*a, &b) ⇒ Object

XXX: figure out how to do this in a cleaner fashion



93
94
95
96
# File 'lib/who_can/connection_wrapper.rb', line 93

def connect(*a, &b)
  on_open(&b)
  super(*a)
end

#connect!(*a, &b) ⇒ Object



98
99
100
101
# File 'lib/who_can/connection_wrapper.rb', line 98

def connect!(*a, &b)
  on_open(&b)
  super(*a)
end