Class: CitrusRpc::RpcServer::Server

Inherits:
Object
  • Object
show all
Includes:
CitrusLoader, Utils::EventEmitter
Defined in:
lib/citrus-rpc/rpc-server/server.rb

Overview

Server

Specifiy remote service interface paths

dirname = File.expand_path File.dirname(__FILE__)
records = [
  { :namespace => 'user', :path => dirname + '/remote/test' }
]

Create a new rpc server and start it

Server.new(:records => records, :port => 3333).start

Instance Method Summary collapse

Methods included from Utils::EventEmitter

#emit, #on, #once

Constructor Details

#initialize(args = {}) ⇒ Server

Create a new rpc server

Parameters:

  • args (Hash) (defaults to: {})

    Options

Options Hash (args):

  • port (Integer)
  • records (Array)

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/citrus-rpc/rpc-server/server.rb', line 37

def initialize args={}
  raise ArgumentError, 'server port empty' unless args[:port]
  raise ArgumentError, 'server port must be bigger than zero' unless args[:port] > 0
  raise ArgumentError, 'records empty' unless args[:records]
  raise ArgumentError, 'records must be an array' unless args[:records].respond_to? :to_a

  @services = {}

  create_namespace args[:records]
  load_remote_services args[:records], args[:context]

  args[:services] = @services

  @gateway = Gateway.new args
  @gateway.on(:error) { |*args| emit :error, *args }
  @gateway.on(:closed) { |*args| emit :closed, *args }
end

Instance Method Details

#startObject

Start the rpc server



56
57
58
# File 'lib/citrus-rpc/rpc-server/server.rb', line 56

def start
  @gateway.start
end

#stopObject

Stop the rpc server



61
62
63
# File 'lib/citrus-rpc/rpc-server/server.rb', line 61

def stop
  @gateway.stop
end