Class: FFWD::Debug::MonitorSession

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, channel, type) ⇒ MonitorSession

Returns a new instance of MonitorSession.



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
54
55
# File 'lib/ffwd/debug/monitor_session.rb', line 22

def initialize id, 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 => @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 => @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 Attribute Details

#idObject (readonly)

Returns the value of attribute id.



20
21
22
# File 'lib/ffwd/debug/monitor_session.rb', line 20

def id
  @id
end

Instance Method Details

#register(peer, client) ⇒ Object



57
58
59
# File 'lib/ffwd/debug/monitor_session.rb', line 57

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

#send(line) ⇒ Object



65
66
67
68
69
# File 'lib/ffwd/debug/monitor_session.rb', line 65

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

#unregister(peer, client) ⇒ Object



61
62
63
# File 'lib/ffwd/debug/monitor_session.rb', line 61

def unregister peer, client
  @clients.delete peer
end