APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.event

public Class InvocationEvent

extends AWTEvent
implements ActiveEvent
Class Inheritance
All Implemented Interfaces
java.awt.ActiveEvent
Known Direct Subclasses
sun.awt.PeerEvent
Imports
java.awt.AWTEvent, .ActiveEvent, java.io.Serial, sun.awt.AWTAccessor

An 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.

An unspecified behavior will be caused if the id parameter of any particular InvocationEvent instance is not in the range from INVOCATION_FIRST to INVOCATION_LAST.

Authors
Fred Ecks, David Mendenhall
Since
1.2
See Also
java.awt.ActiveEvent, java.awt.EventQueue#invokeLater, java.awt.EventQueue#invokeAndWait, AWTEventListener

Field Summary

Modifier and TypeField and Description
protected boolean
catchExceptions

Set to true if dispatch() catches Throwable and stores it in the exception instance variable.

private volatile boolean
private Exception
public static final int
INVOCATION_DEFAULT

The default id for all InvocationEvents.

public static final int
INVOCATION_FIRST

Marks the first integer id for the range of invocation event ids.

public static final int
INVOCATION_LAST

Marks the last integer id for the range of invocation event ids.

private final Runnable
protected volatile Object
notifier

The (potentially null) Object whose notifyAll() method will be called immediately after the Runnable.run() method has returned or thrown an exception or after the event was disposed.

protected Runnable
runnable

The Runnable whose run() method will be called.

private static final long
serialVersionUID

Hides java.awt.AWTEvent.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.
private Throwable
private long
when

The timestamp of when this event occurred.

Inherited from java.awt.AWTEvent:
ACTION_EVENT_MASKADJUSTMENT_EVENT_MASKCOMPONENT_EVENT_MASKconsumedCONTAINER_EVENT_MASKFOCUS_EVENT_MASKHIERARCHY_BOUNDS_EVENT_MASKHIERARCHY_EVENT_MASKidINPUT_METHOD_EVENT_MASKINVOCATION_EVENT_MASKITEM_EVENT_MASKKEY_EVENT_MASKMOUSE_EVENT_MASKMOUSE_MOTION_EVENT_MASKMOUSE_WHEEL_EVENT_MASKPAINT_EVENT_MASKRESERVED_ID_MAXTEXT_EVENT_MASKWINDOW_EVENT_MASKWINDOW_FOCUS_EVENT_MASKWINDOW_STATE_EVENT_MASK

Constructor Summary

AccessConstructor and Description
public
InvocationEvent(Object
The Object that originated the event
source
,
Runnable
The Runnable whose run() method will be executed
runnable
)

Constructs an InvocationEvent with the specified source which will execute the runnable's run() method when dispatched.

public
InvocationEvent(Object
The Object that originated the event
source
,
Runnable
The Runnable whose run() method will be executed
runnable
,
Object
The Object whose notifyAll method will be called after Runnable.run has returned or thrown an exception or after the event was disposed
notifier
,
boolean
Specifies whether dispatch should catch Throwable when executing the Runnable's run() method, or should instead propagate those Throwables to the EventDispatchThread's dispatch loop
catchThrowables
)

Constructs an InvocationEvent with the specified source which will execute the runnable's run() method when dispatched.

public
InvocationEvent(Object
The Object that originated the event
source
,
Runnable
The Runnable whose run() method will be executed
runnable
,
Runnable
The Runnable whose run() method will be called after the InvocationEvent was dispatched or disposed
listener
,
boolean
Specifies whether dispatch should catch Throwable when executing the Runnable's run() method, or should instead propagate those Throwables to the EventDispatchThread's dispatch loop
catchThrowables
)

Constructs an InvocationEvent with the specified source which will execute the runnable's run() method when dispatched.

protected
InvocationEvent(Object
The Object that originated the event
source
,
int
An integer indicating the type of event. For information on allowable values, see the class description for InvocationEvent
id
,
Runnable
The Runnable whose run() method will be executed
runnable
,
Object
The Object whose notifyAll method will be called after Runnable.run has returned or thrown an exception or after the event was disposed
notifier
,
boolean
Specifies whether dispatch should catch Throwable when executing the Runnable's run() method, or should instead propagate those Throwables to the EventDispatchThread's dispatch loop
catchThrowables
)

Constructs an InvocationEvent with the specified source and ID which will execute the runnable's run() method when dispatched.

private
InvocationEvent(Object source, int id, Runnable runnable, Object notifier, Runnable listener, boolean catchThrowables)

Method Summary

Modifier and TypeMethod and Description
public void
dispatch()

Implements java.awt.ActiveEvent.dispatch.

Executes the Runnable's run() method and notifies the notifier (if any) when run() has returned or thrown an exception.

private void
finishedDispatching(boolean
true if the event was dispatched false if the event was disposed
dispatched
)

Called when the event was dispatched or disposed

public Exception

Returns:

A reference to the Exception if one was thrown; null if no Exception was thrown or if this InvocationEvent does not catch exceptions
getException
()

Returns any Exception caught while executing the Runnable's run() method.

public Throwable

Returns:

A reference to the Throwable if one was thrown; null if no Throwable was thrown or if this InvocationEvent does not catch Throwables
getThrowable
()

Returns any Throwable caught while executing the Runnable's run() method.

public long

Returns:

this event's timestamp
getWhen
()

Returns the timestamp of when this event occurred.

public boolean

Returns:

true if the event has been dispatched, or any exception has been thrown while dispatching, false otherwise
isDispatched
()

Returns true if the event is dispatched or any exception is thrown while dispatching, false otherwise.

public String

Returns:

A string identifying the event and its attributes
paramString
()

Overrides java.awt.AWTEvent.paramString.

Returns a parameter string identifying this event.

Inherited from java.awt.AWTEvent:
consumegetIDisConsumedsetSourcetoString

Field Detail

catchExceptionsback to summary
protected boolean catchExceptions

Set 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.

dispatchedback to summary
private volatile boolean dispatched
Since
1.7
See Also
isDispatched
exceptionback to summary
private Exception exception
INVOCATION_DEFAULTback to summary
public static final int INVOCATION_DEFAULT

The default id for all InvocationEvents.

INVOCATION_FIRSTback to summary
public static final int INVOCATION_FIRST

Marks the first integer id for the range of invocation event ids.

INVOCATION_LASTback to summary
public static final int INVOCATION_LAST

Marks the last integer id for the range of invocation event ids.

listenerback to summary
private final Runnable listener
Annotations
@SuppressWarnings:serial
Since
1.8
See Also
isDispatched
notifierback to summary
protected volatile Object notifier

The (potentially null) Object whose notifyAll() method will be called immediately after the Runnable.run() method has returned or thrown an exception or after the event was disposed.

Annotations
@SuppressWarnings:serial
See Also
isDispatched
runnableback to summary
protected Runnable runnable

The Runnable whose run() method will be called.

Annotations
@SuppressWarnings:serial
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.AWTEvent.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.

Annotations
@Serial
throwableback to summary
private Throwable throwable
whenback to summary
private long when

The timestamp of when this event occurred.

See Also
getWhen

Constructor Detail

InvocationEventback to 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 InvocationEvent(source, runnable, null, false).

This method throws an IllegalArgumentException if source is null.

Parameters
source:Object

The Object that originated the event

runnable:Runnable

The Runnable whose run() method will be executed

Exceptions
IllegalArgumentException:
if source is null
See Also
getSource(), InvocationEvent(Object, Runnable, Object, boolean)
InvocationEventback to summary
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() has returned or thrown an exception.

An invocation of the form InvocationEvent(source, runnable, notifier, catchThrowables) behaves in exactly the same way as the invocation of InvocationEvent(source, InvocationEvent.INVOCATION_DEFAULT, runnable, notifier, catchThrowables).

This method throws an IllegalArgumentException if source is null.

Parameters
source:Object

The Object that originated the event

runnable:Runnable

The Runnable whose run() method will be executed

notifier:Object

The Object whose notifyAll method will be called after Runnable.run has returned or thrown an exception or after the event was disposed

catchThrowables:boolean

Specifies whether dispatch should catch Throwable when executing the Runnable's run() method, or should instead propagate those Throwables to the EventDispatchThread's dispatch loop

Exceptions
IllegalArgumentException:
if source is null
See Also
getSource(), InvocationEvent(Object, int, Runnable, Object, boolean)
InvocationEventback to summary
public InvocationEvent(Object source, Runnable runnable, Runnable listener, boolean catchThrowables)

Constructs an InvocationEvent with the specified source which will execute the runnable's run() method when dispatched. If listener is non-null, listener.run() will be called immediately after run has returned, thrown an exception or the event was disposed.

This method throws an IllegalArgumentException if source is null.

Parameters
source:Object

The Object that originated the event

runnable:Runnable

The Runnable whose run() method will be executed

listener:Runnable

The Runnable whose run() method will be called after the InvocationEvent was dispatched or disposed

catchThrowables:boolean

Specifies whether dispatch should catch Throwable when executing the Runnable's run() method, or should instead propagate those Throwables to the EventDispatchThread's dispatch loop

Exceptions
IllegalArgumentException:
if source is null
InvocationEventback to summary
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() has returned or thrown an exception.

This method throws an IllegalArgumentException if source is null.

Parameters
source:Object

The Object that originated the event

id:int

An integer indicating the type of event. For information on allowable values, see the class description for InvocationEvent

runnable:Runnable

The Runnable whose run() method will be executed

notifier:Object

The Object whose notifyAll method will be called after Runnable.run has returned or thrown an exception or after the event was disposed

catchThrowables:boolean

Specifies whether dispatch should catch Throwable when executing the Runnable's run() method, or should instead propagate those Throwables to the EventDispatchThread's dispatch loop

Exceptions
IllegalArgumentException:
if source is null
See Also
getSource(), getID()
InvocationEventback to summary
private InvocationEvent(Object source, int id, Runnable runnable, Object notifier, Runnable listener, boolean catchThrowables)

Method Detail

dispatchback to summary
public void dispatch()

Implements java.awt.ActiveEvent.dispatch.

Executes the Runnable's run() method and notifies the notifier (if any) when run() has returned or thrown an exception.

See Also
isDispatched
finishedDispatchingback to summary
private void finishedDispatching(boolean dispatched)

Called when the event was dispatched or disposed

Parameters
dispatched:boolean

true if the event was dispatched false if the event was disposed

getExceptionback to summary
public Exception getException()

Returns any Exception caught while executing the Runnable's run() method.

Returns:Exception

A reference to the Exception if one was thrown; null if no Exception was thrown or if this InvocationEvent does not catch exceptions

getThrowableback to summary
public Throwable getThrowable()

Returns any Throwable caught while executing the Runnable's run() method.

Returns:Throwable

A reference to the Throwable if one was thrown; null if no Throwable was thrown or if this InvocationEvent does not catch Throwables

Since
1.5
getWhenback to summary
public long getWhen()

Returns the timestamp of when this event occurred.

Returns:long

this event's timestamp

Since
1.4
isDispatchedback to summary
public boolean isDispatched()

Returns true if the event is dispatched or any exception is thrown while dispatching, false otherwise. The method should be called by a waiting thread that calls the notifier.wait() method. Since spurious wakeups are possible (as explained in Object#wait()), this method should be used in a waiting loop to ensure that the event got dispatched:

    while (!event.isDispatched()) {
        notifier.wait();
    }
If the waiting thread wakes up without dispatching the event, the isDispatched() method returns false, and the while loop executes once more, thus, causing the awakened thread to revert to the waiting mode.

If the notifier.notifyAll() happens before the waiting thread enters the notifier.wait() method, the while loop ensures that the waiting thread will not enter the notifier.wait() method. Otherwise, there is no guarantee that the waiting thread will ever be woken from the wait.

Returns:boolean

true if the event has been dispatched, or any exception has been thrown while dispatching, false otherwise

Since
1.7
See Also
dispatch, notifier, catchExceptions
paramStringback to summary
public String paramString()

Overrides java.awt.AWTEvent.paramString.

Returns a parameter string identifying this event. This method is useful for event-logging and for debugging.

Returns:String

A string identifying the event and its attributes