class RJR::Nodes::UnixConnection

@private Helper class intialized by eventmachine encapsulating a unix socket connection

Attributes

socketname[R]

Public Class Methods

new(args = {}) click to toggle source

UnixConnection intializer

Specify the Unix Node establishing the connection and optionaly socketname which this connection is connected to

# 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

Public Instance Methods

receive_data(data) click to toggle source

EventMachine::Connection#receive_data callback, handle request / response messages

# 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
send_msg(data) click to toggle source

Send data safely using local connection

# File lib/rjr/nodes/unix.rb, line 52
def send_msg(data)
  @send_lock.synchronize{
    Unix.em.schedule { send_data(data) }
  }
end