Class: Baykit::BayServer::Agent::AcceptHandler

Inherits:
Object
  • Object
show all
Includes:
Baykit::BayServer::Agent, Util
Defined in:
lib/baykit/bayserver/agent/accept_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent, port_map) ⇒ AcceptHandler

Returns a new instance of AcceptHandler.



18
19
20
21
22
23
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 18

def initialize(agent, port_map)
  @agent = agent
  @port_map = port_map
  @ch_count = 0
  @is_shutdown = false
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



12
13
14
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 12

def agent
  @agent
end

#ch_countObject (readonly)

Returns the value of attribute ch_count.



16
17
18
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 16

def ch_count
  @ch_count
end

#is_shutdownObject (readonly)

Returns the value of attribute is_shutdown.



15
16
17
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 15

def is_shutdown
  @is_shutdown
end

#port_mapObject (readonly)

Returns the value of attribute port_map.



13
14
15
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 13

def port_map
  @port_map
end

Instance Method Details

#close_allObject



54
55
56
57
58
59
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 54

def close_all()
  @port_map.keys.each do |skt|
    BayLog.debug("%s Close server Socket: %s", @agent, skt)
    skt.close()
  end
end

#on_acceptable(server_skt) ⇒ Object



25
26
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 25

def on_acceptable(server_skt)
end

#on_busyObject



32
33
34
35
36
37
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 32

def on_busy()
  BayLog.debug("%s AcceptHandler:onBusy", @agent)
  @port_map.keys().each do |ch|
    @agent.selector.unregister(ch)
  end
end

#on_closedObject



28
29
30
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 28

def on_closed()
  @ch_count -= 1
end

#on_freeObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 39

def on_free()
  BayLog.debug("%s AcceptHandler:onFree isShutdown=%s", @agent, @is_shutdown)
  if @is_shutdown
    return
  end

  @port_map.keys().each do |ch|
    @agent.selector.register(ch, Selector::OP_READ)
  end
end

#server_socket?(skt) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 50

def server_socket?(skt)
  return @port_map.key?(skt)
end

#shutdownObject



61
62
63
64
65
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 61

def shutdown()
  @is_shutdown = true
  on_busy()
  @agent.wakeup()
end