Class: Vissen::Input::Broker::PropagationControl
- Inherits:
-
Object
- Object
- Vissen::Input::Broker::PropagationControl
- Defined in:
- lib/vissen/input/broker.rb
Overview
Internal class used by the Broker
to control the propagation of a
message and provide a control surface for subscription handlers,
allowing them to stop the propagation at priorites lower than (not equal
to) their own.
== Usage
The following example uses a propagation control object to stop
propagation at priority 1. Note that #stop?
must be called for each
message before #stop!
to ensure that the correct priority is set.
ctrl = PropagationControl.new ctrl.stop? 2 # => false ctrl.stop? 1 # => false
ctrl.stop!
ctrl.stop? 1 # => false ctrl.stop? 0 # => true
Instance Method Summary collapse
-
#initialize ⇒ PropagationControl
constructor
A new instance of PropagationControl.
-
#stop! ⇒ nil
Sets the priority stopping threshold.
-
#stop?(priority) ⇒ true, false
Whether to stop or not.
Constructor Details
#initialize ⇒ PropagationControl
Returns a new instance of PropagationControl.
154 155 156 157 |
# File 'lib/vissen/input/broker.rb', line 154 def initialize @stop_at_priority = -1 @current_priority = 0 end |
Instance Method Details
#stop! ⇒ nil
Sets the priority stopping threshold.
172 173 174 175 |
# File 'lib/vissen/input/broker.rb', line 172 def stop! @stop_at_priority = @current_priority nil end |
#stop?(priority) ⇒ true, false
Returns whether to stop or not.
162 163 164 165 166 167 |
# File 'lib/vissen/input/broker.rb', line 162 def stop?(priority) return true if priority < @stop_at_priority @current_priority = priority false end |