Class: Sqewer::StateLock
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Sqewer::StateLock
- Defined in:
- lib/sqewer/state_lock.rb
Overview
Controls the state of the Worker object, and wraps it's state transitions with a Mutex.
Instance Method Summary collapse
- #in_state?(some_state) ⇒ Boolean
-
#initialize ⇒ StateLock
constructor
A new instance of StateLock.
- #transition!(to_state) ⇒ Object
Constructor Details
#initialize ⇒ StateLock
Returns a new instance of StateLock.
7 8 9 10 11 12 13 14 15 |
# File 'lib/sqewer/state_lock.rb', line 7 def initialize @m = Mutex.new m = VeryTinyStateMachine.new(:stopped) m.permit_state :starting, :running, :stopping, :stopped, :failed m.permit_transition :stopped => :starting, :starting => :running m.permit_transition :running => :stopping, :stopping => :stopped m.permit_transition :starting => :failed # Failed to start __setobj__(m) end |
Instance Method Details
#in_state?(some_state) ⇒ Boolean
17 18 19 |
# File 'lib/sqewer/state_lock.rb', line 17 def in_state?(some_state) @m.synchronize { __getobj__.in_state?(some_state) } end |
#transition!(to_state) ⇒ Object
21 22 23 |
# File 'lib/sqewer/state_lock.rb', line 21 def transition!(to_state) @m.synchronize { __getobj__.transition!(to_state) } end |