Please disable Adblockers and enable JavaScript for domain CEWebS.cs.univie.ac.at! We have NO ADS, but they may interfere with some of our course material.

Name: examples/p34_monitor.rb 
1:
#!/usr/bin/ruby
2:
require 'riddl/client'
3:
 
4:
srv = Riddl::Client.new('http://localhost:9399','http://localhost:9399/?riddl-description')
5:
 
6:
pattern = 'p34'
7:
 
8:
res = srv.resource("/")
9:
status, response = res.get
10:
doc = XML::Smart::string(response.first.value.read)
11:
ist = doc.find("/instances/instance[text()='#{pattern}']")
12:
unless ist.empty?
13:
  ins = ist.first.attributes["id"]
14:
  puts "Monitoring #{pattern} - Instance #{ins}"
15:
  res = srv.resource("/#{ins}/notifications/subscriptions/")
16:
  status, response = res.post [
17:
    Riddl::Parameter::Simple.new("topic","running"),
18:
    Riddl::Parameter::Simple.new("events","after_push,call"),
19:
  ]
20:
  key = response[0].value
21:
 
22:
  view = srv.resource("/#{ins}/notifications/subscriptions/#{key}/ws/")
23:
  view.ws do |conn|
24:
    conn.stream do |msg|
25:
      puts "<#{msg}>"
26:
    end
27:
    conn.disconnect do
28:
      EM::stop_event_loop
29:
    end
30:
  end
31:
end