All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class guinea.util.EventQueue

java.lang.Object
   |
   +----guinea.util.EventQueue

public abstract class EventQueue
extends Object
The EventQueue class provides a base class for implementing a event queue. The event queue uses a separate thread to dispatch the event to interested event listeners. The event dispatching thread can be shared with multiple event queues.


Variable Index

· dispatcher
The event dispatcher thread.
· eventQueue
The queue used to send and receive events.
· isShared
Is this queue shared to other queues.
· quitThreadMarker
Dispatcher thread quit thread marker.
· sharedQueue
The queue we are sharing.
· threadName
Name for the dispatcher thread.

Constructor Index

· EventQueue()
Construct a new event queue with no name.
· EventQueue(EventQueue)
Construct a new event queue by sharing the event queue and thread of another event queue.
· EventQueue(String)
Construct a new event queue with given name for the dispatcher thread.

Method Index

· addListener()
Called as the first thing in all sub-classes' add*Listener methods.
· hasListeners()
Is there any more event listeners.
· postEvent(EventObject)
Put an event to the event queue.
· postEvent(EventObject, EventQueue)
Put an event to the event queue.
· processEvent(EventObject)
Process the event and send it to all listeners.
· removeListener()
Called as the last thing in all sub-classes' remove*Listener methods.
· setShared()
Mark this queue as shared.

Variables

· eventQueue
 protected Queue eventQueue
The queue used to send and receive events.

· dispatcher
 protected Thread dispatcher
The event dispatcher thread.

· threadName
 protected String threadName
Name for the dispatcher thread.

· quitThreadMarker
 protected static final Object quitThreadMarker
Dispatcher thread quit thread marker.

· sharedQueue
 protected final EventQueue sharedQueue
The queue we are sharing.

· isShared
 protected boolean isShared
Is this queue shared to other queues.

Constructors

· EventQueue
 public EventQueue()
Construct a new event queue with no name.

· EventQueue
 public EventQueue(String name)
Construct a new event queue with given name for the dispatcher thread.

Parameters:
name - the name for the dispatcher thread.
· EventQueue
 public EventQueue(EventQueue share)
Construct a new event queue by sharing the event queue and thread of another event queue.

Parameters:
share - the other event queue whose queue to share.

Methods

· hasListeners
 public abstract boolean hasListeners()
Is there any more event listeners.

Returns:
true if there are listeners registered.
· setShared
 protected synchronized void setShared()
Mark this queue as shared. When a event queue is shared, several event queues use the same queue object and thread to dispatch the events. When a queue has been marked shared, it will not terminate the thread when all listeners have been removed. (it doesn't know whether the sharing queues still have listeners, knows only about the initial queue which is shared.

· postEvent
 protected void postEvent(EventObject e)
Put an event to the event queue. The dispatcher thread will receive the event from the queue and sends it to registered listeners. By default this will call postEvent(e, this).

Parameters:
e - an event to be sent.
· postEvent
 protected void postEvent(EventObject e,
                          EventQueue eq)
Put an event to the event queue. The dispatcher thread will receive the event from the queue and sends it to registered listeners.

Parameters:
e - an event to be sent.
eq - the event queue that originated this event.
· addListener
 protected synchronized void addListener()
Called as the first thing in all sub-classes' add*Listener methods. When this is called the first time the event queue and the dispatcher thread are created.

· removeListener
 protected synchronized void removeListener()
Called as the last thing in all sub-classes' remove*Listener methods. When the last listener is removed, the dispatcher thread will be terminated and the internal event queue is removed if the queue isn't shared with other event queues.

· processEvent
 protected void processEvent(EventObject event)
Process the event and send it to all listeners. This is called by the dispatcher thread. Subclasses should extend this method to recognize its event types and process them appropiately. If an unknown event type is received, subclasses should pass it to super-class via super.processEvent(event) call.

Parameters:
event - the event to be sent to listeners.

All Packages  Class Hierarchy  This Package  Previous  Next  Index