org.bushe.swing.event
Class EventServiceLocator

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

public class EventServiceLocator
extends Object

A central registry of EventServices. Used by the EventBus.

By default will lazily hold a SwingEventService, which is mapped to SERVICE_NAME_SWING_EVENT_SERVICE and returned by getSwingEventService(). Also by default this same instance is returned by getEventBusService(), is mapped to SERVICE_NAME_EVENT_BUS and wrapped by the EventBus.

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.

To change the default implementation class for the EventBus' EventService, use the API:

 EventServiceLocator.setEventService(EventServiceLocator.SERVICE_NAME_EVENT_BUS, new SomeEventServiceImpl());
 
Or use system properties by:
 System.setProperty(EventServiceLocator.SERVICE_NAME_EVENT_BUS, YourEventServiceImpl.class.getName());
 
Likewise, you can set this on the command line via -Dorg.bushe.swing.event.swingEventServiceClass=foo.YourEventServiceImpl

To change the default implementation class for the SwingEventService, use the API:

 EventServiceLocator.setEventService(EventServiceLocator.SERVICE_NAME_SWING_EVENT_SERVICE, new SomeSwingEventServiceImpl());
 
Or use system properties by:
 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


Field Summary
static String EVENT_BUS_CLASS
          Set this Java property to a Class that implements EventService to use an instance of that class instead of the instance returned by getSwingEventService().
static String SERVICE_NAME_EVENT_BUS
          The name "EventBus" is reserved for the service that the EventBus wraps and is returned by getEventBusService().
static String SERVICE_NAME_SWING_EVENT_SERVICE
          The name "SwingEventService" is reserved for the service that is returned by getSwingEventService().
static String SWING_EVENT_SERVICE_CLASS
          Set this Java property to a Class that implements EventService to use an instance of that class instead of SwingEventService as service returned by getSwingEventService().
 
Constructor Summary
EventServiceLocator()
           
 
Method Summary
static EventService getEventBusService()
           
static EventService getEventService(String serviceName)
           
static EventService getSwingEventService()
           
static void setEventService(String serviceName, EventService es)
          Registers 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 String SERVICE_NAME_EVENT_BUS
The name "EventBus" is reserved for the service that the EventBus wraps and is returned by getEventBusService().

See Also:
Constant Field Values

SERVICE_NAME_SWING_EVENT_SERVICE

public static final String SERVICE_NAME_SWING_EVENT_SERVICE
The name "SwingEventService" is reserved for the service that is returned by getSwingEventService().

See Also:
Constant Field Values

EVENT_BUS_CLASS

public static final String EVENT_BUS_CLASS
Set this Java property to a Class that implements EventService to use an instance of that class instead of the instance returned by getSwingEventService(). Must be set before getEventBusService() is called.

See Also:
Constant Field Values

SWING_EVENT_SERVICE_CLASS

public static final String SWING_EVENT_SERVICE_CLASS
Set this Java property to a Class that implements EventService to use an instance of that class instead of SwingEventService as service returned by getSwingEventService(). Must be set on startup or before the method getSwingEventService()is called.

See Also:
Constant Field Values
Constructor Detail

EventServiceLocator

public EventServiceLocator()
Method Detail

getEventBusService

public static EventService getEventBusService()
Returns:
the singleton instance of the EventService used by the EventBus

getSwingEventService

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

getEventService

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

setEventService

public static void setEventService(String serviceName,
                                   EventService es)
                            throws EventServiceExistsException
Registers a named EventService to the locator. Can be used to change the default 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 and the new service is non-null


Copyright © 2011 Bushe Enterprises, Inc.. All Rights Reserved.