org.objectweb.perseus.distribution.lib

Class 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.

Field Summary

static byte
STATE_IDLE
static byte
STATE_READY
static byte
STATE_RUNNING
static byte
STATE_STOPPED
static byte
STATE_STOPPING
static String[]
stateStr

Constructor Summary

TaskThread(String name, Object tid, TaskScheduler sched)

Method Summary

void
addTask(Task a)
Add an task to the thread.
void
deleteTasksUpTo(long upToSN)
Object
getId()
byte
getState()
Returns the state of the thread
long
getTaskNumber()
void
resetTaskNumber()
byte
start()
byte
stop()
Stops the thread.
String
toString()
boolean
waitState(byte state)
Waits until a particular state is reached

Field Details

STATE_IDLE

public static final byte STATE_IDLE

Field Value:
1


STATE_READY

public static final byte STATE_READY

Field Value:
2


STATE_RUNNING

public static final byte STATE_RUNNING

Field Value:
3


STATE_STOPPED

public static final byte STATE_STOPPED

Field Value:
0


STATE_STOPPING

public static final byte STATE_STOPPING

Field Value:
4


stateStr

public static final String[] stateStr

Constructor Details

TaskThread

public TaskThread(String name,
                  Object tid,
                  TaskScheduler sched)

Method Details

addTask

public void addTask(Task a)
Add an task to the thread.

Parameters:
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

Returns:
the state of the thread


getTaskNumber

public long getTaskNumber()


resetTaskNumber

public void resetTaskNumber()


start

public byte start()


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.

Returns:
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

Parameters:
state - the state to wait for

Returns:
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.