01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.l2.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.async.api.Sink;
11: import com.tc.l2.msg.GCResultMessage;
12: import com.tc.l2.objectserver.ReplicatedObjectManager;
13: import com.tc.logging.TCLogger;
14: import com.tc.logging.TCLogging;
15: import com.tc.objectserver.core.api.ServerConfigurationContext;
16: import com.tc.objectserver.tx.ServerTransactionManager;
17: import com.tc.objectserver.tx.TxnsInSystemCompletionLister;
18:
19: public class GCResultHandler extends AbstractEventHandler {
20:
21: private static final TCLogger logger = TCLogging
22: .getLogger(GCResultHandler.class);
23:
24: private ReplicatedObjectManager rObjectManager;
25: private ServerTransactionManager transactionManager;
26: private Sink gcResultSink;
27:
28: public void handleEvent(EventContext context) {
29: if (context instanceof GCResultMessage) {
30: GCResultMessage msg = (GCResultMessage) context;
31: logger
32: .info("Scheduling to process GC results when all current transactions are completed : "
33: + msg);
34: transactionManager
35: .callBackOnTxnsInSystemCompletion(new GCResultCallback(
36: msg, gcResultSink));
37: } else {
38: GCResultCallback callback = (GCResultCallback) context;
39: rObjectManager.handleGCResult(callback.getGCResult());
40: }
41: }
42:
43: public void initialize(ConfigurationContext context) {
44: super .initialize(context);
45: ServerConfigurationContext oscc = (ServerConfigurationContext) context;
46: this .transactionManager = oscc.getTransactionManager();
47: this .rObjectManager = oscc.getL2Coordinator()
48: .getReplicatedObjectManager();
49: this .gcResultSink = oscc.getStage(
50: ServerConfigurationContext.GC_RESULT_PROCESSING_STAGE)
51: .getSink();
52: }
53:
54: private static final class GCResultCallback implements
55: TxnsInSystemCompletionLister, EventContext {
56:
57: private final Sink sink;
58: private final GCResultMessage msg;
59:
60: public GCResultCallback(GCResultMessage msg, Sink sink) {
61: this .msg = msg;
62: this .sink = sink;
63: }
64:
65: public GCResultMessage getGCResult() {
66: return msg;
67: }
68:
69: public void onCompletion() {
70: sink.add(this);
71: }
72: }
73: }
|