01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.objectserver.lockmanager.impl;
06:
07: import com.tc.async.api.Sink;
08: import com.tc.net.groups.NodeID;
09: import com.tc.object.lockmanager.api.LockID;
10: import com.tc.object.lockmanager.api.LockLevel;
11: import com.tc.object.lockmanager.api.ServerThreadID;
12: import com.tc.object.lockmanager.api.ThreadID;
13:
14: public class Request {
15: private final ServerThreadContext threadContext;
16: private final Sink lockResponseSink;
17: private final NodeID nodeID;
18: private final ThreadID threadID;
19: private long timestamp;
20: private final int lockLevel;
21: private final int hashcode;
22:
23: /**
24: * Create a new lock response
25: *
26: * @param threadContext the open transaction associated with this request
27: * @param lockLevel the lock level that will be in lock response message to the client
28: * @param lockResponseSink the sink that accepts the lock response events
29: */
30: public Request(ServerThreadContext txn, int lockLevel,
31: Sink lockResponseSink) {
32: this .timestamp = System.currentTimeMillis();
33: ServerThreadID id = txn.getId();
34:
35: this .nodeID = id.getNodeID();
36: this .threadID = id.getClientThreadID();
37: this .threadContext = txn;
38: this .lockResponseSink = lockResponseSink;
39: this .lockLevel = lockLevel;
40: this .hashcode = txn.hashCode();
41: }
42:
43: public NodeID getRequesterID() {
44: return this .nodeID;
45: }
46:
47: public ThreadID getSourceID() {
48: return this .threadID;
49: }
50:
51: public long getTimestamp() {
52: return timestamp;
53: }
54:
55: public int getLockLevel() {
56: return lockLevel;
57: }
58:
59: void execute(LockID id) {
60: lockResponseSink.add(Lock.createLockAwardResponseContext(id,
61: threadContext.getId(), lockLevel));
62: }
63:
64: ServerThreadContext getThreadContext() {
65: return this .threadContext;
66: }
67:
68: public int hashCode() {
69: return hashcode;
70: }
71:
72: public boolean equals(Object o) {
73: if (this == o)
74: return true;
75: if (o instanceof Request) {
76: Request other = (Request) o;
77: return (this .threadContext.equals(other.threadContext) && (this .lockLevel == other.lockLevel));
78: }
79: return false;
80: }
81:
82: Sink getLockResponseSink() {
83: return this .lockResponseSink;
84: }
85:
86: public String toString() {
87: return "Request" + "@" + System.identityHashCode(this ) + "["
88: + nodeID + "," + threadID + ",level="
89: + LockLevel.toString(lockLevel) + "]";
90: }
91:
92: }
|