class Protobuf::Rpc::Service

def self.client(options = {})


for all available options.
See Client#initialize and ClientConnection::DEFAULT_OPTIONS
Create a new client for the given service.

Class Methods
#
def self.client(options = {})
  ::Protobuf::Rpc::Client.new({ :service => self,
                                :host => host,
                                :port => port }.merge(options))
end

def self.configure(config = {})


will not have to configure the location each time.
so that any Clients using the Service.client sugar
Useful for system-startup configuration of a service
Allows service-level configuration of location.
def self.configure(config = {})
  self.host = config[:host] if config.key?(:host)
  self.port = config[:port] if config.key?(:port)
end

def self.host


The host location of the service.
def self.host
  @_host ||= DEFAULT_HOST
end

def self.host=(new_host)


The host location setter.
def self.host=(new_host)
  @_host = new_host
end

def self.implemented_services

code
An array of defined service classes that contain implementation
def self.implemented_services
  classes = (self.subclasses || []).select do |subclass|
    subclass.rpcs.any? do |(name, _)|
      subclass.method_defined? name
    end
  end
  classes.map(&:name)
end

def self.located_at(location)


e.g. localhost:0
e.g. 127.0.0.1:9933
Shorthand call to configure, passing a string formatted as hostname:port
def self.located_at(location)
  return if location.nil? || location.downcase.strip !~ /.+:\d+/
  host, port = location.downcase.strip.split ':'
  configure(:host => host, :port => port.to_i)
end

def self.port


The port of the service on the destination server.
def self.port
  @_port ||= DEFAULT_PORT
end

def self.port=(new_port)


The port location setter.
def self.port=(new_port)
  @_port = new_port
end

def self.rpc(method, request_type, response_type)


and not useful for user code.
This methods is only used by the generated service definitions
Define an rpc method with the given request and response types.
def self.rpc(method, request_type, response_type)
  rpcs[method] = RpcMethod.new(method, request_type, response_type)
end

def self.rpc_method?(name)


Check if the given method name is a known rpc endpoint.
def self.rpc_method?(name)
  rpcs.key?(name)
end

def self.rpcs


Hash containing the set of methods defined via `rpc`.
def self.rpcs
  @_rpcs ||= {}
end

def callable_rpc_method(method_name)


is why we wrap the method call).
The returned lambda is expected to be called at a later time (which
to invoke the specified rpc method. Facilitates callback dispatch.
Get a callable object that will be used by the dispatcher

Instance Methods
#
def callable_rpc_method(method_name)
  lambda { run_filters(method_name) }
end

def initialize(env)

for the request.
Initialize a service with the rpc endpoint name and the bytes

Constructor!
#
def initialize(env)
  @env = env.dup # Dup the env so it doesn't change out from under us
  @request = env.request
end

def request_type

def request_type
  @_request_type ||= env.request_type
end

def respond_with(candidate)


object returned by the response reader.
If this method is not called, the response will be the memoized
Sugar to make an rpc method feel like a controller method.
def respond_with(candidate)
  @_response = candidate
end

def response


Response object for this rpc cycle. Not assignable.
def response
  @_response ||= response_type.new
end

def response_type

def response_type
  @_response_type ||= env.response_type
end

def rpc_failed(message)


Automatically fail a service method.
def rpc_failed(message)
  message = message.message if message.respond_to?(:message)
  raise RpcFailed.new(message)
end

def rpc_method?(name)


Convenience method to get back to class method.
def rpc_method?(name)
  self.class.rpc_method?(name)
end

def rpcs


Convenience method to get back to class rpcs hash.
def rpcs
  self.class.rpcs
end