Class: RJR::Nodes::UnixConnection
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- RJR::Nodes::UnixConnection
- Defined in:
- lib/rjr/nodes/unix.rb
Overview
Helper class intialized by eventmachine encapsulating a unix socket connection
Instance Attribute Summary collapse
-
#socketname ⇒ Object
readonly
Returns the value of attribute socketname.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ UnixConnection
constructor
UnixConnection intializer.
-
#receive_data(data) ⇒ Object
EventMachine::Connection#receive_data callback, handle request / response messages.
-
#send_msg(data) ⇒ Object
Send data safely using local connection.
Constructor Details
#initialize(args = {}) ⇒ UnixConnection
UnixConnection intializer
Specify the Unix Node establishing the connection and optionaly socketname which this connection is connected to
31 32 33 34 35 36 37 |
# File 'lib/rjr/nodes/unix.rb', line 31 def initialize(args = {}) @rjr_node = args[:rjr_node] @socketname = args[:socketname] @send_lock = Mutex.new @data = "" end |
Instance Attribute Details
#socketname ⇒ Object (readonly)
Returns the value of attribute socketname.
25 26 27 |
# File 'lib/rjr/nodes/unix.rb', line 25 def socketname @socketname end |
Instance Method Details
#receive_data(data) ⇒ Object
EventMachine::Connection#receive_data callback, handle request / response messages
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rjr/nodes/unix.rb', line 40 def receive_data(data) # a large json-rpc message may be split over multiple packets # (invocations of receive_data) # and multiple messages may be concatinated into one packet @data += data while extracted = JSONParser.extract_json_from(@data) msg, @data = *extracted @rjr_node.send(:handle_message, msg, self) # XXX private method end end |