Class: Protobuf::Rpc::Connectors::EMClient

Inherits:
EM::Connection
  • Object
show all
Includes:
Logger::LogMethods, Common
Defined in:
lib/protobuf/rpc/connectors/em_client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options={}, &failure_cb)
  @failure_cb = failure_cb
  @options = DEFAULT_OPTIONS.merge(options)
  verify_options
  initialize_stats

  log_debug "[#{log_signature}] Client Initialized: %s" % options.inspect
rescue
  fail(:RPC_ERROR, 'Failed to initialize connection: %s' % $!.message)
end

Instance Attribute Details

#errorObject (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_messageObject (readonly)

Returns the value of attribute error_message.



11
12
13
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 11

def error_message
  @error_message
end

#error_reasonObject (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

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 10

def options
  @options
end

#requestObject (readonly)

Returns the value of attribute request.



10
11
12
# File 'lib/protobuf/rpc/connectors/em_client.rb', line 10

def request
  @request
end

#responseObject (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(options={})
  options = DEFAULT_OPTIONS.merge(options)
  log_debug "[client-#{self}] Connecting to server: %s" % options.inspect
  EM.connect(options[:host], options[:port], self, options)
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