jason.core.pool
Class ThreadCapsuleImpl

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--jason.core.pool.ThreadCapsuleImpl
All Implemented Interfaces:
java.lang.Runnable, ThreadCapsule

public class ThreadCapsuleImpl
extends java.lang.Thread
implements ThreadCapsule


Field Summary
protected  Task coreThread
           
protected  boolean keepAlive
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ThreadCapsuleImpl()
          This capsule waits until a setTask is called
ThreadCapsuleImpl(Task task)
          Start the ThreadCapsule with a task
 
Method Summary
 void activateThreadCapsule()
          This method should be called only if the keep alive state is to true
 Task getTask()
           
 boolean hasTask()
           
 boolean isKeepAlive()
           
protected  void resetPriority()
          Restore the priority
 void run()
           
 void setDefaultPriority(int defaultPriority)
          Update the default thread priority.
 void setKeepAlive(boolean keepAlive)
          Decide to maintain the current thread.
 void setLoopTask(boolean loop)
          Decide to maintain the current task (setTask) in the thread.
 void setTask(Task task)
           
 void setTask(Task task, int priority)
           
 void setTaskContext(TaskContext tc)
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

coreThread

protected Task coreThread

keepAlive

protected boolean keepAlive
Constructor Detail

ThreadCapsuleImpl

public ThreadCapsuleImpl()
This capsule waits until a setTask is called


ThreadCapsuleImpl

public ThreadCapsuleImpl(Task task)
Start the ThreadCapsule with a task

Method Detail

setDefaultPriority

public void setDefaultPriority(int defaultPriority)
Update the default thread priority. This method will update the current priority unless a task has been set

Specified by:
setDefaultPriority in interface ThreadCapsule

resetPriority

protected void resetPriority()
Restore the priority


hasTask

public boolean hasTask()
Specified by:
hasTask in interface ThreadCapsule

setTask

public void setTask(Task task)
Specified by:
setTask in interface ThreadCapsule

setTask

public void setTask(Task task,
                    int priority)
Specified by:
setTask in interface ThreadCapsule

setTaskContext

public void setTaskContext(TaskContext tc)
Specified by:
setTaskContext in interface ThreadCapsule

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

setLoopTask

public void setLoopTask(boolean loop)
Decide to maintain the current task (setTask) in the thread. The task will run until a new task takes its place


setKeepAlive

public void setKeepAlive(boolean keepAlive)
Decide to maintain the current thread. by default the value is true. If you decide to set it to false, you will not have an effective run method meaning a task will not be run

Specified by:
setKeepAlive in interface ThreadCapsule

isKeepAlive

public boolean isKeepAlive()
Specified by:
isKeepAlive in interface ThreadCapsule

getTask

public Task getTask()
Specified by:
getTask in interface ThreadCapsule

activateThreadCapsule

public void activateThreadCapsule()
This method should be called only if the keep alive state is to true

Specified by:
activateThreadCapsule in interface ThreadCapsule