com.agentfactory.cldc.scheduler
Class ThreadTask

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

public class ThreadTask
extends java.lang.Object
implements java.lang.Runnable

In AFME, agents and other tasks are scheduled to execute at periodic intervals. The task to be scheduled must implement the runnable interface. The ThreadTask associates the task to be executed with an execution time. The scheduler places thread task in a buffer. At execution time the thread task is extracted from the buffer and subseqently executed by worker threads.

Author:
Conor Muldoon

Constructor Summary
ThreadTask(java.lang.Runnable runnable, ExTime et)
          Creates a new instance of ThreadTask.
 
Method Summary
 long calcSleepTime()
          Calculates the amount of time the scheduler should sleep until it reaches the execution time.
 boolean equalsProcess(java.lang.Runnable run)
          Checks whether the runnable task within this thread task is equal to the specified runnable task.
 void removeTime(java.util.Hashtable table)
          If there are no more agents schedule at the execution time interval, the execution time interval will be removed from the specified hash table.
 void run()
          Executes the runnable task.
 boolean schedule()
          Calculates the next execution time at which the task will be executed.
 boolean sooner(ThreadTask task)
          Checks whether this task will execute sooner than the specified task.
 void writeAgent(java.io.DataOutputStream dos)
          Writes the state of the runnable object (Agent) to the specified data output stream.
 void writeTime(java.io.DataOutputStream dos)
          Writes the execution time to the specified data output stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadTask

public ThreadTask(java.lang.Runnable runnable,
                  ExTime et)
Creates a new instance of ThreadTask.

Parameters:
runnable - the task to be executed.
et - the execution time.
Method Detail

removeTime

public void removeTime(java.util.Hashtable table)
If there are no more agents schedule at the execution time interval, the execution time interval will be removed from the specified hash table.

Parameters:
table - the hash table that the execution time interval is to be removed from.

equalsProcess

public boolean equalsProcess(java.lang.Runnable run)
Checks whether the runnable task within this thread task is equal to the specified runnable task.

Parameters:
run - the specified runnalbe task.
Returns:
true if this runnable task is equal to the specified task, false otherwise.

sooner

public boolean sooner(ThreadTask task)
Checks whether this task will execute sooner than the specified task.

Parameters:
task - the specified task.
Returns:
true if the execution time is sooner, false otherwise.

calcSleepTime

public long calcSleepTime()
Calculates the amount of time the scheduler should sleep until it reaches the execution time.

Returns:
the amount of time the scheduler should sleep.

schedule

public boolean schedule()
                 throws MalformedLogicException
Calculates the next execution time at which the task will be executed.

Returns:
false if the task is to be executed now, true otherwise.
Throws:
MalformedLogicException - if there is a logic error.

run

public void run()
Executes the runnable task.

Specified by:
run in interface java.lang.Runnable

writeAgent

public void writeAgent(java.io.DataOutputStream dos)
                throws java.io.IOException
Writes the state of the runnable object (Agent) to the specified data output stream.

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

writeTime

public void writeTime(java.io.DataOutputStream dos)
               throws java.io.IOException
Writes the execution time to the specified data output stream.

Parameters:
dos - the data output stream to write the execution time to.
Throws:
java.io.IOException - if there is an I/O error.