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/p39.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', :a |
| 9: | value :endpoint, 'http://y', :b |
| 10: | |
| 11: | event :before, :instance, :position, :endpoint |
| 12: | event :after, :instance, :position, :endpoint |
| 13: | |
| 14: | context :sync, :buf => [], :active => false |
| 15: | |
| 16: | call :continue |
| 17: | |
| 18: | rule event.before do |
| 19: | context.sync.buf << [event.instance, event.position] |
| 20: | end |
| 21: | |
| 22: | rule event.after do |
| 23: | context.sync.active = false |
| 24: | continue event.instance, event.position |
| 25: | end |
| 26: | |
| 27: | rule context.sync{buf.any? && active == false} do |
| 28: | context.sync.active = true |
| 29: | continue context.sync.buf.shift |
| 30: | end |
| 31: | end |
| 32: | |
| 33: | m.on_continue do |instance,position| |
| 34: | puts Term::ANSIColor::bold(Term::ANSIColor::red(" Continuing #{instance}, #{position}")) |
| 35: | end |
| 36: | m.before_push do |evt_name,evt_data,context| |
| 37: | puts Term::ANSIColor::bold("Pushing #{evt_name} #{evt_data.inspect}") |
| 38: | end |
| 39: | m.after_push do |context| |
| 40: | puts " After:\n" + context.pretty_inspect.gsub(/^/,' |') |
| 41: | end |
| 42: | |
| 43: | puts Term::ANSIColor::bold("Initial context:") |
| 44: | puts m.context.pretty_inspect.gsub(/^/,' |') |
| 45: | |
| 46: | m.push :before, :position => :p, :endpoint => 'http://not_valid', :instance => 'http://localhost:9188/2' |
| 47: | |
| 48: | m.push :before, :position => :p, :endpoint => 'http://b', :instance => 'http://localhost:9188/2' |
| 49: | m.push :before, :position => :p, :endpoint => 'http://y', :instance => 'http://localhost:9188/1' |
| 50: | |
| 51: | m.push :after, :position => :p, :endpoint => 'http://b', :instance => 'http://localhost:9188/2' |
| 52: | m.push :after, :position => :p, :endpoint => 'http://y', :instance => 'http://localhost:9188/1' |