public class SlowTaskException extends Exception
However Handles cannot be used by system threads and so a static method is provided that will provide a SlowTaskException ONLY if the current thread is not a system thread. The method that wants to throw such an exception can then call this static method and check if a SlowTaskException was returned. If one was, then it can start up a new Thread to perform the task, and use the handle to report the progress of the operation. If a SlowTaskException was not returned, then it should just go ahead and do the task as normal.
Constructor and Description |
---|
SlowTaskException(Handle h) |
SlowTaskException(String message,
Handle h) |
Modifier and Type | Method and Description |
---|---|
static boolean |
canThrow()
This returns if a SlowTaskException is appropriate to be thrown here.
|
static Object |
checkSlowTask(Handle runningTask,
int waitBeforeThrowing)
Let the runningTask run for a certain length of time before throwing
a SlowTaskException.
|
static Object |
checkSlowTask(int waitBeforeThrowing,
Task taskToRun)
Start a Task and let it run for a certain length of time before throwing
a SlowTaskException.
|
static Object |
checkSlowTask(Object target,
Class targetClass,
String method,
Object[] parameters,
int waitBeforeThrowing)
Execute a method on a target Object in a separate Task and then call checkSlowTask
on the running Task.
|
static Object |
checkSlowTask(Object target,
Method method,
Object[] parameters,
int waitBeforeThrowing)
Execute a method on a target Object in a separate Task and then call checkSlowTask
on the running Task.
|
Handle |
getHandle()
Get the handle for the task being performed.
|
static SlowTaskException |
getNew()
This returns a new SlowTaskException ONLY if the calling thread is not a System Thread.
|
static SlowTaskException |
getNew(String message)
This returns a new SlowTaskException ONLY if the calling thread is not a system thread.
|
static SlowTaskException |
getNew(String message,
Handle h)
This returns a new SlowTaskException ONLY if the calling thread is not in a System Thread.
|
SlowTaskException |
setHandle(Handle h) |
Object |
waitForReturnValue()
This waits until the Handle of the SlowTaskException has stopped and
then returns the returnValue.
|
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
public SlowTaskException(Handle h)
public SlowTaskException setHandle(Handle h)
public Handle getHandle()
public static SlowTaskException getNew(String message)
message
- An optional message for the exception.public static SlowTaskException getNew(String message, Handle h)
message
- An optional message for the exception.h
- A Handle to be used for the task.public static SlowTaskException getNew()
public static boolean canThrow()
public static Object checkSlowTask(int waitBeforeThrowing, Task taskToRun) throws SlowTaskException
If the current Thread is a System Thread this method runs the task directly within this Thread and so a SlowTaskException is never thrown.
waitBeforeThrowing
- how long to wait before considering it slow
and throwing a SlowTaskException. If this is zero then the SlowTaskException
is always thrown.taskToRun
- the task to run that may take too long.SlowTaskException
public static Object checkSlowTask(Handle runningTask, int waitBeforeThrowing) throws SlowTaskException
runningTask
- the running task that may take too long.waitBeforeThrowing
- how long to wait before considering it slow
and throwing a SlowTaskException. If this is zero then the SlowTaskException
is always thrown.SlowTaskException
public static Object checkSlowTask(Object target, Method method, Object[] parameters, int waitBeforeThrowing) throws SlowTaskException
target
- the target object which may be null if the method is static.method
- the method to invoke.parameters
- any parameters for the method.waitBeforeThrowing
- the length of time in milliseconds to wait
before throwing the SlowTaskException.SlowTaskException
public static Object checkSlowTask(Object target, Class targetClass, String method, Object[] parameters, int waitBeforeThrowing) throws SlowTaskException
target
- the target object which may be null if the method is static.method
- the method to invoke.parameters
- any parameters for the method.waitBeforeThrowing
- the length of time in milliseconds to wait
before throwing the SlowTaskException.SlowTaskException
public Object waitForReturnValue()