org.objectweb.perseus.distribution.lib
Class TaskThread

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byjava.util.AbstractSequentialList
              extended byjava.util.LinkedList
                  extended byorg.objectweb.perseus.distribution.lib.TaskThread
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, java.io.Serializable

public class TaskThread
extends java.util.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.

See Also:
Serialized Form

Field Summary
static byte STATE_IDLE
           
static byte STATE_READY
           
static byte STATE_RUNNING
           
static byte STATE_STOPPED
           
static byte STATE_STOPPING
           
static java.lang.String[] stateStr
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
TaskThread(java.lang.String name, java.lang.Object tid, TaskScheduler sched)
           
 
Method Summary
 void addTask(Task a)
          Add an task to the thread.
 void deleteTasksUpTo(long upToSN)
           
 java.lang.Object getId()
           
 byte getState()
          Returns the state of the thread
 long getTaskNumber()
           
 void resetTaskNumber()
           
 byte start()
           
 byte stop()
          Stops the thread.
 java.lang.String toString()
           
 boolean waitState(byte state)
          Waits until a particular state is reached
 
Methods inherited from class java.util.LinkedList
add, add, addAll, addAll, addFirst, addLast, clear, clone, contains, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, remove, remove, removeFirst, removeLast, set, size, toArray, toArray
 
Methods inherited from class java.util.AbstractSequentialList
iterator
 
Methods inherited from class java.util.AbstractList
equals, hashCode, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, retainAll, subList
 

Field Detail

STATE_STOPPED

public static final byte STATE_STOPPED
See Also:
Constant Field Values

STATE_IDLE

public static final byte STATE_IDLE
See Also:
Constant Field Values

STATE_READY

public static final byte STATE_READY
See Also:
Constant Field Values

STATE_RUNNING

public static final byte STATE_RUNNING
See Also:
Constant Field Values

STATE_STOPPING

public static final byte STATE_STOPPING
See Also:
Constant Field Values

stateStr

public static final java.lang.String[] stateStr
Constructor Detail

TaskThread

public TaskThread(java.lang.String name,
                  java.lang.Object tid,
                  TaskScheduler sched)
Method Detail

getState

public byte getState()
Returns the state of the thread

Returns:
the state of the thread

waitState

public boolean waitState(byte state)
                  throws java.lang.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
Throws:
java.lang.InterruptedException

getId

public java.lang.Object getId()

addTask

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

Parameters:
a - the task ot be added

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

resetTaskNumber

public void resetTaskNumber()

getTaskNumber

public long getTaskNumber()

toString

public java.lang.String toString()

deleteTasksUpTo

public void deleteTasksUpTo(long upToSN)


Copyright © 2000-2002 France Telecom S.A., INRIA, IMAG-LSR All Rights Reserved.