InvocationEventpublic class InvocationEvent extends AWTEvent implements ActiveEventAn event which executes the run() method on a Runnable
when dispatched by the AWT event dispatcher thread. This class can
be used as a reference implementation of ActiveEvent rather
than declaring a new class and defining dispatch() .
Instances of this class are placed on the EventQueue by calls
to invokeLater and invokeAndWait . Client code
can use this fact to write replacement functions for invokeLater
and invokeAndWait without writing special-case code
in any AWTEventListener objects. |
Fields Summary |
---|
public static final int | INVOCATION_FIRSTMarks the first integer id for the range of invocation event ids. | public static final int | INVOCATION_DEFAULTThe default id for all InvocationEvents. | public static final int | INVOCATION_LASTMarks the last integer id for the range of invocation event ids. | protected Runnable | runnableThe Runnable whose run() method will be called. | protected Object | notifierThe (potentially null) Object whose notifyAll() method will be called
immediately after the Runnable.run() method returns. | protected boolean | catchExceptionsSet to true if dispatch() catches Throwable and stores it in the
exception instance variable. If false, Throwables are propagated up
to the EventDispatchThread's dispatch loop. | private Exception | exceptionThe (potentially null) Exception thrown during execution of the
Runnable.run() method. This variable will also be null if a particular
instance does not catch exceptions. | private Throwable | throwableThe (potentially null) Throwable thrown during execution of the
Runnable.run() method. This variable will also be null if a particular
instance does not catch exceptions. | private long | whenThe timestamp of when this event occurred. | private static final long | serialVersionUID |
Constructors Summary |
---|
public InvocationEvent(Object source, Runnable runnable)Constructs an InvocationEvent with the specified
source which will execute the runnable's run
method when dispatched.
This is a convenience constructor. An invocation of the form
InvocationEvent(source, runnable)
behaves in exactly the same way as the invocation of
{@link #InvocationEvent(Object, Runnable, Object, boolean) InvocationEvent}(source, runnable, null, false).
This method throws an IllegalArgumentException
if source is null .
this(source, runnable, null, false);
| public InvocationEvent(Object source, Runnable runnable, Object notifier, boolean catchThrowables)Constructs an InvocationEvent with the specified
source which will execute the runnable's run
method when dispatched. If notifier is non-null ,
notifyAll() will be called on it
immediately after run returns.
An invocation of the form InvocationEvent(source,
runnable, notifier, catchThrowables)
behaves in exactly the same way as the invocation of
{@link #InvocationEvent(Object, int, Runnable, Object, boolean) InvocationEvent}(source, InvocationEvent.INVOCATION_DEFAULT, runnable, notifier, catchThrowables).
This method throws an IllegalArgumentException
if source is null .
this(source, INVOCATION_DEFAULT, runnable, notifier, catchThrowables);
| protected InvocationEvent(Object source, int id, Runnable runnable, Object notifier, boolean catchThrowables)Constructs an InvocationEvent with the specified
source and ID which will execute the runnable's run
method when dispatched. If notifier is non-null ,
notifyAll will be called on it
immediately after run returns.
Note that passing in an invalid id results in
unspecified behavior. This method throws an
IllegalArgumentException if source
is null .
super(source, id);
this.runnable = runnable;
this.notifier = notifier;
this.catchExceptions = catchThrowables;
this.when = System.currentTimeMillis();
|
Methods Summary |
---|
public void | dispatch()Executes the Runnable's run() method and notifies the
notifier (if any) when run() returns.
if (catchExceptions) {
try {
runnable.run();
}
catch (Throwable t) {
if (t instanceof Exception) {
exception = (Exception) t;
}
throwable = t;
}
}
else {
runnable.run();
}
if (notifier != null) {
synchronized (notifier) {
notifier.notifyAll();
}
}
| public java.lang.Exception | getException()Returns any Exception caught while executing the Runnable's run()
method.
return (catchExceptions) ? exception : null;
| public java.lang.Throwable | getThrowable()Returns any Throwable caught while executing the Runnable's run()
method.
return (catchExceptions) ? throwable : null;
| public long | getWhen()Returns the timestamp of when this event occurred.
return when;
| public java.lang.String | paramString()Returns a parameter string identifying this event.
This method is useful for event-logging and for debugging.
String typeStr;
switch(id) {
case INVOCATION_DEFAULT:
typeStr = "INVOCATION_DEFAULT";
break;
default:
typeStr = "unknown type";
}
return typeStr + ",runnable=" + runnable + ",notifier=" + notifier +
",catchExceptions=" + catchExceptions + ",when=" + when;
|
|