Parent

Files

Class/Module Index [+]

Quicksearch

God::DriverEventQueue

The DriverEventQueue is a simple queue that holds TimedEvent instances in order to maintain the schedule of upcoming events.

Public Class Methods

new() click to toggle source

Initialize a DriverEventQueue.

# File lib/god/driver.rb, line 95
def initialize
  @shutdown = false
  @events = []
  @monitor = Monitor.new
  @resource = @monitor.new_cond
end

Public Instance Methods

clear() click to toggle source

Clear the queue.

Returns nothing.

# File lib/god/driver.rb, line 153
def clear
  @events.clear
end
empty?() click to toggle source

Returns true if the queue is empty, false if not.

# File lib/god/driver.rb, line 146
def empty?
  @events.empty?
end
length() click to toggle source

Returns the Integer length of the queue.

# File lib/god/driver.rb, line 158
def length
  @events.length
end
Also aliased as: size
pop() click to toggle source

Wait until the queue has something due, pop it off the queue, and return it.

Returns the popped event.

# File lib/god/driver.rb, line 116
def pop
  @monitor.synchronize do
    if @events.empty?
      raise ThreadError, "queue empty" if @shutdown
      @resource.wait
    else
      delay = @events.first.at - Time.now
      @resource.wait(delay) if delay > 0
    end

    @events.shift
  end
end
push(event) click to toggle source

Add an event to the queue, wake any waiters if what we added needs to happen sooner than the next pending event.

Returns nothing.

# File lib/god/driver.rb, line 134
def push(event)
  @monitor.synchronize do
    @events << event
    @events.sort!

    # If we've sorted the events and found the one we're adding is at
    # the front, it will likely need to run before the next due date.
    @resource.signal if @events.first == event
  end
end
shutdown() click to toggle source

Wake any sleeping threads after setting the sentinel.

Returns nothing.

# File lib/god/driver.rb, line 105
def shutdown
  @shutdown = true
  @monitor.synchronize do
    @resource.broadcast
  end
end
size() click to toggle source
Alias for: length

[Validate]

Generated with the Darkfish Rdoc Generator 2.