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.handler;
06:
07: import com.tc.async.api.AbstractEventHandler;
08: import com.tc.async.api.ConfigurationContext;
09: import com.tc.async.api.EventContext;
10: import com.tc.async.api.Sink;
11: import com.tc.async.impl.NullSink;
12: import com.tc.net.groups.ClientID;
13: import com.tc.object.lockmanager.api.LockID;
14: import com.tc.object.lockmanager.api.ThreadID;
15: import com.tc.object.msg.LockRequestMessage;
16: import com.tc.objectserver.core.api.ServerConfigurationContext;
17: import com.tc.objectserver.lockmanager.api.LockManager;
18:
19: /**
20: * Makes the request for a lock on behalf of a client
21: *
22: * @author steve
23: */
24: public class RequestLockUnLockHandler extends AbstractEventHandler {
25: public static final Sink NULL_SINK = new NullSink();
26:
27: private LockManager lockManager;
28: private Sink lockResponseSink;
29:
30: public void handleEvent(EventContext context) {
31: LockRequestMessage lrm = (LockRequestMessage) context;
32:
33: LockID lid = lrm.getLockID();
34: ClientID cid = lrm.getClientID();
35: ThreadID tid = lrm.getThreadID();
36: if (lrm.isObtainLockRequest()) {
37: lockManager.requestLock(lid, cid, tid, lrm.getLockLevel(),
38: lockResponseSink);
39: } else if (lrm.isTryObtainLockRequest()) {
40: lockManager.tryRequestLock(lid, cid, tid, lrm
41: .getLockLevel(), lrm.getWaitInvocation(),
42: lockResponseSink);
43: } else if (lrm.isReleaseLockRequest()) {
44: if (lrm.isWaitRelease()) {
45: lockManager.wait(lid, cid, tid,
46: lrm.getWaitInvocation(), lockResponseSink);
47: } else {
48: lockManager.unlock(lid, cid, tid);
49: }
50: } else if (lrm.isRecallCommitLockRequest()) {
51: lockManager.recallCommit(lid, cid, lrm.getLockContexts(),
52: lrm.getWaitContexts(),
53: lrm.getPendingLockContexts(), lrm
54: .getPendingTryLockContexts(),
55: lockResponseSink);
56: } else if (lrm.isQueryLockRequest()) {
57: lockManager.queryLock(lid, cid, tid, lockResponseSink);
58: } else if (lrm.isInterruptWaitRequest()) {
59: lockManager.interrupt(lid, cid, tid);
60: } else {
61: throw new AssertionError("Unknown lock request message: "
62: + lrm);
63: }
64: }
65:
66: public void initialize(ConfigurationContext context) {
67: super .initialize(context);
68: ServerConfigurationContext oscc = (ServerConfigurationContext) context;
69: this.lockManager = oscc.getLockManager();
70: this.lockResponseSink = oscc
71: .getStage(
72: ServerConfigurationContext.RESPOND_TO_LOCK_REQUEST_STAGE)
73: .getSink();
74: }
75: }
|