KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > tx > CommitTransactionMessageRecycler


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.objectserver.tx;
5
6 import com.tc.net.protocol.tcm.ChannelID;
7 import com.tc.object.msg.DSOMessageBase;
8 import com.tc.object.msg.MessageRecyclerImpl;
9 import com.tc.object.tx.ServerTransactionID;
10
11 import java.util.Collection JavaDoc;
12 import java.util.HashSet JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.Set JavaDoc;
15
16 public class CommitTransactionMessageRecycler extends MessageRecyclerImpl implements ServerTransactionListener {
17
18   private final Set JavaDoc resentTransactionIDs = new HashSet JavaDoc();
19
20   public CommitTransactionMessageRecycler(ServerTransactionManager transactionManager) {
21     super();
22     transactionManager.addTransactionListener(this);
23   }
24
25   public synchronized void addMessage(DSOMessageBase message, Set JavaDoc keys) {
26     if (resentTransactionIDs.size() > 0) {
27       if (resentTransactionIDs.removeAll(keys)) {
28         // Dont manage this Message
29
if (false) System.err.println("MessageRecycler :: ignoring resent message : resentTxIDs.size() = "
30                                       + resentTransactionIDs.size());
31         return;
32       }
33     }
34     super.addMessage(message, keys);
35   }
36
37   public void transactionCompleted(ServerTransactionID stxID) {
38     recycle(stxID);
39   }
40
41   public void addResentServerTransactionIDs(Collection JavaDoc stxIDs) {
42     resentTransactionIDs.addAll(stxIDs);
43   }
44
45   public void clearAllTransactionsFor(ChannelID client) {
46     for (Iterator JavaDoc iter = resentTransactionIDs.iterator(); iter.hasNext();) {
47       ServerTransactionID stxID = (ServerTransactionID) iter.next();
48       if (stxID.getChannelID().equals(client)) {
49         iter.remove();
50       }
51     }
52   }
53
54   public void transactionApplied(ServerTransactionID stxID) {
55     return;
56   }
57
58   public void incomingTransactions(ChannelID cid, Set JavaDoc serverTxnIDs) {
59     return;
60   }
61
62 }
63
Popular Tags