org.exolab.jmscts.core
Class ThreadedAction

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.exolab.jmscts.core.ThreadedAction
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
DelayedAction, ThreadedActions, ThreadedReceiver, ThreadedSender

public abstract class ThreadedAction
extends java.lang.Thread

Helper class to run an action in a separate thread, and catch any exception that the action generates.

Version:
$Revision: 1.5 $ $Date: 2004/01/31 13:44:24 $
Author:
Tim Anderson

Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ThreadedAction()
          Construct a new ThreadedAction
ThreadedAction(CompletionListener listener)
          Construct a new ThreadedAction, with a listener to notify on completion
 
Method Summary
 long getElapsedTime()
          Returns the elapsed time of the action.
 java.lang.Exception getException()
          Returns any exception thrown by runProtected(), or null, if no exception was thrown
 void run()
          Run the action.
abstract  void runProtected()
          Run the action
protected  void setException(java.lang.Exception exception)
          Set the exception
 void waitForCompletion()
          Wait for the action to complete
 boolean waitForCompletion(long timeout)
          Wait for the action to complete
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ThreadedAction

public ThreadedAction()
Construct a new ThreadedAction

ThreadedAction

public ThreadedAction(CompletionListener listener)
Construct a new ThreadedAction, with a listener to notify on completion
Parameters:
listener - the listener to notify on completion
Method Detail

run

public void run()
Run the action. This delegates to runProtected().
If a CompletionListener was supplied, it will be notified on completion of the action.
Overrides:
run in class java.lang.Thread

runProtected

public abstract void runProtected()
                           throws java.lang.Exception
Run the action
Throws:
java.lang.Exception - for any error

getElapsedTime

public long getElapsedTime()
Returns the elapsed time of the action. This is the time taken to run runProtected()
Returns:
the elapsed time of the action, in milliseconds

getException

public java.lang.Exception getException()
Returns any exception thrown by runProtected(), or null, if no exception was thrown
Returns:
any exception thrown, or null, if none was thrown

waitForCompletion

public void waitForCompletion()
                       throws java.lang.InterruptedException
Wait for the action to complete
Throws:
java.lang.InterruptedException - if interrupted

waitForCompletion

public boolean waitForCompletion(long timeout)
                          throws java.lang.InterruptedException
Wait for the action to complete
Parameters:
timeout - the number of milleseconds to wait. An argument less than or equal to zero means not to wait at all
Returns:
true if the action completed in the given time frame
Throws:
java.lang.InterruptedException - if interrupted while waiting

setException

protected void setException(java.lang.Exception exception)
Set the exception
Parameters:
exception - the exception


Copyright © 2001-2004 JMS CTS Team. All Rights Reserved.