Instantiate a new Driver and start the scheduler loop to handle events.
task - The Task this Driver belongs to.
# File lib/god/driver.rb, line 174 def initialize(task) @task = task @events = God::DriverEventQueue.new @thread = Thread.new do loop do begin @events.pop.handle_event rescue ThreadError => e # queue is empty break rescue Object => e message = format("Unhandled exception in driver loop - (%s): %s\n%s", e.class, e.message, e.backtrace.join("\n")) applog(nil, :fatal, message) end end end end
Clear all events for this Driver.
Returns nothing.
# File lib/god/driver.rb, line 204 def clear_events @events.clear end
Check if we're in the driver context.
Returns true if in driver thread, false if not.
# File lib/god/driver.rb, line 197 def in_driver_context? Thread.current == @thread end
Queue an asynchronous message.
name - The Symbol name of the operation. args - An optional Array of arguments.
Returns nothing.
# File lib/god/driver.rb, line 221 def message(name, args = []) @events.push(DriverOperation.new(@task, name, args)) end
Create and schedule a new DriverEvent.
condition - The Condition. delay - The Numeric number of seconds to delay (default: interval
defined in condition).
Returns nothing.
# File lib/god/driver.rb, line 232 def schedule(condition, delay = condition.interval) applog(nil, :debug, "driver schedule #{condition} in #{delay} seconds") @events.push(DriverEvent.new(delay, @task, condition)) end
Shutdown the DriverEventQueue threads.
Returns nothing.
# File lib/god/driver.rb, line 211 def shutdown @events.shutdown end
Generated with the Darkfish Rdoc Generator 2.