KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > tx > ServerTransactionID


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.object.tx;
5
6 import java.io.Serializable JavaDoc;
7
8 import com.tc.net.protocol.tcm.ChannelID;
9 import com.tc.object.tx.TransactionID;
10
11 /**
12  * A class that represents a particular client transaction from the server's perspective (ie. the combination of
13  * ChannelID and a client TransactionID)
14  */

15 public class ServerTransactionID implements Serializable JavaDoc {
16   public static final ServerTransactionID NULL_ID = new ServerTransactionID(ChannelID.NULL_ID, TransactionID.NULL_ID);
17
18   private final TransactionID txnID;
19   private final ChannelID channelID;
20   private final int hashCode;
21
22   public ServerTransactionID(ChannelID channelID, TransactionID txnID) {
23     this.channelID = channelID;
24     this.txnID = txnID;
25
26     int hash = 29;
27     hash = (37 * hash) + channelID.hashCode();
28     hash = (37 * hash) + txnID.hashCode();
29     this.hashCode = hash;
30   }
31
32   public ChannelID getChannelID() {
33     return channelID;
34   }
35
36   public TransactionID getClientTransactionID() {
37     return txnID;
38   }
39   
40   public boolean isNull() {
41     return channelID.isNull() && txnID.isNull();
42   }
43
44   public String JavaDoc toString() {
45     return new StringBuffer JavaDoc().append("ServerTransactionID{").append(channelID).append(',').append(txnID).append('}')
46         .toString();
47   }
48
49   public int hashCode() {
50     return this.hashCode;
51   }
52
53   public boolean equals(Object JavaDoc obj) {
54     if (obj instanceof ServerTransactionID) {
55       ServerTransactionID other = (ServerTransactionID) obj;
56       return this.channelID.equals(other.channelID) && this.txnID.equals(other.txnID);
57     }
58     return false;
59   }
60 }
61
Popular Tags