jrun.jms.core.messagemgr
Class Scheduler

jrunx.kernel.ServiceAdapter
  |
  +--jrun.jms.core.util.JMSServiceAdapter
        |
        +--jrun.jms.core.messagemgr.Scheduler
All Implemented Interfaces:
JMSService, JMSServiceAdapterMBean, javax.naming.Referenceable, java.lang.Runnable, java.io.Serializable, Service, ServiceMBean

public class Scheduler
extends JMSServiceAdapter
implements java.lang.Runnable

A scheduler for Runnable objects. Clients add Runnable objects to this scheduler, and when a thread becomes available, they will be executed.

Version:
$Revision: 1.6 $ $Date: 2001/06/11 15:49:36 $
Author:
Jim Mourikis, Tim Anderson
See Also:
Runnable, org.exolab.core.service.BasicService, org.exolab.core.threadPool.ThreadPool, Serialized Form

Field Summary
static java.lang.String OBJECT_NAME
           
 
Fields inherited from class jrunx.kernel.ServiceAdapter
DEFAULT_DEACTIVATED, DEFAULT_DOMAIN, DOMAIN_NAME_SEPARATOR, DOMAIN_NAME_SUFFIX, domainName, jndiBindable, LOGGER_CACHE_TIME, SCHEDULER_SERVICE, SECURITY_MANAGER, server, status, TRANSACTION_MANAGER
 
Fields inherited from interface jrunx.kernel.Service
INITIALIZED, STARTED, STARTING, STOPPED, STOPPING, UNINITIALIZED
 
Constructor Summary
  Scheduler(int maxThreads)
          Constructor that constructs a scheduler with the default service name.
protected Scheduler(int maxThreads, java.lang.String name)
          Constructor that constructs a scheduler with a specified service name.
 
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 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 BasicService.stop()
 void start()
          Starts the scheduler.
 void stop()
          Stop the scheduler.
 
Methods inherited from class jrun.jms.core.util.JMSServiceAdapter
getMetaData, restart, resume, setMetaData, suspend
 
Methods inherited from class jrunx.kernel.ServiceAdapter
bind, destroy, findObjectInstance, findObjectInstance, findObjectInstance, getBindToJNDI, getDeactivated, getDomainName, getDomainSearchPath, getJRunService, getLogger, getName, getParentService, getReference, getResourceManager, getServerName, getServerProperties, getStatus, init, invokeMethod, isInPartition, isPartition, lookup, postDeregister, postRegister, preDeregister, preRegister, requestServer, scheduleRunnable, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, toString, unbind, unscheduleRunnable, updateStatus
 
Methods inherited from interface jrunx.kernel.ServiceMBean
bind, getBindToJNDI, getDeactivated, getDomainName, getJRunService, getLogger, getName, getParentService, getServerName, requestServer, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, unbind
 
Methods inherited from interface jrunx.kernel.Service
destroy, getStatus, init, updateStatus
 

Field Detail

OBJECT_NAME

public static final java.lang.String OBJECT_NAME
Constructor Detail

Scheduler

public Scheduler(int maxThreads)
Constructor that constructs a scheduler with the default service name.
Parameters:
maxThreads - the number of threads to use

Scheduler

protected Scheduler(int maxThreads,
                    java.lang.String name)
Constructor that constructs a scheduler with a specified service name.
Parameters:
maxThreads - the number of threads to use
name - the name of this service
Method Detail

instance

public static Scheduler instance()

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 BasicService.stop()
Specified by:
run in interface java.lang.Runnable

start

public void start()
           throws java.lang.Exception
Starts the scheduler.
Overrides:
start in class ServiceAdapter

stop

public void stop()
          throws java.lang.Exception
Stop the scheduler. Any threads will be terminated.
Overrides:
stop in class ServiceAdapter
Throws:
ServiceException -  

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 � 2002 Macromedia Corporation. All Rights Reserved.