Class: PachubeStream::Connection
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- PachubeStream::Connection
- Includes:
- RequestMethods
- Defined in:
- lib/pachube-stream/connection.rb
Constant Summary collapse
- NF_RECONNECT_START =
0.25
- NF_RECONNECT_ADD =
0.25
- NF_RECONNECT_MAX =
16- RECONNECT_MAX =
320- RETRIES_MAX =
10
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#max_reconnects_callback ⇒ Object
Returns the value of attribute max_reconnects_callback.
-
#nf_last_reconnect ⇒ Object
Returns the value of attribute nf_last_reconnect.
-
#on_error_block(&block) ⇒ Object
Returns the value of attribute on_error_block.
-
#on_init_callback ⇒ Object
Returns the value of attribute on_init_callback.
-
#on_response_block(&block) ⇒ Object
Returns the value of attribute on_response_block.
-
#options ⇒ Object
Returns the value of attribute options.
-
#reconnect_callback ⇒ Object
Returns the value of attribute reconnect_callback.
-
#reconnect_retries ⇒ Object
Returns the value of attribute reconnect_retries.
Class Method Summary collapse
Instance Method Summary collapse
- #client ⇒ Object
- #immediate_reconnect ⇒ Object
-
#initialize(options) ⇒ Connection
constructor
A new instance of Connection.
- #on_max_reconnects(&block) ⇒ Object
- #on_reconnect(&block) ⇒ Object
- #post_init ⇒ Object
- #receive_data(response) ⇒ Object
- #stop ⇒ Object
- #unbind ⇒ Object
Methods included from RequestMethods
#delete, #get, #post, #put, #subscribe, #unsubsribe
Constructor Details
#initialize(options) ⇒ Connection
Returns a new instance of Connection.
28 29 30 31 32 33 34 |
# File 'lib/pachube-stream/connection.rb', line 28 def initialize() = @api_key = [:api_key] @timeout = [:timeout] || 0 @reconnect_retries = 0 @immediate_reconnect = false end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/pachube-stream/connection.rb', line 11 def api_key @api_key end |
#max_reconnects_callback ⇒ Object
Returns the value of attribute max_reconnects_callback.
12 13 14 |
# File 'lib/pachube-stream/connection.rb', line 12 def max_reconnects_callback @max_reconnects_callback end |
#nf_last_reconnect ⇒ Object
Returns the value of attribute nf_last_reconnect.
12 13 14 |
# File 'lib/pachube-stream/connection.rb', line 12 def nf_last_reconnect @nf_last_reconnect end |
#on_error_block(&block) ⇒ Object
Returns the value of attribute on_error_block.
11 12 13 |
# File 'lib/pachube-stream/connection.rb', line 11 def on_error_block @on_error_block end |
#on_init_callback ⇒ Object
Returns the value of attribute on_init_callback.
11 12 13 |
# File 'lib/pachube-stream/connection.rb', line 11 def on_init_callback @on_init_callback end |
#on_response_block(&block) ⇒ Object
Returns the value of attribute on_response_block.
11 12 13 |
# File 'lib/pachube-stream/connection.rb', line 11 def on_response_block @on_response_block end |
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/pachube-stream/connection.rb', line 11 def end |
#reconnect_callback ⇒ Object
Returns the value of attribute reconnect_callback.
12 13 14 |
# File 'lib/pachube-stream/connection.rb', line 12 def reconnect_callback @reconnect_callback end |
#reconnect_retries ⇒ Object
Returns the value of attribute reconnect_retries.
12 13 14 |
# File 'lib/pachube-stream/connection.rb', line 12 def reconnect_retries @reconnect_retries end |
Class Method Details
.connect(options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pachube-stream/connection.rb', line 15 def self.connect( = {}) api_key = [:api_key] raise ArgumentError.new("You need to supply an API Key") unless api_key host = [:host] || "beta.pachube.com" port = [:port] || 8081 EventMachine.connect host, port, self, rescue EventMachine::ConnectionError => e conn = EventMachine::FailedConnection.new(req) conn.error = e. conn.fail conn end |
Instance Method Details
#client ⇒ Object
36 37 38 |
# File 'lib/pachube-stream/connection.rb', line 36 def client @client ||= PachubeStream::Client.new(self, @api_key, ) end |
#immediate_reconnect ⇒ Object
66 67 68 69 70 |
# File 'lib/pachube-stream/connection.rb', line 66 def immediate_reconnect @immediate_reconnect = true @gracefully_closed = false close_connection end |
#on_max_reconnects(&block) ⇒ Object
49 50 51 |
# File 'lib/pachube-stream/connection.rb', line 49 def on_max_reconnects(&block) @max_reconnects_callback = block end |
#on_reconnect(&block) ⇒ Object
45 46 47 |
# File 'lib/pachube-stream/connection.rb', line 45 def on_reconnect(&block) @reconnect_callback = block end |
#post_init ⇒ Object
40 41 42 43 |
# File 'lib/pachube-stream/connection.rb', line 40 def post_init set_comm_inactivity_timeout @timeout if @timeout > 0 @on_inited_callback.call if @on_inited_callback end |
#receive_data(response) ⇒ Object
76 77 78 |
# File 'lib/pachube-stream/connection.rb', line 76 def receive_data(response) client.process_data(response) end |
#stop ⇒ Object
61 62 63 64 |
# File 'lib/pachube-stream/connection.rb', line 61 def stop @gracefully_closed = true close_connection end |
#unbind ⇒ Object
72 73 74 |
# File 'lib/pachube-stream/connection.rb', line 72 def unbind schedule_reconnect unless @gracefully_closed end |