Class: PubControlSet

Inherits:
Object
  • Object
show all
Defined in:
lib/pubcontrolset.rb

Instance Method Summary collapse

Constructor Details

#initializePubControlSet

Returns a new instance of PubControlSet.



12
13
14
15
# File 'lib/pubcontrolset.rb', line 12

def initialize
  @pubs = Array.new
  at_exit { finish }
end

Instance Method Details

#add(pub) ⇒ Object



21
22
23
# File 'lib/pubcontrolset.rb', line 21

def add(pub)
  @pubs.push(pub)
end

#apply_config(config) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/pubcontrolset.rb', line 25

def apply_config(config)
  config.each do |entry|
    pub = PubControl.new(entry['uri'])
    if entry.key?('iss')
      pub.set_auth_jwt({'iss' => entry['iss']}, entry['key'])
    end
    @pubs.push(pub)
  end
end

#apply_grip_config(config) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pubcontrolset.rb', line 35

def apply_grip_config(config)
  config.each do |entry|
    if !entry.key?('control_uri')
      next
    end
    pub = PubControl.new(entry['control_uri'])
    if !entry.key?('control_iss')
      pub.set_auth_jwt({'iss' => entry['control_iss']}, entry['key'])
    end
    @pubs.push(pub)
  end
end

#clearObject



17
18
19
# File 'lib/pubcontrolset.rb', line 17

def clear
  @pubs = Array.new
end

#publish(channel, item, blocking = false, callback = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pubcontrolset.rb', line 48

def publish(channel, item, blocking=false, callback=nil)
  if blocking
    @pubs.each do |pub|
      pub.publish(channel, item)
    end
  else
    cb = nil
    if !callback.nil?
      cb = PubControlCallbackHandler.new(@pubs.length, callback).
          handler_method_symbol
    end
    @pubs.each do |pub|
      pub.publish_async(channel, item, cb)
    end
  end
end