Class: Edoors::Board
Instance Attribute Summary
Attributes inherited from Iota
#name, #parent, #path, #spin, #viewer
Class Method Summary collapse
-
.json_create(o) ⇒ Object
creates a Board object from a JSON data.
Instance Method Summary collapse
-
#flush! ⇒ Object
sends away all stored Particle.
-
#initialize(n, p) ⇒ Board
constructor
creates a Board object from the arguments.
-
#keep!(p) ⇒ Object
stores back the given Particle.
-
#process_p(p) ⇒ Object
process the given particle then forward it to user code.
-
#to_json(*a) ⇒ Object
called by JSON#generate to serialize the Board object into JSON data.
Methods inherited from Door
#process_sys_p, #release_p, #require_p, #send_p, #send_sys_p
Methods inherited from Iota
#hibernate!, #receive_p, #resume!, #start!, #stop!
Constructor Details
#initialize(n, p) ⇒ Board
creates a Board object from the arguments.
34 35 36 37 |
# File 'lib/edoors/board.rb', line 34 def initialize n, p super n, p @postponed = {} end |
Class Method Details
.json_create(o) ⇒ Object
creates a Board object from a JSON data
57 58 59 60 61 62 63 64 65 |
# File 'lib/edoors/board.rb', line 57 def self.json_create o raise Edoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name board = self.new o['name'], o['parent'] o['postponed'].each do |link_value,particle| board.process_p Edoors::Particle.json_create(particle.merge!('spin'=>board.spin)) end board.resume! o board end |
Instance Method Details
#flush! ⇒ Object
sends away all stored Particle
98 99 100 101 102 |
# File 'lib/edoors/board.rb', line 98 def flush! while p=@postponed.shift send_p p[1] end end |
#keep!(p) ⇒ Object
stores back the given Particle
this can be used to prevent the overhead of sending the particle back to self
91 92 93 94 |
# File 'lib/edoors/board.rb', line 91 def keep! p @postponed[p.link_value] = p @saved = nil end |
#process_p(p) ⇒ Object
process the given particle then forward it to user code
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/edoors/board.rb', line 71 def process_p p @viewer.receive_p p if @viewer if p.action!=Edoors::ACT_ERROR and p.action!=Edoors::ACT_PASS_THROUGH p2 = @postponed[p.link_value] ||= p return if p2==p @postponed.delete p.link_value p,p2 = p2,p if p.action==Edoors::ACT_FOLLOW p.merge! p2 end @saved = p receive_p p _garbage if not @saved.nil? end |
#to_json(*a) ⇒ Object
called by JSON#generate to serialize the Board object into JSON data
43 44 45 46 47 48 49 |
# File 'lib/edoors/board.rb', line 43 def to_json *a { 'kls' => self.class.name, 'name' => @name, 'postponed' => @postponed }.merge(hibernate!).to_json *a end |