Class: Protobuf::Rpc::Connectors::EMClient
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- Protobuf::Rpc::Connectors::EMClient
- Includes:
- Logger::LogMethods, Common
- Defined in:
- lib/protobuf/rpc/connectors/em_client.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#error_reason ⇒ Object
readonly
Returns the value of attribute error_reason.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}, &failure_cb) ⇒ EMClient
constructor
A new instance of EMClient.
-
#on_complete(&complete_cb) ⇒ Object
Completion callback registration.
-
#on_failure(&failure_cb) ⇒ Object
Failure callback registration.
-
#on_success(&success_cb) ⇒ Object
Success callback registration.
- #receive_data(data) ⇒ Object
Methods included from Common
#_send_request, #any_callbacks?, #complete, #data_callback, #fail, #initialize_stats, #log_signature, #parse_response, #post_init, #succeed, #verify_callbacks, #verify_options
Constructor Details
#initialize(options = {}, &failure_cb) ⇒ EMClient
Returns a new instance of EMClient.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 23 def initialize(={}, &failure_cb) @failure_cb = failure_cb @options = DEFAULT_OPTIONS.merge() initialize_stats log_debug "[#{log_signature}] Client Initialized: %s" % .inspect rescue fail(:RPC_ERROR, 'Failed to initialize connection: %s' % $!.) end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
11 12 13 |
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 11 def error @error end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
11 12 13 |
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 11 def @error_message end |
#error_reason ⇒ Object (readonly)
Returns the value of attribute error_reason.
11 12 13 |
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 11 def error_reason @error_reason end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 10 def @options end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
10 11 12 |
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 10 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
10 11 12 |
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 10 def response @response end |
Class Method Details
.connect(options = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 15 def connect(={}) = DEFAULT_OPTIONS.merge() log_debug "[client-#{self}] Connecting to server: %s" % .inspect EM.connect([:host], [:port], self, ) end |
Instance Method Details
#on_complete(&complete_cb) ⇒ Object
Completion callback registration
45 46 47 |
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 45 def on_complete(&complete_cb) @complete_cb = complete_cb end |
#on_failure(&failure_cb) ⇒ Object
Failure callback registration
40 41 42 |
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 40 def on_failure(&failure_cb) @failure_cb = failure_cb end |
#on_success(&success_cb) ⇒ Object
Success callback registration
35 36 37 |
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 35 def on_success(&success_cb) @success_cb = success_cb end |
#receive_data(data) ⇒ Object
49 50 51 52 53 |
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 49 def receive_data(data) log_debug "[#{log_signature}] receive_data: %s" % data @buffer << data parse_response if @buffer.flushed? end |