01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.lockmanager.api;
05:
06: import org.apache.commons.lang.builder.HashCodeBuilder;
07:
08: public class LockRequest {
09: private LockID lockID;
10: private ThreadID threadID;
11: private int lockLevel;
12: private int hashCode;
13: private boolean initialized;
14:
15: public LockRequest(LockID lockID, ThreadID threadID, int lockLevel) {
16: initialize(lockID, threadID, lockLevel);
17: }
18:
19: public void initialize(LockID theLockID, ThreadID theThreadID,
20: int theLockLevel) {
21: if (initialized)
22: throw new AssertionError(
23: "Attempt to intialize more than once.");
24: this .lockID = theLockID;
25: this .threadID = theThreadID;
26: this .lockLevel = theLockLevel;
27: hashCode = new HashCodeBuilder(5503, 6737).append(theLockID)
28: .append(theThreadID).append(theLockLevel).toHashCode();
29: initialized = true;
30: }
31:
32: public LockID lockID() {
33: return lockID;
34: }
35:
36: public ThreadID threadID() {
37: return threadID;
38: }
39:
40: public int lockLevel() {
41: return lockLevel;
42: }
43:
44: public boolean equals(Object o) {
45: if (o == this )
46: return true;
47: if (!(o instanceof LockRequest))
48: return false;
49: LockRequest cmp = (LockRequest) o;
50: return lockID.equals(cmp.lockID)
51: && threadID.equals(cmp.threadID)
52: && lockLevel == cmp.lockLevel;
53: }
54:
55: public int hashCode() {
56: if (!initialized)
57: throw new AssertionError(
58: "Attempt to call hashCode() before initializing");
59: return hashCode;
60: }
61:
62: public String toString() {
63: return getClass().getName() + "[" + lockID + ", " + threadID
64: + ", lockLevel=" + lockLevel + "]";
65: }
66:
67: }
|