org.objectweb.perseus.distribution.lib
Class TaskThread
LinkedList
org.objectweb.perseus.distribution.lib.TaskThread
public class TaskThread
extends LinkedList
This class represents threads of tasks. A thread of tasks is assigned by an
instance of TaskScheduler (that is, a 'scheduler') to an instance of
TaskPerformer (that is a 'processor'). A thread is a list of tasks which are
executed in FIFO order. Actually, this could be easily enhanced to accept
other scheduling of tasks within a thread.
Tasks are added to a thread and will be executed eventually provided the
thread is started (or restarted if it has been stopped. One can waits that
a thread go to a particular state. In particular one can request that the
thread is stopped and, if it is in the running state, waits for the current
performed task is terminated.
A thread can be in the five distinct states:
* stopped: the thread will not be executed until iy is (re-)started.
It is its initial state.
* idle: the thread has no task to execute. It is a safe state to remove
(for instance to free memory)
* ready: the thread has at least one task to execute, is not currently
executed and can be executed
* running: the running task of the thread is currently (or will be very
soon) executed. Next state: ready or idle
* stopping: the thread has a running task and the stop method has been
called. Next state is stopped.
Its life cycle is as follows :
stopped idle ready running stopping
---------------------------------------------------------------------------
stopped ADD STOP STOP - PERFORM
---------------------------------------------------------------------------
idle START - - PERFORM -
---------------------------------------------------------------------------
ready START ADD ADD PERFORM -
---------------------------------------------------------------------------
running - - SCHED1 PERFORM -
---------------------------------------------------------------------------
stopping - - - STOP -
Any unauthorized transition should throw an exception
Threads of tasks are used in the jgroups implementation of the distributed
resource services interfaces so as to flush messages relative to a resource.
STATE_IDLE
public static final byte STATE_IDLE
- 1
STATE_READY
public static final byte STATE_READY
- 2
STATE_RUNNING
public static final byte STATE_RUNNING
- 3
STATE_STOPPED
public static final byte STATE_STOPPED
- 0
STATE_STOPPING
public static final byte STATE_STOPPING
- 4
stateStr
public static final String[] stateStr
TaskThread
public TaskThread(String name,
Object tid,
TaskScheduler sched)
addTask
public void addTask(Task a)
Add an task to the thread.
a
- the task ot be added
deleteTasksUpTo
public void deleteTasksUpTo(long upToSN)
getId
public Object getId()
getState
public byte getState()
Returns the state of the thread
- the state of the thread
getTaskNumber
public long getTaskNumber()
resetTaskNumber
public void resetTaskNumber()
stop
public byte stop()
Stops the thread. No more tasks will be performed until it is started
again EXCEPT the possibly one being performed...
To be sure no more tasks is being performed, a call to waitState must
be done.
- the new state of the thread. if in the blocked state, a
call to waitState must be done to make sure no more tasks is being
performed
toString
public String toString()
waitState
public boolean waitState(byte state)
throws InterruptedException
Waits until a particular state is reached
state
- the state to wait for
- true if the thread was not in the wished state when entering
Copyright © 2000-2002 France Telecom S.A., INRIA, IMAG-LSR All Rights Reserved.