Class: CircuitBreaker::Place
- Inherits:
-
Object
- Object
- CircuitBreaker::Place
- Defined in:
- lib/circuit_breaker.rb
Overview
Represents a place in the Petri net workflow Places can hold tokens and connect to transitions via arcs
Instance Attribute Summary collapse
-
#input_arcs ⇒ Object
readonly
Returns the value of attribute input_arcs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output_arcs ⇒ Object
readonly
Returns the value of attribute output_arcs.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#add_input_arc(source, weight = 1) ⇒ Arc
Add an input arc from a source to this place.
-
#add_output_arc(target, weight = 1) ⇒ Arc
Add an output arc from this place to a target.
-
#add_token(token) ⇒ Object
Add a token to this place.
-
#initialize(name) ⇒ Place
constructor
Initialize a new place with a given name.
-
#remove_token ⇒ Token?
Remove and return the most recently added token.
-
#token_count ⇒ Integer
Get the current number of tokens in this place.
Constructor Details
#initialize(name) ⇒ Place
Initialize a new place with a given name
33 34 35 36 37 38 39 |
# File 'lib/circuit_breaker.rb', line 33 def initialize(name) @name = name @tokens = [] @input_arcs = [] @output_arcs = [] @mutex = Mutex.new end |
Instance Attribute Details
#input_arcs ⇒ Object (readonly)
Returns the value of attribute input_arcs.
25 26 27 |
# File 'lib/circuit_breaker.rb', line 25 def input_arcs @input_arcs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/circuit_breaker.rb', line 17 def name @name end |
#output_arcs ⇒ Object (readonly)
Returns the value of attribute output_arcs.
29 30 31 |
# File 'lib/circuit_breaker.rb', line 29 def output_arcs @output_arcs end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
21 22 23 |
# File 'lib/circuit_breaker.rb', line 21 def tokens @tokens end |
Instance Method Details
#add_input_arc(source, weight = 1) ⇒ Arc
Add an input arc from a source to this place
63 64 65 66 67 |
# File 'lib/circuit_breaker.rb', line 63 def add_input_arc(source, weight = 1) arc = Arc.new(source, self, weight) @input_arcs << arc arc end |
#add_output_arc(target, weight = 1) ⇒ Arc
Add an output arc from this place to a target
73 74 75 76 77 |
# File 'lib/circuit_breaker.rb', line 73 def add_output_arc(target, weight = 1) arc = Arc.new(self, target, weight) @output_arcs << arc arc end |
#add_token(token) ⇒ Object
Add a token to this place
43 44 45 |
# File 'lib/circuit_breaker.rb', line 43 def add_token(token) @mutex.synchronize { @tokens << token } end |
#remove_token ⇒ Token?
Remove and return the most recently added token
49 50 51 |
# File 'lib/circuit_breaker.rb', line 49 def remove_token @mutex.synchronize { @tokens.pop } end |
#token_count ⇒ Integer
Get the current number of tokens in this place
55 56 57 |
# File 'lib/circuit_breaker.rb', line 55 def token_count @tokens.size end |