Class: Funl::ClientSequencer
- Inherits:
-
Object
- Object
- Funl::ClientSequencer
- Defined in:
- lib/funl/client-sequencer.rb
Overview
Assigns unique ids to clients.
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#next_id ⇒ Object
readonly
Returns the value of attribute next_id.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#server_thread ⇒ Object
readonly
Returns the value of attribute server_thread.
-
#stream_type ⇒ Object
readonly
Returns the value of attribute stream_type.
Instance Method Summary collapse
-
#initialize(server, *conns, log: Logger.new($stderr), stream_type: ObjectStream::MSGPACK_TYPE, next_id: 0) ⇒ ClientSequencer
constructor
A new instance of ClientSequencer.
- #run ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(server, *conns, log: Logger.new($stderr), stream_type: ObjectStream::MSGPACK_TYPE, next_id: 0) ⇒ ClientSequencer
Returns a new instance of ClientSequencer.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/funl/client-sequencer.rb', line 14 def initialize server, *conns, log: Logger.new($stderr), stream_type: ObjectStream::MSGPACK_TYPE, next_id: 0 @server = server @log = log @stream_type = stream_type @next_id = next_id conns.each do |conn| handle_conn conn end end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
11 12 13 |
# File 'lib/funl/client-sequencer.rb', line 11 def log @log end |
#next_id ⇒ Object (readonly)
Returns the value of attribute next_id.
10 11 12 |
# File 'lib/funl/client-sequencer.rb', line 10 def next_id @next_id end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
8 9 10 |
# File 'lib/funl/client-sequencer.rb', line 8 def server @server end |
#server_thread ⇒ Object (readonly)
Returns the value of attribute server_thread.
9 10 11 |
# File 'lib/funl/client-sequencer.rb', line 9 def server_thread @server_thread end |
#stream_type ⇒ Object (readonly)
Returns the value of attribute stream_type.
12 13 14 |
# File 'lib/funl/client-sequencer.rb', line 12 def stream_type @stream_type end |
Instance Method Details
#run ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/funl/client-sequencer.rb', line 42 def run loop do conn = server.accept log.debug {"accepted #{conn.inspect}"} handle_conn conn end rescue => ex log.error ex raise end |
#start ⇒ Object
28 29 30 31 32 |
# File 'lib/funl/client-sequencer.rb', line 28 def start @server_thread = Thread.new do run end end |
#stop ⇒ Object
34 35 36 |
# File 'lib/funl/client-sequencer.rb', line 34 def stop server_thread.kill if server_thread end |
#wait ⇒ Object
38 39 40 |
# File 'lib/funl/client-sequencer.rb', line 38 def wait server_thread.join end |