Class: Funl::ClientSequencer

Inherits:
Object
  • Object
show all
Defined in:
lib/funl/client-sequencer.rb

Overview

Assigns unique ids to clients.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#logObject (readonly)

Returns the value of attribute log.



11
12
13
# File 'lib/funl/client-sequencer.rb', line 11

def log
  @log
end

#next_idObject (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

#serverObject (readonly)

Returns the value of attribute server.



8
9
10
# File 'lib/funl/client-sequencer.rb', line 8

def server
  @server
end

#server_threadObject (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_typeObject (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

#runObject



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

#startObject



28
29
30
31
32
# File 'lib/funl/client-sequencer.rb', line 28

def start
  @server_thread = Thread.new do
    run
  end
end

#stopObject



34
35
36
# File 'lib/funl/client-sequencer.rb', line 34

def stop
  server_thread.kill if server_thread
end

#waitObject



38
39
40
# File 'lib/funl/client-sequencer.rb', line 38

def wait
  server_thread.join
end