KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > lockmanager > api > Notify


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.lockmanager.api;
5
6 import org.apache.commons.lang.builder.HashCodeBuilder;
7
8 import com.tc.io.TCByteBufferInputStream;
9 import com.tc.io.TCByteBufferOutput;
10 import com.tc.io.TCSerializable;
11
12 import java.io.IOException JavaDoc;
13
14 public class Notify implements TCSerializable {
15
16   public static final Notify NULL = new Notify(true);
17
18   private LockID lockID;
19   private ThreadID threadID;
20   private boolean all;
21   private boolean initialized;
22   private int hashCode;
23   private final boolean isNull;
24
25   public Notify(LockID lockID, ThreadID threadID, boolean all) {
26     isNull = false;
27     initialize(lockID, threadID, all);
28   }
29
30   public Notify() {
31     isNull = false;
32   }
33
34   private Notify(boolean isNull) {
35     this.isNull = isNull;
36   }
37
38   public boolean isNull() {
39     return this.isNull;
40   }
41
42   private void initialize(LockID l, ThreadID id, boolean isAll) {
43     if (initialized) throw new AssertionError JavaDoc("Attempt to initialize twice");
44     this.lockID = l;
45     this.threadID = id;
46     this.all = isAll;
47     hashCode = new HashCodeBuilder(5503, 6737).append(lockID).append(threadID).append(isAll).toHashCode();
48     initialized = true;
49   }
50
51   public void serializeTo(TCByteBufferOutput out) {
52     if (!initialized) throw new AssertionError JavaDoc("Attempt to serialize an uninitialized Notify.");
53     out.writeString(this.lockID.asString());
54     out.writeLong(this.threadID.toLong());
55     out.writeBoolean(this.all);
56   }
57
58   public Object JavaDoc deserializeFrom(TCByteBufferInputStream in) throws IOException JavaDoc {
59     initialize(new LockID(in.readString()), new ThreadID(in.readLong()), in.readBoolean());
60     return this;
61   }
62
63   public int hashCode() {
64     if (!initialized) throw new AssertionError JavaDoc("Called hashCode before initializing.");
65     return hashCode;
66   }
67
68   public boolean equals(Object JavaDoc o) {
69     if (!(o instanceof Notify)) return false;
70     Notify cmp = (Notify) o;
71     return this.lockID.equals(cmp.lockID) && this.threadID.equals(cmp.threadID) && this.all == cmp.all;
72   }
73
74   public String JavaDoc toString() {
75     return getClass().getName() + "[" + lockID + ", " + threadID + ", " + "all: " + all + "]";
76   }
77
78   public ThreadID getThreadID() {
79     return this.threadID;
80   }
81
82   public LockID getLockID() {
83     return this.lockID;
84   }
85
86   public boolean getIsAll() {
87     return this.all;
88   }
89 }
90
Popular Tags