- Type Parameters:
C
- type of componentR
- type of result that may be returned when the desired condition arises
- Direct Known Subclasses:
MediaPlayerWaiter
,MediaWaiter
This implementation works by adding a temporary event listener to an associated component then waiting, via
await()
, for an internal synchronisation object to trigger, via ready()
or ready(Object)
when one or other of the event listener's implementation methods detects the desired component event. The temporary
event listener is then removed and the await()
method is unblocked and returns.
Commonly needed triggers are implemented for error()
and finished()
.
This facilitates a semblance of synchronous or sequential programming.
Sub-classes have access to the associated component
if needed.
Sub-classes may also override onBefore(Object)
and onAfter(Object, Object)
to implement behaviour
that executes respectively before awaiting the condition and after the condition state is reached.
Using onBefore(Object)
guarantees that the component event listener has been registered with the media
player before the condition implementation is executed (e.g. an implementation of this method could check if the
condition they would otherwise wait for has already been achieved).
Note that as with other media player and related component implementations the event callbacks are running in a native thread.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Waiter
-
-
Method Details
-
await
public final R await() throws InterruptedException, UnexpectedWaiterErrorException, UnexpectedWaiterFinishedExceptionWait for the required condition to occur.- Returns:
- optional result
- Throws:
InterruptedException
- if the condition was interrupted while waitingUnexpectedWaiterErrorException
- if an unexpected error occurredUnexpectedWaiterFinishedException
- if the condition finished unexpectedly
-