org.openbandy.service
Class EventService

java.lang.Object
  extended by org.openbandy.service.Service
      extended by org.openbandy.service.EventService

public final class EventService
extends Service

The EventService acts as a router between EventSources and EventSinks. Events are either generated by event sources, which use this service to dispatch the events to the subscribed sinks, or they can be created by any other class or service. The distinction of event types is made by the events shortClassName (@see StringUtil), as for example 'ObjectEvent'. As event sources are implemented as threads, we suggest to register every source at the event service. This way it is possible to only start sources when there actually is an event sink interest in the type of event provided. Thus, as soon as an event sink is registered @ the event service, it tries to start the needed event sources. If no sources are available, the event sink stays registered and corresponding sources are started as soon as they are registered at the event service. If an event source is unregistered that provided an event type that is absorbed by a registered event sink, the affected event sink will be informed via lostEventSource.

(c) Copyright P. Bolliger 2007, ALL RIGHTS RESERVED.

Version:
1.0
Author:
Philipp Bolliger (philipp@bolliger.name)

Constructor Summary
EventService()
           
 
Method Summary
static void dispatch(Event event)
          This methods forwards the provided Event to every EventSink that has been registered for this type of Event.
static void registerSource(EventSource eventSource)
          This method registers an EventSource with every type of event it provides.
static void subscribe(EventSink eventSink, EventFilter filter)
          This method registers an EventSink with every type of event it absorbs.
static void unregisterSource(EventSource eventSource)
          Unregister an EventSource.
static void unsubscribe(EventSink eventSink)
          Unsubscribe an EventSink.
 
Methods inherited from class org.openbandy.service.Service
runningOnMicroEdition, runningOnSunWTK
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventService

public EventService()
Method Detail

registerSource

public static void registerSource(EventSource eventSource)
This method registers an EventSource with every type of event it provides. A thus registered source will be started as soon as a sink registers for a corresponding event type. If no sink is interested in the type of event provided by this source, it will be stopped eventually.

Parameters:
eventSource - The source to register.

subscribe

public static void subscribe(EventSink eventSink,
                             EventFilter filter)
This method registers an EventSink with every type of event it absorbs. Every event that is absorbed by this sink will henceforth be delegate to this sink. If an EventFilter is provided, the events will be delegated to the filter which then eventually forwards the events to the subscribed EventSink.

Parameters:
eventSink - The sink to register.

unregisterSource

public static void unregisterSource(EventSource eventSource)
Unregister an EventSource.

Parameters:
eventSource - The source to unregister.

unsubscribe

public static void unsubscribe(EventSink eventSink)
Unsubscribe an EventSink.

Parameters:
eventSink - The sink to unregister.

dispatch

public static void dispatch(Event event)
This methods forwards the provided Event to every EventSink that has been registered for this type of Event. Registration (i.e. distinction) of Events is made by the Events shortClassName (@see StringUtil), as for example 'ObjectEvent'.

Parameters:
event - The event that has to be routed.