FileDocCategorySizeDatePackage
ThreadedEventQueue.javaAPI DocJMF 2.1.1e2386Mon May 12 12:20:44 BST 2003com.sun.media.util

ThreadedEventQueue

public abstract class ThreadedEventQueue extends MediaThread
A utility class to manage an event queue in a thread. To use it, subclass from it and implement the processEvent() method.
version
1.4, 02/08/21

Fields Summary
private Vector
eventQueue
private boolean
killed
Constructors Summary
public ThreadedEventQueue()


      
	useControlPriority();
    
Methods Summary
protected booleandispatchEvents()
Wait until there is something in the event queue to process. Then dispatch the event to the listeners.The entire method does not need to be synchronized since this includes taking the event out from the queue and processing the event. We only need to provide exclusive access over the code where an event is removed from the queue.


	ControllerEvent evt = null;
	
	synchronized (this){
	    
	    // Wait till there is an event in the event queue.
	    try {
		while (!killed && eventQueue.size() == 0)
		    wait();
	    } catch (InterruptedException e) {
		System.err.println("MediaNode event thread " + e);
		return true;
	    }

	    // Remove the event from the queue and dispatch it to the listeners.
	    if (eventQueue.size() > 0) {
	    	evt = (ControllerEvent)eventQueue.firstElement();
	    	eventQueue.removeElementAt(0);
	    }

	} // end of synchronized

	if (evt != null)
	    processEvent(evt);

	// We have to finish delivering all the events before dying.

	return (!killed || eventQueue.size() != 0);
    
public synchronized voidkill()
kill the thread.

	killed = true;
	notifyAll();
    
public synchronized voidpostEvent(javax.media.ControllerEvent evt)
Queue the given event in the event queue.

	eventQueue.addElement(evt);
	notifyAll();
    
protected abstract voidprocessEvent(javax.media.ControllerEvent evt)
Invoked when there is at least one event in the queue. Implement this as a callback to process one event.

public voidrun()
An inifinite while loop to dispatch ControllerEvent.

	while (dispatchEvents()) {
	    // Deliberately empty.
	}