1 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 ("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 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 ("Attempt to call hashCode() before initializing"); 59 return hashCode; 60 } 61 62 public String toString() { 63 return getClass().getName() + "[" + lockID + ", " + threadID + ", lockLevel=" + lockLevel + "]"; 64 } 65 66 } 67 | Popular Tags |