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.objectserver.lockmanager.impl;
05:
06: import com.tc.async.api.Sink;
07: import com.tc.net.groups.NodeID;
08: import com.tc.object.lockmanager.api.ServerThreadID;
09: import com.tc.object.lockmanager.api.ThreadID;
10: import com.tc.object.tx.WaitInvocation;
11: import com.tc.objectserver.lockmanager.api.LockWaitContext;
12: import com.tc.util.Assert;
13:
14: public class LockWaitContextImpl implements LockWaitContext {
15: private final ServerThreadContext threadContext;
16: private final NodeID nodeID;
17: private final ThreadID threadID;
18: private final Sink lockResponseSink;
19: private final WaitInvocation call;
20: private final Lock lock;
21: private long timestamp;
22: private final int lockLevel;
23:
24: public LockWaitContextImpl(ServerThreadContext threadContext,
25: Lock lock, WaitInvocation call, int lockLevel,
26: Sink lockResponseSink) {
27: this .lockLevel = lockLevel;
28: Assert.assertNoNullElements(new Object[] { threadContext, lock,
29: call, lockResponseSink });
30: this .timestamp = System.currentTimeMillis();
31: ServerThreadID id = threadContext.getId();
32: this .threadContext = threadContext;
33: this .nodeID = id.getNodeID();
34: this .threadID = id.getClientThreadID();
35: this .lockResponseSink = lockResponseSink;
36: this .call = call;
37: this .lock = lock;
38: }
39:
40: public int hashCode() {
41: return this .threadContext.hashCode();
42: }
43:
44: public boolean equals(Object obj) {
45: if (obj instanceof LockWaitContextImpl) {
46: LockWaitContextImpl other = (LockWaitContextImpl) obj;
47: return this .threadContext.equals(other.threadContext);
48: }
49: return false;
50: }
51:
52: public String toString() {
53: return "LockWaitContex@" + System.identityHashCode(this ) + "["
54: + nodeID + "," + threadID + "," + call + ","
55: + lock.getLockID() + "]";
56: }
57:
58: public NodeID getNodeID() {
59: return nodeID;
60: }
61:
62: public ThreadID getThreadID() {
63: return threadID;
64: }
65:
66: public ServerThreadContext getThreadContext() {
67: return threadContext;
68: }
69:
70: public WaitInvocation getWaitInvocation() {
71: return this .call;
72: }
73:
74: public long getTimestamp() {
75: return timestamp;
76: }
77:
78: public int lockLevel() {
79: return lockLevel;
80: }
81:
82: Lock getLock() {
83: return lock;
84: }
85:
86: public Sink getLockResponseSink() {
87: return lockResponseSink;
88: }
89:
90: public void waitTimeout() {
91: this.lock.waitTimeout(this);
92: }
93:
94: }
|