1 5 package com.tc.object.lockmanager.api; 6 7 import org.apache.commons.lang.builder.HashCodeBuilder; 8 9 import com.tc.io.TCByteBufferInputStream; 10 import com.tc.io.TCByteBufferOutput; 11 import com.tc.io.TCSerializable; 12 import com.tc.net.protocol.tcm.ChannelID; 13 import com.tc.util.Assert; 14 15 import java.io.IOException ; 16 17 22 public class LockContext implements TCSerializable { 23 24 private LockID lockID; 25 private int lockLevel; 26 private ChannelID channelID; 27 private ThreadID threadID; 28 private boolean noBlock; 29 private int hashCode; 30 31 public LockContext() { 32 return; 33 } 34 35 public LockContext(LockID lockID, ChannelID channelID, ThreadID threadID, int lockLevel, boolean noBlock) { 36 this.lockID = lockID; 37 this.channelID = channelID; 38 this.threadID = threadID; 39 Assert.assertFalse(LockLevel.isSynchronous(lockLevel)); 40 this.lockLevel = lockLevel; 41 this.noBlock = noBlock; 42 this.hashCode = new HashCodeBuilder(5503, 6737).append(lockID).append(channelID).append(threadID).append(lockLevel).append(noBlock) 43 .toHashCode(); 44 } 45 46 public LockContext(LockID lockID, ChannelID channelID, ThreadID threadID, int lockLevel) { 47 this(lockID, channelID, threadID, lockLevel, false); 48 } 49 50 public ChannelID getChannelID() { 51 return channelID; 52 } 53 54 public LockID getLockID() { 55 return lockID; 56 } 57 58 public int getLockLevel() { 59 return this.lockLevel; 60 } 61 62 public ThreadID getThreadID() { 63 return threadID; 64 } 65 66 public boolean noBlock() { 67 return noBlock; 68 } 69 70 public boolean equals(Object o) { 71 if (o == this) return true; 72 if (!(o instanceof LockContext)) return false; 73 LockContext cmp = (LockContext) o; 74 return lockID.equals(cmp.lockID) && threadID.equals(cmp.threadID) && lockLevel == cmp.lockLevel 75 && channelID.equals(cmp.channelID) && noBlock == cmp.noBlock; 76 } 77 78 public int hashCode() { 79 return hashCode; 80 } 81 82 public void serializeTo(TCByteBufferOutput output) { 83 output.writeString(lockID.asString()); 84 output.writeLong(channelID.toLong()); 85 output.writeLong(threadID.toLong()); 86 output.writeInt(lockLevel); 87 output.writeBoolean(noBlock); 88 } 89 90 public Object deserializeFrom(TCByteBufferInputStream input) throws IOException { 91 lockID = new LockID(input.readString()); 92 channelID = new ChannelID(input.readLong()); 93 threadID = new ThreadID(input.readLong()); 94 lockLevel = input.readInt(); 95 noBlock = input.readBoolean(); 96 return this; 97 } 98 99 } 100 | Popular Tags |