Module: MarilynRPC::Server
- Defined in:
- lib/marilyn-rpc/server.rb
Overview
The server will be used to make incomming connections possible. The server handles the low level networking functions, so that the services don’t have to deal with them. Because of the way eventmachine works you can have as many servers as you want.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Object
initalize the server with connection options.
-
#post_init ⇒ Object
Initialize the first recieving envelope for the connection and create the service cache since each connection gets it’s own service instance.
-
#receive_data(data) ⇒ Object
Handler for the incoming data.
-
#unbind ⇒ Object
Handler for client disconnect.
Instance Method Details
#initialize(options = {}) ⇒ Object
initalize the server with connection options
18 19 20 |
# File 'lib/marilyn-rpc/server.rb', line 18 def initialize( = {}) @secure = [:secure] end |
#post_init ⇒ Object
Initialize the first recieving envelope for the connection and create the service cache since each connection gets it’s own service instance.
24 25 26 27 28 |
# File 'lib/marilyn-rpc/server.rb', line 24 def post_init @envelope = MarilynRPC::Envelope.new @cache = MarilynRPC::ServiceCache.new start_tls if @secure end |
#receive_data(data) ⇒ Object
Handler for the incoming data. EventMachine compatible.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/marilyn-rpc/server.rb', line 32 def receive_data(data) overhang = @envelope.parse!(data) # was massage parsed successfully? if @envelope.finished? # grep the request answer = @cache.call(@envelope) if answer.is_a? String send_data(answer) else answer.connection = self # pass connection for async responses end # initialize the next envelope @envelope.reset! receive_data(overhang) if overhang # reenter the data loop end end |
#unbind ⇒ Object
Handler for client disconnect
52 53 54 |
# File 'lib/marilyn-rpc/server.rb', line 52 def unbind @cache.disconnect! end |