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(id, 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
Returns a new instance of TCP.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ffwd/debug/tcp.rb', line 28 def initialize host, port, rebind_timeout @clients = {} @sessions = {} @host = host @port = port @peer = "#{@host}:#{@port}" r = FFWD.retry :timeout => rebind_timeout do |attempt| EM.start_server @host, @port, Connection, self log.info "Bind on tcp://#{@peer} (attempt #{attempt})" end r.error do |a, t, e| log.error "Failed to bind tcp://#{@peer} (attempt #{a}), retry in #{t}s", e end r.depend_on self end |
Instance Method Details
#monitor(id, channel, type) ⇒ Object
Setup monitor hooks for the specified input and output channel.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ffwd/debug/tcp.rb', line 64 def monitor id, channel, type if session = @sessions[id] log.error "Session already monitored: #{id}" return end session = @sessions[id] = MonitorSession.new id, channel, type # provide the session to the already connected clients. @clients.each do |peer, client| session.register peer, client end channel.stopping do @sessions.delete id end end |
#register_client(peer, client) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/ffwd/debug/tcp.rb', line 47 def register_client peer, client @sessions.each do |id, session| session.register peer, client end @clients[peer] = client end |
#unregister_client(peer, client) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/ffwd/debug/tcp.rb', line 55 def unregister_client peer, client @sessions.each do |id, session| session.unregister peer, client end @clients.delete peer end |