Class: Einhorn::Event::Connection
Instance Attribute Summary
#client_id, #read_buffer, #write_buffer
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Persistent
included, persistent?
#close, #log_debug, #log_error, #log_info, #notify_readable, #notify_writeable, open, #process_read_buffer, #read, #to_io, #write, #write_pending?
Constructor Details
#initialize(*args) ⇒ Connection
Returns a new instance of Connection.
5
6
7
8
|
# File 'lib/einhorn/event/connection.rb', line 5
def initialize(*args)
@subscriptions = {}
super
end
|
Class Method Details
.from_state(state) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
|
# 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]
state.fetch(:subscriptions, {}).each do |tag, id|
conn.subscribe(tag, id)
end
conn
end
|
Instance Method Details
#consume_record(command) ⇒ Object
#parse_record ⇒ Object
10
11
12
13
14
15
16
17
|
# 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! ⇒ Object
59
60
61
62
63
|
# 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) ⇒ Object
45
46
47
48
49
|
# File 'lib/einhorn/event/connection.rb', line 45
def subscribe(tag, request_id)
if request_id
@subscriptions[tag] = request_id
end
end
|
#subscription(tag) ⇒ Object
51
52
53
|
# File 'lib/einhorn/event/connection.rb', line 51
def subscription(tag)
@subscriptions[tag]
end
|
#to_state ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/einhorn/event/connection.rb', line 23
def to_state
state = {:class => self.class.to_s, :socket => @socket.fileno}
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) ⇒ Object
55
56
57
|
# File 'lib/einhorn/event/connection.rb', line 55
def unsubscribe(tag)
@subscriptions.delete(tag)
end
|