Class: FFWD::Debug::MonitorSession

Inherits:
Object
  • Object
show all
Defined in:
lib/ffwd/debug/monitor_session.rb

Instance Method Summary collapse

Constructor Details

#initialize(channel, type) ⇒ MonitorSession

Returns a new instance of MonitorSession.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ffwd/debug/monitor_session.rb', line 20

def initialize channel, type
  @type = type
  @clients = {}

  subs = []

  channel.starting do
    subs << channel.event_subscribe do |event|
      data = @type.serialize_event event

      begin
        send JSON.dump(:id => channel.id, :type => :event, :data => data)
      rescue => e
        log.error "Failed to serialize event", e
        return
      end
    end

    subs << channel.metric_subscribe do |metric|
      data = @type.serialize_metric metric

      begin
        send JSON.dump(:id => channel.id, :type => :metric, :data => data)
      rescue => e
        log.error "Failed to serialize metric", e
        return
      end
    end
  end

  channel.stopping do
    subs.each(&:unsubscribe).clear
  end
end

Instance Method Details

#register(peer, client) ⇒ Object



55
56
57
# File 'lib/ffwd/debug/monitor_session.rb', line 55

def register peer, client
  @clients[peer] = client
end

#send(line) ⇒ Object



63
64
65
66
67
# File 'lib/ffwd/debug/monitor_session.rb', line 63

def send line
  @clients.each do |peer, client|
    client.send_line line
  end
end

#unregister(peer, client) ⇒ Object



59
60
61
# File 'lib/ffwd/debug/monitor_session.rb', line 59

def unregister peer, client
  @clients.delete peer
end