com.agentfactory.cldc.scheduler
Class Scheduler

java.lang.Object
  extended by java.lang.Thread
      extended by com.agentfactory.cldc.scheduler.Scheduler
All Implemented Interfaces:
java.lang.Runnable

public class Scheduler
extends java.lang.Thread

The scheduler schedules tasks to be executed at periodic intervals.

Author:
Conor Muldoon

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Scheduler(int numThreads)
          Creates a new instance of Scheduler.
 
Method Summary
 void destroy()
          Destroys the scheduler.
 void pause()
          Pauses the scheduler.
 void remove(java.lang.Object key)
          Removes the task represented by the key from the scheduler.
 void reschedule(java.lang.Object key, int period)
          Reschedules the task identified by the specified key to execute at period value.
 void run()
          Executes the main control loop of the scheduler.
 void schedule(java.lang.Object key, java.lang.Runnable task, int period)
          Schedules the task identified by the key to be executed periodically.
 void schedule(java.lang.Runnable task)
          Schedules a task to be executed on a once off basis.
 void writeAgent(java.lang.Object key, java.io.DataOutputStream dos)
          Writes the state of the task represented by the key to the data output stream.
 void writeOut(java.lang.Object key, java.io.DataOutputStream dos)
          This method writes the state of the execution time associated with the task that is represented by the specified key.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Scheduler

public Scheduler(int numThreads)
Creates a new instance of Scheduler.

Parameters:
numThreads - the number of worker threads to be created.
Method Detail

schedule

public void schedule(java.lang.Object key,
                     java.lang.Runnable task,
                     int period)
Schedules the task identified by the key to be executed periodically.

Parameters:
key - the identifier for the task.
task - the task to be executed.
period - the period at which the task should be executed.

reschedule

public void reschedule(java.lang.Object key,
                       int period)
Reschedules the task identified by the specified key to execute at period value.

Parameters:
key - the identifier for the task to be rescheduled.
period - the period at which the task should execute.

schedule

public void schedule(java.lang.Runnable task)
Schedules a task to be executed on a once off basis.

Parameters:
task - the task to be executed.

remove

public void remove(java.lang.Object key)
Removes the task represented by the key from the scheduler.

Parameters:
key - the identifer of the task to be removed.

writeAgent

public void writeAgent(java.lang.Object key,
                       java.io.DataOutputStream dos)
                throws java.io.IOException
Writes the state of the task represented by the key to the data output stream. This method should only be used where the scheduled task is an agent.

Parameters:
key - the identifier for the agent task.
dos - the stream to write the state of the agent to.
Throws:
java.io.IOException - if there is an I/O error.

writeOut

public void writeOut(java.lang.Object key,
                     java.io.DataOutputStream dos)
              throws java.io.IOException
This method writes the state of the execution time associated with the task that is represented by the specified key.

Parameters:
key - the identifier of the task.
dos - the stream that the state is written to.
Throws:
java.io.IOException - if there is an I/O error.

pause

public void pause()
Pauses the scheduler.


destroy

public void destroy()
Destroys the scheduler. This method should be called to free up resources when the scheduler is no longer needed.

Overrides:
destroy in class java.lang.Thread

run

public void run()
         throws MalformedLogicException
Executes the main control loop of the scheduler. Tasks are periodically removed from the buffer and executed using the worker threads.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
Throws:
MalformedLogicException