za.org.coefficient.events
Class EventHandlerRegistry

java.lang.Object
  extended by za.org.coefficient.events.EventHandlerRegistry

public class EventHandlerRegistry
extends java.lang.Object

Class: EventHandlerRegistry Description: EventHandlerRegistry maintains a registry of event handlers. It is used to determine which handlers should receive event notifications. NOTE: This class is implemented using the singleton patttern, which doesn't really work too well in a distributed EJB environment. It is assumed, therefore, that the app is not running in a clustered environment - i.e. this is a singleton for the entire app. Alternative approaches include storing this stuff in the database, and reading from there, or using an external RMI interface via JNDI.

Author:
tfogwill

Field Summary
private static EventHandlerRegistry instance
          Singleton instance
private static org.apache.log4j.Logger log
          Logger
private  java.util.Map registry
          Map to hold the registry data
 
Constructor Summary
private EventHandlerRegistry()
          Private constructor to prevent instantiation.
 
Method Summary
 CoefficientEventHandler[] getHandlers(java.lang.Class eventType)
          Get the handlers for the spercified event type
 CoefficientEventHandler[] getHandlers(java.lang.String eventType)
          Get the handlers for the spercified event type
static EventHandlerRegistry getInstance()
          Get the singleton instance
 void registerEventHandler(java.lang.Class eventType, CoefficientEventHandler handler)
          Register a handler with the registry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.log4j.Logger log
Logger


instance

private static EventHandlerRegistry instance
Singleton instance


registry

private java.util.Map registry
Map to hold the registry data

Constructor Detail

EventHandlerRegistry

private EventHandlerRegistry()
Private constructor to prevent instantiation.

Method Detail

getInstance

public static EventHandlerRegistry getInstance()
Get the singleton instance

Returns:
the EventHandlerRegistry instance

getHandlers

public CoefficientEventHandler[] getHandlers(java.lang.String eventType)
Get the handlers for the spercified event type

Parameters:
eventType - The event type
Returns:
the appropriate handlers

getHandlers

public CoefficientEventHandler[] getHandlers(java.lang.Class eventType)
Get the handlers for the spercified event type

Parameters:
eventType - The event type
Returns:
the appropriate handlers

registerEventHandler

public void registerEventHandler(java.lang.Class eventType,
                                 CoefficientEventHandler handler)
Register a handler with the registry. This will cause it to be notified when an event occurs that matches the specified event type. Matching is done down the class hierarchy, so a handler will be notified if events occur that are subclasses of the type it's registered to handle.

Parameters:
eventType - The base event type(class) to receive notifications about
handler - The handler which will be notified.


Copyright CSIR. All Rights Reserved.