1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.transaction; |
8 |
| |
9 |
| |
10 |
| import org.jgroups.Address; |
11 |
| |
12 |
| import java.io.Externalizable; |
13 |
| import java.io.IOException; |
14 |
| import java.io.ObjectInput; |
15 |
| import java.io.ObjectOutput; |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| public class GlobalTransaction implements Externalizable |
28 |
| { |
29 |
| |
30 |
| private static final long serialVersionUID = 8011434781266976149L; |
31 |
| |
32 |
| private static long sid = 0; |
33 |
| |
34 |
| private Address addr = null; |
35 |
| private long id = -1; |
36 |
| private transient boolean remote = false; |
37 |
| |
38 |
| |
39 |
| private transient int hash_code = -1; |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
1474
| public GlobalTransaction()
|
45 |
| { |
46 |
| } |
47 |
| |
48 |
1121243
| private GlobalTransaction(Address addr)
|
49 |
| { |
50 |
1121243
| this.addr = addr;
|
51 |
1121243
| id = newId();
|
52 |
| } |
53 |
| |
54 |
1121243
| private static synchronized long newId()
|
55 |
| { |
56 |
1121243
| return ++sid;
|
57 |
| } |
58 |
| |
59 |
1121243
| public static GlobalTransaction create(Address addr)
|
60 |
| { |
61 |
1121243
| return new GlobalTransaction(addr);
|
62 |
| } |
63 |
| |
64 |
4491
| public Object getAddress()
|
65 |
| { |
66 |
4491
| return addr;
|
67 |
| } |
68 |
| |
69 |
1469
| public void setAddress(Address address)
|
70 |
| { |
71 |
1469
| addr = address;
|
72 |
| } |
73 |
| |
74 |
1444
| public long getId()
|
75 |
| { |
76 |
1444
| return id;
|
77 |
| } |
78 |
| |
79 |
12094771
| public int hashCode()
|
80 |
| { |
81 |
12094254
| if (hash_code == -1)
|
82 |
| { |
83 |
1122699
| hash_code = (addr != null ? addr.hashCode() : 0) + (int) id;
|
84 |
| } |
85 |
12094788
| return hash_code;
|
86 |
| } |
87 |
| |
88 |
13113017
| public boolean equals(Object other)
|
89 |
| { |
90 |
13112958
| if (this == other)
|
91 |
12777724
| return true;
|
92 |
335293
| if (!(other instanceof GlobalTransaction))
|
93 |
734
| return false;
|
94 |
| |
95 |
334559
| GlobalTransaction otherGtx = (GlobalTransaction) other;
|
96 |
334559
| boolean aeq = (addr == null) ? (otherGtx.addr == null) : addr.equals(otherGtx.addr);
|
97 |
334559
| return aeq && (id == otherGtx.id);
|
98 |
| } |
99 |
| |
100 |
1018
| public String toString()
|
101 |
| { |
102 |
1018
| StringBuffer sb = new StringBuffer();
|
103 |
1018
| sb.append("GlobalTransaction:<").append(addr).append(">:").append(id);
|
104 |
1018
| return sb.toString();
|
105 |
| } |
106 |
| |
107 |
2
| public void writeExternal(ObjectOutput out) throws IOException
|
108 |
| { |
109 |
2
| out.writeObject(addr);
|
110 |
2
| out.writeLong(id);
|
111 |
| |
112 |
| } |
113 |
| |
114 |
2
| public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
|
115 |
| { |
116 |
2
| addr = (Address) in.readObject();
|
117 |
2
| id = in.readLong();
|
118 |
2
| hash_code = -1;
|
119 |
| } |
120 |
| |
121 |
| |
122 |
| |
123 |
| |
124 |
1249403
| public boolean isRemote()
|
125 |
| { |
126 |
1249403
| return remote;
|
127 |
| } |
128 |
| |
129 |
| |
130 |
| |
131 |
| |
132 |
1473
| public void setRemote(boolean remote)
|
133 |
| { |
134 |
1473
| this.remote = remote;
|
135 |
| } |
136 |
| |
137 |
| |
138 |
1457
| public void setId(long id)
|
139 |
| { |
140 |
1457
| this.id = id;
|
141 |
| } |
142 |
| } |