OSMQ
v2.0.1

osmq.util
Class Threaded

java.lang.Object
  extended byosmq.util.Threaded
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
DatasetPulsarListener, DynamicPulsar, HeartbeatListener, MCResponder, ServerSocketProcessor, ServerSocketProcessor, ServiceHandler, ServicePulsar, ThreadedReader

public abstract class Threaded
extends java.lang.Object
implements java.lang.Runnable

Base class for objects that need a seperate thread to iteratively perform a task. Handles properly destroying the object when the thread terminates.


Field Summary
static int HIGH_PRIORITY
           
static int HIGHEST_PRIORITY
           
static int INCREASED_PRIORITY
           
static int VERY_HIGH_PRIORITY
           
 
Constructor Summary
Threaded()
           
 
Method Summary
 ExceptionListener getExceptionListener()
           
 long getIterations()
          Returns the number of time the derived class's iterativeProces() has been invoked successfully.
 int getPriority()
           
 int getSequenceNumber()
           
 java.lang.String getUserDefinedName()
           
 int getYieldToPeers()
           
 boolean hasTerminated()
           
 boolean isPaused()
           
 boolean isRunning()
           
 boolean isShutdownCompleted()
           
static void killAll()
           
static void killAllInGroup()
          This function destroys all the threads derived from Threaded.
 void run()
           
 void setExceptionListener(ExceptionListener listener)
          Registers a listener that will be notified if the thread is being halted due to an exception that was thrown by the derived class's iterativeProcess() method.
 void setPaused(boolean p)
           
 void setPriority(int priority)
           
 void setUserDefinedName(java.lang.String name)
           
 void setYieldCount(int yieldcount)
          Used to control whether to give up time slice to threads with the same priority.
 boolean shutdownRequested()
           
static void sleepSecs(int secs)
           
static void sleepTenths(int secs)
           
 void start()
          This method first calls the derived class's initialize() method, and then begins iteratively executing the derived class's iterativeProcess() function.
 void stop()
          Halt execution of the thread processing
 boolean successfulInit()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INCREASED_PRIORITY

public static final int INCREASED_PRIORITY
See Also:
Constant Field Values

HIGH_PRIORITY

public static final int HIGH_PRIORITY
See Also:
Constant Field Values

VERY_HIGH_PRIORITY

public static final int VERY_HIGH_PRIORITY
See Also:
Constant Field Values

HIGHEST_PRIORITY

public static final int HIGHEST_PRIORITY
See Also:
Constant Field Values
Constructor Detail

Threaded

public Threaded()
Method Detail

setUserDefinedName

public void setUserDefinedName(java.lang.String name)

getUserDefinedName

public java.lang.String getUserDefinedName()

killAllInGroup

public static void killAllInGroup()
This function destroys all the threads derived from Threaded. It should not be called except in catastrophic situations.


setExceptionListener

public void setExceptionListener(ExceptionListener listener)
Registers a listener that will be notified if the thread is being halted due to an exception that was thrown by the derived class's iterativeProcess() method.


getExceptionListener

public ExceptionListener getExceptionListener()

successfulInit

public boolean successfulInit()

start

public void start()
           throws java.lang.IllegalStateException
This method first calls the derived class's initialize() method, and then begins iteratively executing the derived class's iterativeProcess() function. The thread continues calling iterativeProcess() until the the stop() method is invoked, or an exception is thrown by the derived class's interativeProcess() function.

If an exception is thrown by the iterativeProcess() method, the exception listener (if one has been registered) will be notified.

As a final step when the thread is halted, whether by a stop() call or due to an exception being thrown, the derived class's cleanup() method will be called.

Throws:
java.lang.IllegalStateException - if the initialize() method fails or a thread could not be started.
See Also:
setExceptionListener(ExceptionListener)

setYieldCount

public void setYieldCount(int yieldcount)
Used to control whether to give up time slice to threads with the same priority. This is significant with programs that run under "green threads" (versus native OS time-sliced threads).

Parameters:
yieldcount - is the number of times to execute process before yielding to peers. The default is DEFAULT_YIELD_COUNT. A value of 0 turns off yeilding.

getYieldToPeers

public int getYieldToPeers()

getIterations

public long getIterations()
Returns the number of time the derived class's iterativeProces() has been invoked successfully.


run

public final void run()
Specified by:
run in interface java.lang.Runnable

setPriority

public void setPriority(int priority)

getPriority

public int getPriority()

getSequenceNumber

public int getSequenceNumber()

isShutdownCompleted

public boolean isShutdownCompleted()

killAll

public static final void killAll()

isRunning

public boolean isRunning()

hasTerminated

public boolean hasTerminated()

stop

public void stop()
Halt execution of the thread processing


shutdownRequested

public boolean shutdownRequested()

setPaused

public void setPaused(boolean p)

isPaused

public boolean isPaused()

sleepTenths

public static void sleepTenths(int secs)

sleepSecs

public static void sleepSecs(int secs)

(c) 2000 - 2003 MQue Systems
All Rights Reserved