Class: Cuboid::State::Application
- Defined in:
- lib/cuboid/state/application.rb
Overview
State information for Framework.
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
- #running ⇒ Bool
-
#runtime ⇒ Object
Returns the value of attribute runtime.
- #status ⇒ Symbol
- #status_messages ⇒ Array<String> readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#abort ⇒ Bool
‘true` if the abort request was successful, `false` if the system is already #suspended? or is #suspending?.
-
#abort? ⇒ Bool
‘true` if a #abort signal is in place , `false` otherwise.
-
#aborted ⇒ Object
Signals a completed abort operation.
-
#aborted? ⇒ Bool
‘true` if the system has been aborted, `false` otherwise.
-
#aborting? ⇒ Bool
‘true` if the system is being aborted, `false` otherwise.
-
#add_status_message(message, *sprintf) ⇒ Object
Pushes a message to #status_messages.
-
#available_status_messages ⇒ Hash{Symbol=>String}
All possible #status_messages by type.
- #clear ⇒ Object
-
#clear_status_messages ⇒ Object
Clears #status_messages.
-
#done? ⇒ Bool
‘true` if the system has completed successfully, `false` otherwise.
- #dump(directory) ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
-
#pause ⇒ TrueClass
Pauses the framework on a best effort basis, might take a while to take effect.
-
#pause? ⇒ Bool
‘true` if the framework should pause, `false` otherwise.
-
#paused ⇒ Object
Signals that the system has been paused..
-
#paused? ⇒ Bool
‘true` if the framework is paused.
-
#pausing? ⇒ Bool
‘true` if the system is being paused, `false` otherwise.
-
#resume ⇒ Bool
Resumes a paused system.
- #resumed ⇒ Object
- #running? ⇒ Boolean
-
#set_status_message(*args) ⇒ Object
Sets a message as #status_messages.
- #statistics ⇒ Object
-
#suspend ⇒ Bool
‘true` if the suspend request was successful, `false` if the system is already #suspended? or is #suspending?.
-
#suspend? ⇒ Bool
‘true` if an #abort signal is in place , `false` otherwise.
-
#suspended ⇒ Object
Signals a completed suspension.
-
#suspended? ⇒ Bool
‘true` if the system has been suspended, `false` otherwise.
-
#suspending? ⇒ Bool
‘true` if the system is being suspended, `false` otherwise.
- #timed_out ⇒ Object
- #timed_out? ⇒ Boolean
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
39 40 41 42 43 44 45 46 |
# File 'lib/cuboid/state/application.rb', line 39 def initialize @running = false @pre_pause_status = nil @pause_signals = Set.new @status_messages = [] end |
Instance Attribute Details
#running ⇒ Bool
32 33 34 |
# File 'lib/cuboid/state/application.rb', line 32 def running @running end |
#runtime ⇒ Object
Returns the value of attribute runtime.
37 38 39 |
# File 'lib/cuboid/state/application.rb', line 37 def runtime @runtime end |
#status ⇒ Symbol
29 30 31 |
# File 'lib/cuboid/state/application.rb', line 29 def status @status end |
#status_messages ⇒ Array<String> (readonly)
35 36 37 |
# File 'lib/cuboid/state/application.rb', line 35 def @status_messages end |
Class Method Details
.load(directory) ⇒ Object
288 289 290 291 292 |
# File 'lib/cuboid/state/application.rb', line 288 def self.load( directory ) application = new application.runtime = Cuboid::Application.serializer.load( IO.binread( "#{directory}/runtime" ) ) application end |
Instance Method Details
#abort ⇒ Bool
Returns ‘true` if the abort request was successful, `false` if the system is already #suspended? or is #suspending?.
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/cuboid/state/application.rb', line 119 def abort return false if aborting? || aborted? if !running? fail Error::StateNotAbortable, "Cannot abort idle state: #{status}" end :aborting @status = :aborting @abort = true true end |
#abort? ⇒ Bool
Returns ‘true` if a #abort signal is in place , `false` otherwise.
135 136 137 |
# File 'lib/cuboid/state/application.rb', line 135 def abort? !!@abort end |
#aborted ⇒ Object
Signals a completed abort operation.
140 141 142 143 144 145 |
# File 'lib/cuboid/state/application.rb', line 140 def aborted @abort = false @status = :aborted @running = false nil end |
#aborted? ⇒ Bool
Returns ‘true` if the system has been aborted, `false` otherwise.
149 150 151 |
# File 'lib/cuboid/state/application.rb', line 149 def aborted? @status == :aborted end |
#aborting? ⇒ Bool
Returns ‘true` if the system is being aborted, `false` otherwise.
155 156 157 |
# File 'lib/cuboid/state/application.rb', line 155 def aborting? @status == :aborting end |
#add_status_message(message, *sprintf) ⇒ Object
Pushes a message to #status_messages.
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cuboid/state/application.rb', line 82 def ( , *sprintf ) if .is_a? Symbol if !.include?( ) fail Error::InvalidStatusMessage, "Could not find status message for: '#{}'" end = [] % sprintf end @status_messages << .to_s end |
#available_status_messages ⇒ Hash{Symbol=>String}
Returns All possible #status_messages by type.
56 57 58 59 60 61 62 63 64 |
# File 'lib/cuboid/state/application.rb', line 56 def { suspending: 'Will suspend as soon as the current page is audited.', saving_snapshot: 'Saving snapshot at: %s', snapshot_location: 'Snapshot location: %s', aborting: 'Aborting the scan.', timed_out: 'Scan timed out.' } end |
#clear ⇒ Object
294 295 296 297 298 299 300 301 |
# File 'lib/cuboid/state/application.rb', line 294 def clear @pause_signals.clear @running = false @pre_pause_status = nil @runtime = nil end |
#clear_status_messages ⇒ Object
Clears #status_messages.
96 97 98 |
# File 'lib/cuboid/state/application.rb', line 96 def @status_messages.clear end |
#done? ⇒ Bool
Returns ‘true` if the system has completed successfully, `false` otherwise.
161 162 163 |
# File 'lib/cuboid/state/application.rb', line 161 def done? @status == :done end |
#dump(directory) ⇒ Object
281 282 283 284 285 286 |
# File 'lib/cuboid/state/application.rb', line 281 def dump( directory ) FileUtils.mkdir_p( directory ) d = Cuboid::Application.serializer.dump( @runtime ) IO.binwrite( "#{directory}/runtime", d ) end |
#pause ⇒ TrueClass
Returns Pauses the framework on a best effort basis, might take a while to take effect.
225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/cuboid/state/application.rb', line 225 def pause @pre_pause_status ||= @status if !paused? && !pausing? if !paused? @status = :pausing end @pause_signals << :nil paused if !running? true end |
#pause? ⇒ Bool
Returns ‘true` if the framework should pause, `false` otherwise.
258 259 260 |
# File 'lib/cuboid/state/application.rb', line 258 def pause? @pause_signals.any? end |
#paused ⇒ Object
Signals that the system has been paused..
239 240 241 242 |
# File 'lib/cuboid/state/application.rb', line 239 def paused @status = :paused end |
#paused? ⇒ Bool
Returns ‘true` if the framework is paused.
246 247 248 |
# File 'lib/cuboid/state/application.rb', line 246 def paused? @status == :paused end |
#pausing? ⇒ Bool
Returns ‘true` if the system is being paused, `false` otherwise.
252 253 254 |
# File 'lib/cuboid/state/application.rb', line 252 def pausing? @status == :pausing end |
#resume ⇒ Bool
Resumes a paused system
267 268 269 270 271 272 |
# File 'lib/cuboid/state/application.rb', line 267 def resume @status = :resuming @pause_signals.clear true end |
#resumed ⇒ Object
274 275 276 277 278 279 |
# File 'lib/cuboid/state/application.rb', line 274 def resumed @status = @pre_pause_status @pre_pause_status = nil true end |
#running? ⇒ Boolean
100 101 102 |
# File 'lib/cuboid/state/application.rb', line 100 def running? !!@running end |
#set_status_message(*args) ⇒ Object
Sets a message as #status_messages.
70 71 72 73 |
# File 'lib/cuboid/state/application.rb', line 70 def ( *args ) ( *args ) end |
#statistics ⇒ Object
48 49 50 51 52 |
# File 'lib/cuboid/state/application.rb', line 48 def statistics { runtime: !!@runtime } end |
#suspend ⇒ Bool
Returns ‘true` if the suspend request was successful, `false` if the system is already #suspended? or is #suspending?.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/cuboid/state/application.rb', line 175 def suspend return false if suspending? || suspended? if paused? || pausing? fail Error::StateNotSuspendable, 'Cannot suspend a paused state.' end if !running? fail Error::StateNotSuspendable, "Cannot suspend idle state: #{status}" end :suspending @status = :suspending @suspend = true true end |
#suspend? ⇒ Bool
Returns ‘true` if an #abort signal is in place , `false` otherwise.
195 196 197 |
# File 'lib/cuboid/state/application.rb', line 195 def suspend? !!@suspend end |
#suspended ⇒ Object
Signals a completed suspension.
200 201 202 203 204 |
# File 'lib/cuboid/state/application.rb', line 200 def suspended @suspend = false @status = :suspended nil end |
#suspended? ⇒ Bool
Returns ‘true` if the system has been suspended, `false` otherwise.
208 209 210 |
# File 'lib/cuboid/state/application.rb', line 208 def suspended? @status == :suspended end |
#suspending? ⇒ Bool
Returns ‘true` if the system is being suspended, `false` otherwise.
214 215 216 |
# File 'lib/cuboid/state/application.rb', line 214 def suspending? @status == :suspending end |
#timed_out ⇒ Object
104 105 106 107 |
# File 'lib/cuboid/state/application.rb', line 104 def timed_out @status = :timed_out nil end |
#timed_out? ⇒ Boolean
109 110 111 |
# File 'lib/cuboid/state/application.rb', line 109 def timed_out? @status == :timed_out end |