KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class LockRequest {
9   private LockID lockID;
10   private ThreadID threadID;
11   private int lockLevel;
12   private int hashCode;
13   private boolean noBlock;
14   private boolean initialized;
15   
16   public LockRequest(LockID lockID, ThreadID threadID, int lockLevel, boolean noBlock) {
17     initialize(lockID, threadID, lockLevel, noBlock);
18   }
19
20   public LockRequest(LockID lockID, ThreadID threadID, int lockLevel) {
21     initialize(lockID, threadID, lockLevel, false);
22   }
23
24   private void initialize(LockID theLockID, ThreadID theThreadID, int theLockLevel, boolean noBlock) {
25     if (initialized) throw new AssertionError JavaDoc("Attempt to intialize more than once.");
26     this.lockID = theLockID;
27     this.threadID = theThreadID;
28     this.lockLevel = theLockLevel;
29     this.noBlock = noBlock;
30     hashCode = new HashCodeBuilder(5503, 6737).append(theLockID).append(theThreadID).append(theLockLevel).append(noBlock).toHashCode();
31     initialized = true;
32   }
33
34   public LockID lockID() {
35     return lockID;
36   }
37
38   public ThreadID threadID() {
39     return threadID;
40   }
41
42   public int lockLevel() {
43     return lockLevel;
44   }
45   
46   public boolean noBlock() {
47     return this.noBlock;
48   }
49
50   public boolean equals(Object JavaDoc o) {
51     if (o == this) return true;
52     if (!(o instanceof LockRequest)) return false;
53     LockRequest cmp = (LockRequest) o;
54     return lockID.equals(cmp.lockID) && threadID.equals(cmp.threadID) && lockLevel == cmp.lockLevel && noBlock == cmp.noBlock;
55   }
56
57   public int hashCode() {
58     if (!initialized) throw new AssertionError JavaDoc("Attempt to call hashCode() before initializing");
59     return hashCode;
60   }
61
62   public String JavaDoc toString() {
63     return getClass().getName() + "[" + lockID + ", " + threadID + ", lockLevel=" + lockLevel + "]";
64   }
65
66 }
67
Popular Tags