com.mozu.api.events.EventManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mozu-api-core Show documentation
Show all versions of mozu-api-core Show documentation
Mozu Java is a SDK that enables you to create robust Java applications that integrate with the Mozu platform
package com.mozu.api.events;
import java.util.HashMap;
import java.util.Map;
import com.mozu.api.ApiException;
/**
* Manage handlers registered to process events. Handlers implement
* one or several event interfaces. When the handler registers, an
* entry is created that associates the handler with an event category
* of the type specified by the interface(s) implemented.
*
* @author john_gatti
*
*/
public class EventManager {
private static final String EVENT_INTERFACE_SUFFIX = "EventHandler";
// A map of registered handlers by handler interface type (category) with
// full name of the handler
// Event interfaces are named in the form [Category]EventHandler (e.g. ProductEventHandler)
private Map eventHandlers = null;
private static EventManager eventManager = null;
protected EventManager()
{
eventHandlers = new HashMap();
};
protected void clearEventHandlers() {
eventHandlers.clear();
}
public static final synchronized EventManager getInstance() {
if (eventManager==null) {
eventManager = new EventManager();
}
return eventManager;
}
/**
* Register an event handler. The registration looks at the interfaces
* that the handler implements. An entry is created in the event handler
* map for each event interface that is implemented.
*
* Event interfaces are named in the form [Category]Event (e.g. ProductEvent)
*
* @param handler handler class
*/
public synchronized void registerHandler(Object handler) {
boolean validClass = false;
if (handler==null) {
throw new IllegalArgumentException("Null handler class");
}
// Get the implemented interfaces. This gets only the
// directly implemented interfaces
Class> clazz = handler.getClass();
Class> interfaces[] = clazz.getInterfaces();
for (int i=0; i handler) {
// Get the implemented interfaces. This gets only the
// directly implemented interfaces
Class> interfaces[] = handler.getInterfaces();
for (int i=0; i