org.apache.ode.scheduler.simple
Class SimpleScheduler

java.lang.Object
  extended by org.apache.ode.scheduler.simple.SimpleScheduler
All Implemented Interfaces:
org.apache.ode.bpel.iapi.Scheduler

public class SimpleScheduler
extends java.lang.Object
implements org.apache.ode.bpel.iapi.Scheduler

A reliable and relatively simple scheduler that uses a database to persist information about scheduled tasks. The challenge is to achieve high performance in a small memory footprint without loss of reliability while supporting distributed/clustered configurations. The design is based around three time horizons: "immediate", "near future", and "everything else". Immediate jobs (i.e. jobs that are about to be up) are written to the database and kept in an in-memory priority queue. When they execute, they are removed from the database. Near future jobs are placed in the database and assigned to the current node, however they are not stored in memory. Periodically jobs are "upgraded" from near-future to immediate status, at which point they get loaded into memory. Jobs that are further out in time, are placed in the database without a node identifer; when they are ready to be "upgraded" to near-future jobs they are assigned to one of the known live nodes. Recovery is rather straighforward, with stale node identifiers being reassigned to known good nodes.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.ode.bpel.iapi.Scheduler
org.apache.ode.bpel.iapi.Scheduler.JobDetails, org.apache.ode.bpel.iapi.Scheduler.JobInfo, org.apache.ode.bpel.iapi.Scheduler.JobProcessor, org.apache.ode.bpel.iapi.Scheduler.JobProcessorException, org.apache.ode.bpel.iapi.Scheduler.JobType, org.apache.ode.bpel.iapi.Scheduler.MapSerializableRunnable, org.apache.ode.bpel.iapi.Scheduler.Synchronizer
 
Constructor Summary
SimpleScheduler(java.lang.String nodeId, DatabaseDelegate del, java.util.Properties conf)
           
 
Method Summary
 void cancelJob(java.lang.String jobId)
           
<T> java.util.concurrent.Future<T>
execIsolatedTransaction(java.util.concurrent.Callable<T> transaction)
           
<T> T
execTransaction(java.util.concurrent.Callable<T> transaction)
           
<T> T
execTransaction(java.util.concurrent.Callable<T> transaction, int timeout)
           
 boolean isTransacted()
           
 void registerSynchronizer(org.apache.ode.bpel.iapi.Scheduler.Synchronizer synch)
           
protected  void runJob(org.apache.ode.scheduler.simple.Job job)
          Run a job in the current thread.
protected  void runPolledRunnable(org.apache.ode.scheduler.simple.Job job)
          Run a job from a polled runnable thread.
 void runTask(org.apache.ode.scheduler.simple.Task task)
           
 java.lang.String scheduleMapSerializableRunnable(org.apache.ode.bpel.iapi.Scheduler.MapSerializableRunnable runnable, java.util.Date when)
           
 java.lang.String schedulePersistedJob(org.apache.ode.bpel.iapi.Scheduler.JobDetails jobDetail, java.util.Date when)
           
 java.lang.String scheduleVolatileJob(boolean transacted, org.apache.ode.bpel.iapi.Scheduler.JobDetails jobDetail)
           
 java.lang.String scheduleVolatileJob(boolean transacted, org.apache.ode.bpel.iapi.Scheduler.JobDetails jobDetail, java.util.Date when)
           
 void setDatabaseDelegate(DatabaseDelegate dbd)
           
 void setExecutorService(java.util.concurrent.ExecutorService executorService)
           
 void setImmediateInterval(long immediateInterval)
           
 void setJobProcessor(org.apache.ode.bpel.iapi.Scheduler.JobProcessor processor)
           
 void setNearFutureInterval(long nearFutureInterval)
           
 void setNodeId(java.lang.String nodeId)
           
 void setPolledRunnableProcesser(org.apache.ode.bpel.iapi.Scheduler.JobProcessor polledRunnableProcessor)
           
 void setPollIntervalForPolledRunnable(long pollIntervalForPolledRunnable)
           
 void setRollbackOnly()
           
 void setStaleInterval(long staleInterval)
           
 void setTransactionManager(javax.transaction.TransactionManager txm)
           
 void setTransactionsPerSecond(int tps)
           
 void shutdown()
           
 void start()
           
 void stop()
           
 void updateHeartBeat(java.lang.String nodeId)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleScheduler

public SimpleScheduler(java.lang.String nodeId,
                       DatabaseDelegate del,
                       java.util.Properties conf)
Method Detail

setPollIntervalForPolledRunnable

public void setPollIntervalForPolledRunnable(long pollIntervalForPolledRunnable)

setNodeId

public void setNodeId(java.lang.String nodeId)

setStaleInterval

public void setStaleInterval(long staleInterval)

setImmediateInterval

public void setImmediateInterval(long immediateInterval)

setNearFutureInterval

public void setNearFutureInterval(long nearFutureInterval)

setTransactionsPerSecond

public void setTransactionsPerSecond(int tps)

setTransactionManager

public void setTransactionManager(javax.transaction.TransactionManager txm)

setDatabaseDelegate

public void setDatabaseDelegate(DatabaseDelegate dbd)

setExecutorService

public void setExecutorService(java.util.concurrent.ExecutorService executorService)

setPolledRunnableProcesser

public void setPolledRunnableProcesser(org.apache.ode.bpel.iapi.Scheduler.JobProcessor polledRunnableProcessor)
Specified by:
setPolledRunnableProcesser in interface org.apache.ode.bpel.iapi.Scheduler

cancelJob

public void cancelJob(java.lang.String jobId)
               throws org.apache.ode.bpel.iapi.ContextException
Specified by:
cancelJob in interface org.apache.ode.bpel.iapi.Scheduler
Throws:
org.apache.ode.bpel.iapi.ContextException

execIsolatedTransaction

public <T> java.util.concurrent.Future<T> execIsolatedTransaction(java.util.concurrent.Callable<T> transaction)
                                                       throws java.lang.Exception,
                                                              org.apache.ode.bpel.iapi.ContextException
Specified by:
execIsolatedTransaction in interface org.apache.ode.bpel.iapi.Scheduler
Throws:
java.lang.Exception
org.apache.ode.bpel.iapi.ContextException

execTransaction

public <T> T execTransaction(java.util.concurrent.Callable<T> transaction)
                  throws java.lang.Exception,
                         org.apache.ode.bpel.iapi.ContextException
Specified by:
execTransaction in interface org.apache.ode.bpel.iapi.Scheduler
Throws:
java.lang.Exception
org.apache.ode.bpel.iapi.ContextException

execTransaction

public <T> T execTransaction(java.util.concurrent.Callable<T> transaction,
                             int timeout)
                  throws java.lang.Exception,
                         org.apache.ode.bpel.iapi.ContextException
Specified by:
execTransaction in interface org.apache.ode.bpel.iapi.Scheduler
Throws:
java.lang.Exception
org.apache.ode.bpel.iapi.ContextException

setRollbackOnly

public void setRollbackOnly()
                     throws java.lang.Exception
Specified by:
setRollbackOnly in interface org.apache.ode.bpel.iapi.Scheduler
Throws:
java.lang.Exception

registerSynchronizer

public void registerSynchronizer(org.apache.ode.bpel.iapi.Scheduler.Synchronizer synch)
                          throws org.apache.ode.bpel.iapi.ContextException
Specified by:
registerSynchronizer in interface org.apache.ode.bpel.iapi.Scheduler
Throws:
org.apache.ode.bpel.iapi.ContextException

schedulePersistedJob

public java.lang.String schedulePersistedJob(org.apache.ode.bpel.iapi.Scheduler.JobDetails jobDetail,
                                             java.util.Date when)
                                      throws org.apache.ode.bpel.iapi.ContextException
Specified by:
schedulePersistedJob in interface org.apache.ode.bpel.iapi.Scheduler
Throws:
org.apache.ode.bpel.iapi.ContextException

scheduleMapSerializableRunnable

public java.lang.String scheduleMapSerializableRunnable(org.apache.ode.bpel.iapi.Scheduler.MapSerializableRunnable runnable,
                                                        java.util.Date when)
                                                 throws org.apache.ode.bpel.iapi.ContextException
Specified by:
scheduleMapSerializableRunnable in interface org.apache.ode.bpel.iapi.Scheduler
Throws:
org.apache.ode.bpel.iapi.ContextException

scheduleVolatileJob

public java.lang.String scheduleVolatileJob(boolean transacted,
                                            org.apache.ode.bpel.iapi.Scheduler.JobDetails jobDetail)
                                     throws org.apache.ode.bpel.iapi.ContextException
Specified by:
scheduleVolatileJob in interface org.apache.ode.bpel.iapi.Scheduler
Throws:
org.apache.ode.bpel.iapi.ContextException

scheduleVolatileJob

public java.lang.String scheduleVolatileJob(boolean transacted,
                                            org.apache.ode.bpel.iapi.Scheduler.JobDetails jobDetail,
                                            java.util.Date when)
                                     throws org.apache.ode.bpel.iapi.ContextException
Specified by:
scheduleVolatileJob in interface org.apache.ode.bpel.iapi.Scheduler
Throws:
org.apache.ode.bpel.iapi.ContextException

setJobProcessor

public void setJobProcessor(org.apache.ode.bpel.iapi.Scheduler.JobProcessor processor)
                     throws org.apache.ode.bpel.iapi.ContextException
Specified by:
setJobProcessor in interface org.apache.ode.bpel.iapi.Scheduler
Throws:
org.apache.ode.bpel.iapi.ContextException

shutdown

public void shutdown()
Specified by:
shutdown in interface org.apache.ode.bpel.iapi.Scheduler

start

public void start()
Specified by:
start in interface org.apache.ode.bpel.iapi.Scheduler

stop

public void stop()
Specified by:
stop in interface org.apache.ode.bpel.iapi.Scheduler

runJob

protected void runJob(org.apache.ode.scheduler.simple.Job job)
Run a job in the current thread.

Parameters:
job - job to run.

runPolledRunnable

protected void runPolledRunnable(org.apache.ode.scheduler.simple.Job job)
Run a job from a polled runnable thread. The runnable is not persistent, however, the poller is persistent and wakes up every given interval to check the status of the runnable.

There is at least one re-scheduling of the poller job. Since, the runnable's state is not persisted, and the same runnable may be tried again after system failure, the runnable that's used with this polling should be repeatable.

Parameters:
job - job to run.

isTransacted

public boolean isTransacted()
Specified by:
isTransacted in interface org.apache.ode.bpel.iapi.Scheduler

runTask

public void runTask(org.apache.ode.scheduler.simple.Task task)

updateHeartBeat

public void updateHeartBeat(java.lang.String nodeId)