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.objectserver.tx;
06:
07: import com.tc.async.api.Sink;
08: import com.tc.async.api.StageManager;
09: import com.tc.objectserver.context.ApplyCompleteEventContext;
10: import com.tc.objectserver.context.ApplyTransactionContext;
11: import com.tc.objectserver.context.CommitTransactionContext;
12: import com.tc.objectserver.context.LookupEventContext;
13: import com.tc.objectserver.context.RecallObjectsContext;
14: import com.tc.objectserver.core.api.ServerConfigurationContext;
15:
16: import java.util.Collections;
17:
18: public class TransactionalStagesCoordinatorImpl implements
19: TransactionalStageCoordinator {
20:
21: private Sink lookupSink;
22: private Sink applySink;
23: private Sink commitSink;
24: private Sink applyCompleteSink;
25: private Sink recallSink;
26:
27: private final StageManager stageManager;
28:
29: public TransactionalStagesCoordinatorImpl(StageManager stageManager) {
30: this .stageManager = stageManager;
31: }
32:
33: public void lookUpSinks() {
34: this .lookupSink = stageManager.getStage(
35: ServerConfigurationContext.TRANSACTION_LOOKUP_STAGE)
36: .getSink();
37: this .recallSink = stageManager.getStage(
38: ServerConfigurationContext.RECALL_OBJECTS_STAGE)
39: .getSink();
40: this .applySink = stageManager.getStage(
41: ServerConfigurationContext.APPLY_CHANGES_STAGE)
42: .getSink();
43: this .applyCompleteSink = stageManager.getStage(
44: ServerConfigurationContext.APPLY_COMPLETE_STAGE)
45: .getSink();
46: this .commitSink = stageManager.getStage(
47: ServerConfigurationContext.COMMIT_CHANGES_STAGE)
48: .getSink();
49: }
50:
51: public void addToApplyStage(ApplyTransactionContext context) {
52: applySink.add(context);
53: }
54:
55: public void initiateLookup() {
56: lookupSink.addLossy(new LookupEventContext());
57: }
58:
59: public void initiateApplyComplete() {
60: applyCompleteSink.addLossy(new ApplyCompleteEventContext());
61: }
62:
63: public void initiateCommit() {
64: commitSink.addLossy(new CommitTransactionContext());
65: }
66:
67: public void initiateRecallAll() {
68: recallSink.add(new RecallObjectsContext(Collections.EMPTY_LIST,
69: true));
70: }
71:
72: }
|