org.bushe.swing.event
Class EventServiceLocator

java.lang.Object
  extended by org.bushe.swing.event.EventServiceLocator

public class EventServiceLocator
extends java.lang.Object

A ServiceLocator pattern class for getting an instance of an EventService. Nothin' fancy, since the EventService is intended for a single VM. Allows mulitple named EventServices to be discovered.

Holds the singleton Swing event service, which is wrapped by the EventBus, which is returned by getSwingEventService and mapped to the service name SERVICE_NAME_EVENT_BUS ("EventBus"). This is not settable.

Since the default EventService implementation is thread safe, and since it's not good to have lots of events on the EventDispatchThread you may want multiple EventServices running on multiple threads, perhaps pulling events from a server and coalescing them into one or more events that are pushed onto the EDT.

The EventServiceLocator is used by the EventBus to locate the implementation of the SwingEventService the EventBus delegates all its calls to. To change the default implementation class from SwingEventService to your own class, call:

 System.setProperty(EventServiceLocator.SWING_EVENT_SERVICE_CLASS, YourEventServiceImpl.class.getName());
 
Likewise, you can set this on the command line via -Dorg.bushe.swing.event.swingEventServiceClass=foo.YourEventServiceImpl

Author:
Michael Bushe michael@bushe.com

Field Summary
static java.lang.String SERVICE_NAME_EVENT_BUS
          The name "EventBus" is reserved for the service that the EventBus wraps.
static java.lang.String SWING_EVENT_SERVICE_CLASS
          Set this Java property to a Class that implements EventService to use that class instead of SwingEventService as the swing EventBus.
 
Constructor Summary
EventServiceLocator()
           
 
Method Summary
static EventService getEventService(java.lang.String serviceName)
           
static EventService getSwingEventService()
           
static void setEventService(java.lang.String serviceName, EventService es)
          Add a named EventService to the locator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVICE_NAME_EVENT_BUS

public static final java.lang.String SERVICE_NAME_EVENT_BUS
The name "EventBus" is reserved for the service that the EventBus wraps.

See Also:
Constant Field Values

SWING_EVENT_SERVICE_CLASS

public static final java.lang.String SWING_EVENT_SERVICE_CLASS
Set this Java property to a Class that implements EventService to use that class instead of SwingEventService as the swing EventBus. Must be set on startup or before the SwingEventService is created.

See Also:
Constant Field Values
Constructor Detail

EventServiceLocator

public EventServiceLocator()
Method Detail

getSwingEventService

public static EventService getSwingEventService()
Returns:
the singleton default instance of a SwingEventService

getEventService

public static EventService getEventService(java.lang.String serviceName)
Parameters:
serviceName - the service name of the EventService, as registered by #setEventService(String, EventService), or SERVICE_NAME_EVENT_BUS.
Returns:
a named event service instance

setEventService

public static void setEventService(java.lang.String serviceName,
                                   EventService es)
                            throws EventServiceExistsException
Add a named EventService to the locator.

Using this method does not change the EventBus implementation or the getSwingEventService() result. See this class' javadoc for information on how to change the EventBus implementation.

Parameters:
serviceName - a named event service instance
es - the EventService to attach to the service name
Throws:
EventServiceExistsException - if a service by this name already exists or if serviceName is "EventBus"