class Einhorn::Event::Connection
Public Class Methods
from_state(state)
click to toggle source
# File lib/einhorn/event/connection.rb, line 32 def self.from_state(state) fd = state[:socket] socket = Socket.for_fd(fd) conn = self.open(socket) conn.read_buffer = state[:read_buffer] if state[:read_buffer] conn.write_buffer = state[:write_buffer] if state[:write_buffer] # subscriptions could be empty if upgrading from an older version of einhorn state.fetch(:subscriptions, {}).each do |tag, id| conn.subscribe(tag, id) end conn end
new(*args)
click to toggle source
Calls superclass method
Einhorn::Event::AbstractTextDescriptor::new
# File lib/einhorn/event/connection.rb, line 5 def initialize(*args) @subscriptions = {} super end
Public Instance Methods
consume_record(command)
click to toggle source
# File lib/einhorn/event/connection.rb, line 19 def consume_record(command) Einhorn::Command::Interface.process_command(self, command) end
deregister!()
click to toggle source
Calls superclass method
Einhorn::Event::AbstractTextDescriptor#deregister!
# File lib/einhorn/event/connection.rb, line 65 def deregister! log_debug("client disconnected") if Einhorn::TransientState.whatami == :master Einhorn::Event.deregister_connection(@socket.fileno) super end
parse_record()
click to toggle source
# File lib/einhorn/event/connection.rb, line 10 def parse_record split = @read_buffer.split("\n", 2) if split.length > 1 split else nil end end
register!()
click to toggle source
Calls superclass method
Einhorn::Event::AbstractTextDescriptor#register!
# File lib/einhorn/event/connection.rb, line 59 def register! log_debug("client connected") Einhorn::Event.register_connection(self, @socket.fileno) super end
subscribe(tag, request_id)
click to toggle source
# File lib/einhorn/event/connection.rb, line 45 def subscribe(tag, request_id) if request_id @subscriptions[tag] = request_id end end
subscription(tag)
click to toggle source
# File lib/einhorn/event/connection.rb, line 51 def subscription(tag) @subscriptions[tag] end
to_state()
click to toggle source
# File lib/einhorn/event/connection.rb, line 23 def to_state state = {:class => self.class.to_s, :socket => @socket.fileno} # Don't include by default because it's not that pretty state[:read_buffer] = @read_buffer if @read_buffer.length > 0 state[:write_buffer] = @write_buffer if @write_buffer.length > 0 state[:subscriptions] = @subscriptions state end
unsubscribe(tag)
click to toggle source
# File lib/einhorn/event/connection.rb, line 55 def unsubscribe(tag) @subscriptions.delete(tag) end