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.objectserver.handler;
06:
07: import com.tc.async.api.AbstractEventHandler;
08: import com.tc.async.api.ConfigurationContext;
09: import com.tc.async.api.EventContext;
10: import com.tc.logging.TCLogger;
11: import com.tc.logging.TCLogging;
12: import com.tc.object.ObjectID;
13: import com.tc.objectserver.api.ObjectManager;
14: import com.tc.objectserver.context.ManagedObjectFaultingContext;
15: import com.tc.objectserver.core.api.ManagedObject;
16: import com.tc.objectserver.core.api.ServerConfigurationContext;
17: import com.tc.objectserver.persistence.api.ManagedObjectStore;
18: import com.tc.properties.TCPropertiesImpl;
19:
20: public class ManagedObjectFaultHandler extends AbstractEventHandler {
21:
22: private static final TCLogger logger = TCLogging
23: .getLogger(ManagedObjectFaultHandler.class);
24: private static final boolean LOG_OBJECT_FAULT = TCPropertiesImpl
25: .getProperties().getBoolean(
26: "l2.objectmanager.fault.logging.enabled");
27:
28: private ObjectManager objectManager;
29: private ManagedObjectStore objectStore;
30:
31: public void handleEvent(EventContext context) {
32: if (LOG_OBJECT_FAULT)
33: incrementAndLog();
34: ManagedObjectFaultingContext mfc = (ManagedObjectFaultingContext) context;
35: ObjectID oid = mfc.getId();
36: ManagedObject mo = objectStore.getObjectByID(oid);
37: objectManager
38: .addFaultedObject(oid, mo, mfc.isRemoveOnRelease());
39: }
40:
41: int count = 0;
42:
43: private synchronized void incrementAndLog() {
44: count++;
45: if (count % 100 == 0) {
46: logger.info("Fault count = " + count);
47: }
48: }
49:
50: public void initialize(ConfigurationContext context) {
51: super .initialize(context);
52: ServerConfigurationContext oscc = (ServerConfigurationContext) context;
53: objectManager = oscc.getObjectManager();
54: objectStore = oscc.getObjectStore();
55: }
56:
57: }
|