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: patterns/px4.rb
1: | #!/usr/bin/env ruby |
2: | require 'rubygems' |
3: | require 'pp' |
4: | require 'term/ansicolor' |
5: | require File.expand_path(File.dirname(__FILE__) + '/../lib/remar') |
6: | |
7: | m = REMAR.new.ruleset do |
8: | value :state, 'finished', :fin |
9: | |
10: | event :running_syncing_after, :instance, :activity, :endpoint |
11: | event :state_change, :state, :instance |
12: | |
13: | context :traces, :specific => {}, :generic => [] |
14: | |
15: | call :continue |
16: | |
17: | rule event.running_syncing_after do |
18: | context.traces.specific[event.instance] ||= [Time.now,[],[]] |
19: | context.traces.specific[event.instance][1] << event.endpoint |
20: | context.traces.specific[event.instance][2] << (context.traces.specific[event.instance][2].empty? ? 0 : Time.now - context.traces.specific[event.instance][0]) |
21: | end |
22: | |
23: | rule event.state_change do |
24: | start, trace, times = context.traces.specific.delete(event.instance) |
25: | if !context.traces.generic.find{|t| t[0] += 1 if t[1] == trace} |
26: | context.traces.generic << [1, trace] |
27: | end |
28: | end |
29: | end |
30: | |
31: | m.on_continue do |instance,position|# {{{ |
32: | puts Term::ANSIColor::bold(Term::ANSIColor::red(" Continuing #{instance}, #{position}")) |
33: | end # }}} |
34: | m.before_push do |evt_name,evt_data,context|# {{{ |
35: | puts Term::ANSIColor::bold("Pushing #{evt_name} #{evt_data.inspect}") |
36: | end# }}} |
37: | m.after_push do |context|# {{{ |
38: | puts " After:\n" + context.pretty_inspect.gsub(/^/,' |') |
39: | end# }}} |
40: | puts Term::ANSIColor::bold("Initial context:")# {{{ |
41: | puts m.context.pretty_inspect.gsub(/^/,' |')# }}} |
42: | |
43: | m.push :running_syncing_after, :activity => :p1, :endpoint => 'http://a', :instance => 'http://localhost:9188/p1' |
44: | sleep 1 |
45: | m.push :running_syncing_after, :activity => :p2, :endpoint => 'http://b', :instance => 'http://localhost:9188/p1' |
46: | sleep 1 |
47: | m.push :running_syncing_after, :activity => :p3, :endpoint => 'http://c', :instance => 'http://localhost:9188/p1' |
48: | m.push :state_change, :state => 'finished', :instance => 'http://localhost:9188/p1' |
49: | |
50: | m.push :running_syncing_after, :activity => :p1, :endpoint => 'http://a', :instance => 'http://localhost:9188/p2' |
51: | sleep 1 |
52: | m.push :running_syncing_after, :activity => :p2, :endpoint => 'http://b', :instance => 'http://localhost:9188/p2' |
53: | sleep 1 |
54: | m.push :running_syncing_after, :activity => :p3, :endpoint => 'http://c', :instance => 'http://localhost:9188/p2' |
55: | m.push :state_change, :state => 'finished', :instance => 'http://localhost:9188/p2' |
56: | |
57: | |
58: | m.push :running_syncing_after, :activity => :p1, :endpoint => 'http://r1', :instance => 'http://localhost:9188/p3' |
59: | sleep 1 |
60: | m.push :running_syncing_after, :activity => :p2, :endpoint => 'http://r2', :instance => 'http://localhost:9188/p3' |
61: | sleep 1 |
62: | m.push :running_syncing_after, :activity => :p3, :endpoint => 'http://c', :instance => 'http://localhost:9188/p3' |
63: | m.push :state_change, :state => 'finished', :instance => 'http://localhost:9188/p3' |