Module: ServiceState
- Included in:
- FileSystemWatcher
- Defined in:
- lib/doozer/watcher.rb
Overview
The Runnable module is a generic mixin for including state and status information in a class
Constant Summary collapse
- NOT_STARTED =
state constants
0
- STARTED =
1
- STOPPED =
2
- CONFIGURED =
3
Instance Attribute Summary collapse
-
#endTime ⇒ Object
readonly
Returns the value of attribute endTime.
-
#startTime ⇒ Object
readonly
Returns the value of attribute startTime.
Instance Method Summary collapse
-
#initializeState ⇒ Object
Initialize the state information.
- #isConfigured? ⇒ Boolean
- #isStarted? ⇒ Boolean
- #isStopped? ⇒ Boolean
-
#onStateChange(&callbackBlock) ⇒ Object
Set the callback for when someone calls setState.
-
#setState(newState) ⇒ Object
All methods, inside this class or not, should use this method to change the state of the JobRunner.
- #stopWhen(&block) ⇒ Object
Instance Attribute Details
#endTime ⇒ Object (readonly)
Returns the value of attribute endTime.
14 15 16 |
# File 'lib/doozer/watcher.rb', line 14 def endTime @endTime end |
#startTime ⇒ Object (readonly)
Returns the value of attribute startTime.
14 15 16 |
# File 'lib/doozer/watcher.rb', line 14 def startTime @startTime end |
Instance Method Details
#initializeState ⇒ Object
Initialize the state information
17 18 19 20 21 22 23 24 25 |
# File 'lib/doozer/watcher.rb', line 17 def initializeState() @configured = false @startTime = 0 @stopTime = 0 @stateMutex = Mutex.new() @stopWhen = nil setState(NOT_STARTED) end |
#isConfigured? ⇒ Boolean
54 55 56 |
# File 'lib/doozer/watcher.rb', line 54 def isConfigured? return @configured end |
#isStarted? ⇒ Boolean
58 59 60 |
# File 'lib/doozer/watcher.rb', line 58 def isStarted? return @state == STARTED end |
#isStopped? ⇒ Boolean
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/doozer/watcher.rb', line 62 def isStopped? if @state == STOPPED then return true elsif @stopWhen && @stopWhen.call() then setState(STOPPED) return true else return false end end |
#onStateChange(&callbackBlock) ⇒ Object
Set the callback for when someone calls setState. You will be passed the state CONSTANT being set
29 30 31 |
# File 'lib/doozer/watcher.rb', line 29 def onStateChange(&callbackBlock) @stateCallback = callbackBlock end |
#setState(newState) ⇒ Object
All methods, inside this class or not, should use this method to change the state of the JobRunner
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/doozer/watcher.rb', line 36 def setState(newState) @stateMutex.synchronize { if newState == CONFIGURED then @configured = true else @state = newState if isStarted? then @startTime = Time.now() elsif isStopped? @stopTime = Time.now() end end } if defined?(@stateCallback) then @stateCallback.call(newState) end end |
#stopWhen(&block) ⇒ Object
73 74 75 |
# File 'lib/doozer/watcher.rb', line 73 def stopWhen(&block) @stopWhen = block end |