Class: CitrusRpc::RpcServer::Gateway
- Inherits:
-
Object
- Object
- CitrusRpc::RpcServer::Gateway
- Includes:
- Dispatcher, Utils::EventEmitter
- Defined in:
- lib/citrus-rpc/rpc-server/gateway.rb
Overview
Gateway
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Gateway
constructor
Create a gateway.
-
#start ⇒ Object
Start the gateway.
-
#stop ⇒ Object
Stop the gateway.
Methods included from Utils::EventEmitter
Methods included from Dispatcher
Constructor Details
#initialize(args = {}) ⇒ Gateway
Create a gateway
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/citrus-rpc/rpc-server/gateway.rb', line 27 def initialize args={} @port = args[:port] || 3050 @started = false @stoped = false @acceptor_class = args[:acceptor_class] || WsAcceptor @services = args[:services] @acceptor = @acceptor_class.new(args) { |msg, &block| dispatch msg, @services, &block } end |
Instance Method Details
#start ⇒ Object
Start the gateway
41 42 43 44 45 46 47 48 |
# File 'lib/citrus-rpc/rpc-server/gateway.rb', line 41 def start raise RuntimeError 'gateway already started' if @started @started = true @acceptor.on(:error) { |*args| emit :error, *args } @acceptor.on(:closed) { |*args| emit :closed, *args } @acceptor.listen @port end |
#stop ⇒ Object
Stop the gateway
51 52 53 54 55 |
# File 'lib/citrus-rpc/rpc-server/gateway.rb', line 51 def stop return unless @started && !@stoped @stoped = true @acceptor.close end |