class Protobuf::Rpc::Client

def initialize(opts={})


})
:request => request
:response_type => "WidgetList",
:request_type => "WidgetFindRequest",
:method => "find",
:service => WidgetService,
client = Client.new({
request = WidgetFindRequest.new

as Client#method_missing defined below.
See Service#client for a more convenient way to create a client, as well
Create a new client with default options (defined in ClientConnection)
def initialize(opts={})
  raise "Invalid client configuration. Service must be defined." if opts[:service].nil?
  @connector = Connector.connector_for_client.new(opts)
  log_debug "[#{log_signature}] Initialized with options: %s" % opts.inspect
end

def log_signature

def log_signature
  @log_signature ||= "client-#{self.class}"
end

def method_missing(method, *params)


end
c.on_failure {|err| ... }
c.on_success {|res| ... }
# `c` in this case is the client object you created above
# This block will be invoked before the request is made
Client.new(:service => WidgetService).find do |c|
# The :find method is not defined by Client which will trigger method_missing

in the wrapper protobuf request.
which will automatically setup the service_class and method_name
Provides a mechanism to call the service method against the client
def method_missing(method, *params)
  service = options[:service]
  unless service.rpcs[service].keys.include?(method)
    log_error "[#{log_signature}] %s#%s not rpc method, passing to super" % [service.name, method.to_s]
    super(method, *params)
  else
    log_debug "[#{log_signature}] %s#%s" % [service.name, method.to_s]
    rpc = service.rpcs[service][method.to_sym]
    options[:request_type] = rpc.request_type
    log_debug "[#{log_signature}] Request Type: %s" % options[:request_type].name
    options[:response_type] = rpc.response_type
    log_debug "[#{log_signature}] Response Type: %s" % options[:response_type].name
    options[:method] = method.to_s
    options[:request] = params[0].is_a?(Hash) ? options[:request_type].new(params[0]) : params[0]
    log_debug "[#{log_signature}] Request Data: %s" % options[:request].inspect
    
    # Call client to setup on_success and on_failure event callbacks
    if block_given?
      log_debug "[#{log_signature}] client setup callback given, invoking"
      yield(self)
    else
      log_debug "[#{log_signature}] no block given for callbacks"
    end

    send_request
  end
end

def on_complete(&complete_cb)


client.on_complete {|obj| ... }
client = Client.new(:service => WidgetService)

Callback is called regardless of :async setting.
Set a complete callback on the client to return the object (self).
def on_complete(&complete_cb)
  @connector.complete_cb = complete_cb 
end

def on_complete=(callable)

def on_complete=(callable)
  if callable != nil && !callable.respond_to?(:call) && callable.arity != 1
    raise "callable must take a single argument and respond to :call"
  end
  
  @connector.complete_cb = callable 
end

def on_failure(&failure_cb)


client.on_failure {|err| ... }
client = Client.new(:service => WidgetService)

Callback is called regardless of :async setting.
is called, success_cb will NOT be called.
error returned by the service, if any. If this callback
Set a failure callback on the client to return the
def on_failure(&failure_cb)
  @connector.failure_cb = failure_cb
end

def on_failure=(callable)

def on_failure=(callable)
  if callable != nil && !callable.respond_to?(:call) && callable.arity != 1
    raise "callable must take a single argument and respond to :call"
  end
  @connector.failure_cb = callable 
end

def on_success(&success_cb)


client.on_success {|res| ... }
client = Client.new(:service => WidgetService)

Callback is called regardless of :async setting.
If this callback is called, failure_cb will NOT be called.
successful response from the service when it is returned.
Set a success callback on the client to return the
def on_success(&success_cb)
  @connector.success_cb = success_cb
end

def on_success=(callable)

def on_success=(callable)
  if callable != nil && !callable.respond_to?(:call) && callable.arity != 1
    raise "callable must take a single argument and respond to :call"
  end
  @connector.success_cb = callable 
end

def send_request


client.send_request

end
puts err.message
client.on_failure do |err|

end
res.widgets.each{|w| puts w.inspect }
client.on_success do |res|

})
:request => request
:response_type => "WidgetList",
:request_type => "WidgetFindRequest",
:method => "find",
:service => WidgetService,
client = Client.new({
request = WidgetFindRequest.new

but is invoked by method_missing (see docs above).
This method is usually never called directly
Send the request to the service through eventmachine.
def send_request
  @connector.send_request
end