|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--jason.core.AbstractService
|
+--jason.core.ThreadableService
Created Wed May 15 16:05:33 2002
This is a core class for services that needs to manage a thread.
This class will enable a thread to be started for the Start
method. User can specify to loop in the run automatically.
You shouldn't write a main loop in the run method. Please
call setThreadLoopMode with the correct value for that.
| Field Summary | |
protected java.lang.Thread |
activeThread
|
| Fields inherited from class jason.core.AbstractService |
INITIALIZED, name, NOSTATE, serviceContext, STARTED, STOPPED |
| Fields inherited from interface jason.core.Service |
ERROR_MESSAGE, INFORMATION_MESSAGE, VERBOSE_MESSAGE, WARNING_MESSAGE |
| Constructor Summary | |
ThreadableService()
By default the thread will not be started at the start method.
|
|
ThreadableService(boolean autoStart)
This constructor will let the service be started as a thread automatically with the start method. |
|
| Method Summary | |
protected void |
actionForStart()
Don't override it, this method is called when starting the service for starting the thread is needed of the service. |
protected void |
enableServiceForThread()
Be careful with this method, it is normally in the constructor of your service you choose it When starting the thread will call the runThread method |
protected long |
getThreadLoopDelay()
|
protected boolean |
isThreadLoopMode()
|
protected boolean |
isThreadStarted()
|
protected boolean |
isWaiting()
This method will be called is the current thread is waiting (user has call the threadWait method. |
protected void |
notifyThreadRunning()
This method can be overrided for a task before the run method. |
protected void |
runThread()
This method call run method. |
void |
setPriority(int newPriority)
Here the thread priority. |
protected void |
setThreadLoopDelay(long delay)
This value is only for the thread loop mode. |
protected void |
setThreadLoopMode(boolean loopMode)
This is an important method, because it permits to use the run in a loop. |
void |
threadNotify()
|
void |
threadWait()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected java.lang.Thread activeThread
| Constructor Detail |
public ThreadableService()
start method.
For enabling it, please call the enableServiceForThread at the
right time
public ThreadableService(boolean autoStart)
start method.
autoStart - true for starting the service as a thread automatically| Method Detail |
protected void enableServiceForThread()
throws ServiceException
runThread method
if - another thread is already running
ServiceExceptionprotected void actionForStart()
run will be called once
actionForStart in class AbstractServiceprotected void setThreadLoopMode(boolean loopMode)
run in a loop. This is useful for the
thread state. By default this method is to true.
so if you want a thread that is launched one time and expired
after the first task use the false value. Note
that is you change this value while running, it will stopped
the current loop if the initial value was true.
protected boolean isThreadLoopMode()
true if the code is in a loop mode for the threadable stateprotected void setThreadLoopDelay(long delay)
sleep method with the delay value. By default this value is
with 100 ms. If you use a value <= 0 then it will disable the
delay
protected long getThreadLoopDelay()
protected void runThread()
run method. This is called inside
a thread. This method is able to stop
It could be dangerous to override it
protected void notifyThreadRunning()
public void setPriority(int newPriority)
protected boolean isWaiting()
threadWait method. Else by calling the
threadNotify method, the response should be false
public void threadWait()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic void threadNotify()
protected boolean isThreadStarted()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||