Class: FFWD::Debug::TCP
- Inherits:
-
Object
- Object
- FFWD::Debug::TCP
- Defined in:
- lib/ffwd/debug/tcp.rb
Instance Method Summary collapse
-
#initialize(host, port, rebind_timeout) ⇒ TCP
constructor
A new instance of TCP.
-
#monitor(channel, type) ⇒ Object
Setup monitor hooks for the specified input and output channel.
- #register_client(peer, client) ⇒ Object
- #unregister_client(peer, client) ⇒ Object
Methods included from Lifecycle
#depend_on, #start, #started?, #starting, #starting_hooks, #stop, #stopped?, #stopping, #stopping_hooks
Methods included from Logging
Constructor Details
#initialize(host, port, rebind_timeout) ⇒ TCP
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ffwd/debug/tcp.rb', line 28 def initialize host, port, rebind_timeout @clients = {} @sessions = {} @host = host @port = port @peer = "#{@host}:#{@port}" info = "tcp://#{@peer}" r = FFWD.retry :timeout => rebind_timeout do |attempt| EM.start_server @host, @port, Connection, self log.info "Bind on #{info} (attempt #{attempt})" end r.error do |a, t, e| log.warning "Bind on #{info} failed, retry ##{a} in #{t}s: #{e}" end r.depend_on self end |
Instance Method Details
#monitor(channel, type) ⇒ Object
Setup monitor hooks for the specified input and output channel.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ffwd/debug/tcp.rb', line 65 def monitor channel, type channel.starting do if session = @sessions[channel.id] log.error "Session already monitored: #{channel.id}" return end session = MonitorSession.new channel, type # provide the session to any already connected clients. @clients.each do |peer, client| session.register peer, client end @sessions[channel.id] = session end channel.stopping do @sessions.delete channel.id end end |
#register_client(peer, client) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/ffwd/debug/tcp.rb', line 48 def register_client peer, client @sessions.each do |id, session| session.register peer, client end @clients[peer] = client end |
#unregister_client(peer, client) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ffwd/debug/tcp.rb', line 56 def unregister_client peer, client @sessions.each do |id, session| session.unregister peer, client end @clients.delete peer end |