org.exolab.jms.scheduler
Class Scheduler

java.lang.Object
  |
  +--org.exolab.core.service.Service
        |
        +--org.exolab.core.service.BasicService
              |
              +--org.exolab.jms.scheduler.Scheduler
All Implemented Interfaces:
java.lang.Runnable, java.io.Serializable, org.exolab.core.service.Serviceable

public class Scheduler
extends org.exolab.core.service.BasicService

The scheduler is responsible for executing Runnable objects using a thread pool. Clients can add these objects to the scheduler and the scheduler will, in fifo order, execute them. If there are no threads currently available, the runnable will wait for one to become available.

A client can add or remove Runnable objects.

Version:
$Revision: 1.9 $ $Date: 2003/08/17 01:32:25 $
Author:
Jim Mourikis, Tim Anderson, Jim Alateras
See Also:
Runnable, BasicService, ThreadPool, Serialized Form

Method Summary
 void add(java.lang.Runnable runner)
          Add a Runnable object to the scheduler queue.
 boolean contains(java.lang.Runnable runner)
          Returns if a Runnable object exists in the scheduler queue.
static Scheduler createInstance()
          Creates the singleton instance
static Scheduler instance()
          Returns the singleton instance
 boolean isEmpty()
          Returns true if the scheduler queue is empty
protected  java.lang.Runnable next()
          Return the next object in the queue to execute This method blocks until an object becomes available.
 boolean remove(java.lang.Runnable runner)
          Remove a Runnable object from the scheduler queue.
 void run()
          Start the scheduler This can only be terminated by invoking stop()
 void stop()
           
 
Methods inherited from class org.exolab.core.service.BasicService
start, toString
 
Methods inherited from class org.exolab.core.service.Service
getName, getState, restart, setState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

createInstance

public static Scheduler createInstance()
                                throws org.exolab.core.service.ServiceException
Creates the singleton instance
Throws:
org.exolab.core.service.ServiceException - if the scheduler can't be created

instance

public static Scheduler instance()
Returns the singleton instance
Returns:
the singleton instance, or null if it hasn't been initialised

add

public void add(java.lang.Runnable runner)
Add a Runnable object to the scheduler queue. When a thread becomes available, it will be executed.
Parameters:
runner - the object to execute

remove

public boolean remove(java.lang.Runnable runner)
Remove a Runnable object from the scheduler queue.
Parameters:
runner - the object to remove
Returns:
boolean true if the object was removed, false if it is already running or doesn't exist

contains

public boolean contains(java.lang.Runnable runner)
Returns if a Runnable object exists in the scheduler queue.
Parameters:
runner - the object to remove
Returns:
boolean true if the object exists, false if it is already running or doesn't exist

isEmpty

public boolean isEmpty()
Returns true if the scheduler queue is empty
Returns:
true if the scheduler queue is empty

run

public void run()
Start the scheduler This can only be terminated by invoking stop()
Overrides:
run in class org.exolab.core.service.BasicService

stop

public void stop()
          throws org.exolab.core.service.ServiceException
Overrides:
stop in class org.exolab.core.service.BasicService

next

protected java.lang.Runnable next()
Return the next object in the queue to execute This method blocks until an object becomes available.
Returns:
Runnable the next object to execute


Copyright © 1999-2004 The OpenJMS Group. All Rights Reserved.