KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > handler > RequestLockUnLockHandler


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.handler;
5
6 import com.tc.async.api.AbstractEventHandler;
7 import com.tc.async.api.ConfigurationContext;
8 import com.tc.async.api.EventContext;
9 import com.tc.async.api.Sink;
10 import com.tc.async.impl.NullSink;
11 import com.tc.logging.TCLogger;
12 import com.tc.logging.TCLogging;
13 import com.tc.net.protocol.tcm.ChannelID;
14 import com.tc.object.lockmanager.api.LockID;
15 import com.tc.object.lockmanager.api.ThreadID;
16 import com.tc.object.msg.LockRequestMessage;
17 import com.tc.objectserver.core.api.ServerConfigurationContext;
18 import com.tc.objectserver.lockmanager.api.LockManager;
19
20 /**
21  * Makes the request for a lock on behalf of a client
22  *
23  * @author steve
24  */

25 public class RequestLockUnLockHandler extends AbstractEventHandler {
26   private static final TCLogger logger = TCLogging.getLogger(RequestLockUnLockHandler.class);
27   public static final Sink NULL_SINK = new NullSink();
28
29   private LockManager lockManager;
30   private Sink lockResponseSink;
31
32   public void handleEvent(EventContext context) {
33     LockRequestMessage lrm = (LockRequestMessage) context;
34
35     LockID lid = lrm.getLockID();
36     ChannelID cid = lrm.getChannelID();
37     ThreadID tid = lrm.getThreadID();
38     if (lrm.isObtainLockRequest()) {
39       lockManager.requestLock(lid, cid, tid, lrm.getLockLevel(), lockResponseSink);
40     } else if (lrm.isTryObtainLockRequest()) {
41       lockManager.tryRequestLock(lid, cid, tid, lrm.getLockLevel(), lockResponseSink);
42     } else if (lrm.isReleaseLockRequest()) {
43       if (lrm.isWaitRelease()) {
44         lockManager.wait(lid, cid, tid, lrm.getWaitInvocation(), lockResponseSink);
45       } else {
46         lockManager.unlock(lid, cid, tid);
47       }
48     } else if (lrm.isRecallCommitLockRequest()) {
49       lockManager.recallCommit(lid, cid, lrm.getLockContexts(), lrm.getWaitContexts(), lrm.getPendingLockContexts(),
50                                lockResponseSink);
51     } else if (lrm.isQueryLockRequest()) {
52       lockManager.queryLock(lid, cid, tid, lockResponseSink);
53     } else if (lrm.isInterruptWaitRequest()) {
54       lockManager.interrupt(lid, cid, tid);
55     } else {
56       logger.error("Unknown lock request message: " + lrm);
57     }
58   }
59
60   public void initialize(ConfigurationContext context) {
61     super.initialize(context);
62     ServerConfigurationContext oscc = (ServerConfigurationContext) context;
63     this.lockManager = oscc.getLockManager();
64     this.lockResponseSink = oscc.getStage(ServerConfigurationContext.RESPOND_TO_LOCK_REQUEST_STAGE).getSink();
65   }
66 }
Popular Tags