module Servolux::Threaded
def _activity_thread
def _activity_thread @_activity_thread ||= ::Servolux::Threaded::ThreadContainer.new(60, false, 0, nil, false); end # @private
def continue_on_error=( value )
interpreter to exit.
A SystemExit will never be caught; it will always cause the Ruby
activity thread when an error is raised by the run method.
is raised by the +run+ method. The default behavior is to stop the
Set to +true+ to continue running the threaded object even if an error
def continue_on_error=( value ) _activity_thread.continue_on_error = (value ? true : false) end
def continue_on_error?
threaded object will stop running when an error is raised.
error is raised by the run method. The default is to return +false+. The
Returns +true+ if the threaded object should continue running even if an
def continue_on_error? _activity_thread.continue_on_error end
def finished_iterations?
Returns +false+ otherwise.
number of iterations or the thread is no longer running.
Returns +true+ if the activity thread has finished its maximum
def finished_iterations? return true unless _activity_thread.running? @_activity_thread.finished_iterations? end
def interval
threaded object's 'run' method.
Returns the number of seconds to sleep between invocations of the
def interval _activity_thread.interval end
def interval=( value )
threaded object's 'run' method.
Sets the number of seconds to sleep between invocations of the
def interval=( value ) value = Float(value) raise ArgumentError, "Sleep interval must be >= 0" unless value >= 0 _activity_thread.interval = value end
def iterations
completed thus far.
Returns the number of iterations of the threaded object's 'run' method
def iterations _activity_thread.iterations end
def join( limit = nil )
with +nil+.
If the activity thread is not running, this method returns immediately
the activity thread is stopped or until _limit_ seconds have passed.
execution and run the activity thread. This method does not return until
If the activity thread is running, the calling thread will suspend
def join( limit = nil ) _activity_thread.join(limit) ? self : nil end
def maximum_iterations
object's 'run' method
Returns the maximum number of invocations of the threaded
def maximum_iterations _activity_thread.maximum_iterations end
def maximum_iterations=( value )
'run' method
Sets the maximum number of invocations of the threaded object's
def maximum_iterations=( value ) unless value.nil? value = Integer(value) raise ArgumentError, "maximum iterations must be >= 1" unless value >= 1 end _activity_thread.maximum_iterations = value end
def run
functionality.
interval. Implementing classes are expect to provide this
This method will be called by the activity thread at the desired
def run raise NotImplementedError, 'The run method must be defined by the threaded object.' end
def running?
otherwise.
Returns +true+ if the activity thread is running. Returns +false+
def running? _activity_thread.running? end
def start
after the thread is created.
including class defines an 'after_starting' method, it will be called
called before the thread is created and run. Likewise, if the
If the including class defines a 'before_starting' method, it will be
without taking any action.
Start the activity thread. If already started this method will return
def start return self if _activity_thread.running? logger.debug "Starting" before_starting if self.respond_to?(:before_starting) @_activity_thread.start self after_starting if self.respond_to?(:after_starting) self end
def status
will cause the exception to be raised in the calling thread.
If this method returns +nil+, then calling join on the threaded object
nil : terminated with an exception
false : not running or terminated normally
'aborting' : aborting
'run' : executing
'sleep' : sleeping or waiting on I/O
Returns the status of threaded object.
def status return false if _activity_thread.thread.nil? @_activity_thread.thread.status end
def stop
has stopped.
defines an 'after_stopping' method, it will be called after the thread
called before the thread is stopped. Likewise, if the including class
If the including class defines a 'before_stopping' method, it will be
without taking any action.
Stop the activity thread. If already stopped this method will return
def stop return self unless _activity_thread.running? logger.debug "Stopping" before_stopping if self.respond_to?(:before_stopping) @_activity_thread.stop self end
def use_strict_interval
semantics. See the setter method for an in depth explanation.
When true, the activity thread will treat the sleep interval with strict
def use_strict_interval _activity_thread.use_strict_interval end
def use_strict_interval=( value )
seconds after the previous invocation.
subsequent invocation of the 'run' will occur as close as possible to 60
to execute, then the activity thread will sleep for 57.2 seconds. The
If the sleep interval is 60 seconds and the 'run' method takes 2.2 seconds
subtracted from the sleep interval.
semantics. The time it takes for the 'run' method to execute will be
Signals the activity thread to treat the sleep interval with strict
def use_strict_interval=( value ) _activity_thread.use_strict_interval = (value ? true : false) end
def wait( limit = nil )
number of iterations has passed since this method was called.
does not return until the activity thread has stopped, or a specific
method will return without taking any action. Otherwise, this method
Wait on the activity thread. If the thread is already stopped, this
def wait( limit = nil ) return self unless _activity_thread.running? initial_iterations = @_activity_thread.iterations loop { break unless @_activity_thread.running? break if limit and @_activity_thread.iterations > ( initial_iterations + limit ) Thread.pass } end