1 4 package com.tc.objectserver.lockmanager.impl; 5 6 import com.tc.async.api.Sink; 7 import com.tc.net.protocol.tcm.ChannelID; 8 import com.tc.object.lockmanager.api.LockID; 9 import com.tc.object.lockmanager.api.LockLevel; 10 import com.tc.object.lockmanager.api.ServerThreadID; 11 import com.tc.object.lockmanager.api.ThreadID; 12 13 public class Request { 14 private final ServerThreadContext threadContext; 15 private final Sink lockResponseSink; 16 private final ChannelID channelID; 17 private final ThreadID threadID; 18 private long timestamp; 19 private final int lockLevel; 20 private final int hashcode; 21 22 29 public Request(ServerThreadContext txn, int lockLevel, Sink lockResponseSink) { 30 this.timestamp = System.currentTimeMillis(); 31 ServerThreadID id = txn.getId(); 32 33 this.channelID = id.getChannelID(); 34 this.threadID = id.getClientThreadID(); 35 this.threadContext = txn; 36 this.lockResponseSink = lockResponseSink; 37 this.lockLevel = lockLevel; 38 this.hashcode = txn.hashCode(); 39 } 40 41 public ChannelID getRequesterID() { 42 return this.channelID; 43 } 44 45 public ThreadID getSourceID() { 46 return this.threadID; 47 } 48 49 public long getTimestamp() { 50 return timestamp; 51 } 52 53 public int getLockLevel() { 54 return lockLevel; 55 } 56 57 void execute(LockID id) { 58 lockResponseSink.add(Lock.createLockAwardResponseContext(id, threadContext.getId(), lockLevel)); 59 } 60 61 ServerThreadContext getThreadContext() { 62 return this.threadContext; 63 } 64 65 public int hashCode() { 66 return hashcode; 67 } 68 69 public boolean equals(Object o) { 70 if (this == o) return true; 71 if (o instanceof Request) { 72 Request other = (Request) o; 73 return (this.threadContext.equals(other.threadContext) && (this.lockLevel == other.lockLevel)); 74 } 75 return false; 76 } 77 78 Sink getLockResponseSink() { 79 return this.lockResponseSink; 80 } 81 82 public String toString() { 83 return "Request" + "@" + System.identityHashCode(this) + "[" + channelID + "," + threadID + ",level=" 84 + LockLevel.toString(lockLevel) + "]"; 85 } 86 87 } | Popular Tags |