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/px1.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 :endpoint, 'http://b', :syn
9:
  
10:
  event :running_syncing_before, :instance, :activity, :endpoint
11:
  event :running_syncing_after, :instance, :activity, :endpoint
12:
  
13:
  context :wait, :buf => []
14:
  context :sync, :run => [], :fin => []
15:
  
16:
  call :continue
17:
  
18:
  rule event.running_syncing_before do
19:
    context.wait.buf << [event.instance, event.activity]
20:
  end
21:
 
22:
  rule context.wait{buf.length >= 1}, context.sync{run.empty?} do
23:
    context.sync.run = context.wait.buf.slice!(0..9)
24:
    context.sync.run.each do |instance,activity|
25:
      continue instance,activity
26:
    end
27:
  end
28:
  
29:
  rule event.running_syncing_after do
30:
    context.sync.fin << [event.instance, event.activity]
31:
  end
32:
  rule context.sync{fin.length == run.length} do
33:
    context.sync.fin.each do |instance,activity|
34:
      continue instance,activity
35:
    end
36:
    context.sync.fin.clear
37:
    context.sync.run.clear
38:
  end
39:
end
40:
 
41:
m.on_continue do |instance,position|# {{{
42:
  puts Term::ANSIColor::bold(Term::ANSIColor::red("  Continuing #{instance}, #{position}"))
43:
end  
44:
 
45:
m.before_push do |evt_name,evt_data,context|
46:
  puts Term::ANSIColor::bold("Pushing #{evt_name} #{evt_data.inspect}")
47:
end
48:
m.after_push do |context|
49:
  puts "  After:\n" + context.pretty_inspect.gsub(/^/,'    |')
50:
end
51:
 
52:
puts Term::ANSIColor::bold("Initial context:")
53:
puts m.context.pretty_inspect.gsub(/^/,'    |')# }}}
54:
 
55:
m.push :running_syncing_before, :activity => :p, :endpoint => 'http://b', :instance => 'http://localhost:9188/p1'
56:
m.push :running_syncing_before, :activity => :p, :endpoint => 'http://b', :instance => 'http://localhost:9188/p2'
57:
 
58:
m.push :running_syncing_after,  :activity => :p, :endpoint => 'http://b', :instance => 'http://localhost:9188/p1'
59:
m.push :running_syncing_after,  :activity => :p, :endpoint => 'http://b', :instance => 'http://localhost:9188/p2'