01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.async.api;
06:
07: import com.tc.logging.TCLogger;
08: import com.tc.logging.TCLogging;
09:
10: import java.util.Collection;
11: import java.util.Iterator;
12:
13: /**
14: * Simple superclass for event handlers that does the iterating over events in the array
15: *
16: * @author steve
17: */
18: public abstract class AbstractEventHandler implements EventHandler {
19:
20: private ConfigurationContext configContext;
21: private TCLogger logger;
22:
23: public abstract void handleEvent(EventContext context)
24: throws EventHandlerException;
25:
26: public void handleEvents(Collection contexts)
27: throws EventHandlerException {
28: for (Iterator i = contexts.iterator(); i.hasNext();) {
29: EventContext eh = (EventContext) i.next();
30: handleEvent(eh);
31: }
32: }
33:
34: public synchronized final void initializeContext(
35: ConfigurationContext context) {
36: if (context == null) {
37: this .logger = TCLogging.getLogger(this .getClass());
38: logger
39: .warn("Setting config context to null. This is highly unusual");
40: } else {
41: this .logger = context.getLogger(this .getClass());
42: }
43: this .configContext = context;
44: initialize(context);
45: }
46:
47: protected void initialize(ConfigurationContext context) {
48: // Subclasses can override this.
49: }
50:
51: public TCLogger getLogger() {
52: return logger;
53: }
54:
55: public synchronized void destroy() {
56: configContext = null;
57: }
58:
59: /**
60: * @return the ConfigurationContext object that was passed to the <code>initialize</code> method.
61: */
62: protected synchronized ConfigurationContext getConfigurationContext() {
63: return configContext;
64: }
65:
66: }
|