net.sf.fmj.ejmf.toolkit.util
Class StateWaiter

java.lang.Object
  extended by net.sf.fmj.ejmf.toolkit.util.StateWaiter
All Implemented Interfaces:
ControllerListener

public class StateWaiter
extends java.lang.Object
implements ControllerListener

The StateWaiter class provides routines to allow the current thread to wait for a Controller to reach a particular state. A StateWaiter object will first register itself as a ControllerListener on the given Controller object. It will then set the state to be waited for, and block the current thread until either

From the book: Essential JMF, Gordon, Talley (ISBN 0130801046). Used with permission.

Author:
Steve Talley and Rob Gordon

Constructor Summary
StateWaiter(Controller controller)
          Construct a StateWaiter object for the given Controller
 
Method Summary
 boolean blockingConfigure()
           
 boolean blockingPrefetch()
          Calls prefetch() on the Controller and blocks the current thread until the Controller is Prefetched.
 boolean blockingRealize()
          Calls realize() on the Controller and blocks the current thread until the Controller is Realized.
 boolean blockingStart()
          Casts the Controller to a Player, calls start(), and blocks the current thread until the player is Started.
 boolean blockingSyncStart(Time t)
          Calls syncStart() on the Controller and blocks the current thread until the Controller is Started.
 boolean blockingWait(int state)
           
 void controllerUpdate(ControllerEvent event)
          Listens for a transition to the state that this StateWaiter is waiting for.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateWaiter

public StateWaiter(Controller controller)
Construct a StateWaiter object for the given Controller

Parameters:
controller - the Controller on which to wait for the desired state
Method Detail

controllerUpdate

public void controllerUpdate(ControllerEvent event)
Listens for a transition to the state that this StateWaiter is waiting for. Notifies the the waiting thread and stops listening if any of the following occur:

Specified by:
controllerUpdate in interface ControllerListener
Parameters:
event - the media event

blockingRealize

public boolean blockingRealize()
Calls realize() on the Controller and blocks the current thread until the Controller is Realized.

Returns:
boolean indicating whether the transition was successful.

blockingPrefetch

public boolean blockingPrefetch()
Calls prefetch() on the Controller and blocks the current thread until the Controller is Prefetched.

Returns:
boolean indicating whether the transition was successful.

blockingStart

public boolean blockingStart()
Casts the Controller to a Player, calls start(), and blocks the current thread until the player is Started.

Returns:
boolean indicating whether the transition was successful.
Throws:
java.lang.ClassCastException - If the Controller is not a Player

blockingSyncStart

public boolean blockingSyncStart(Time t)
Calls syncStart() on the Controller and blocks the current thread until the Controller is Started. This could throw a ClockStartedError if the Controller is not in the Prefetched state.

Returns:
boolean indicating whether the transition was successful.

blockingConfigure

public boolean blockingConfigure()

blockingWait

public boolean blockingWait(int state)