KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > lockmanager > impl > LockWaitContextImpl


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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