KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > handler > LockResponseHandler


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.object.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.logging.TCLogger;
10 import com.tc.logging.TCLogging;
11 import com.tc.object.ClientConfigurationContext;
12 import com.tc.object.lockmanager.api.ClientLockManager;
13 import com.tc.object.msg.LockResponseMessage;
14 import com.tc.object.session.SessionID;
15 import com.tc.object.session.SessionManager;
16
17 /**
18  * @author steve
19  */

20 public class LockResponseHandler extends AbstractEventHandler {
21   private static final TCLogger logger = TCLogging.getLogger(LockResponseHandler.class);
22   private ClientLockManager lockManager;
23   private final SessionManager sessionManager;
24
25   public LockResponseHandler(SessionManager sessionManager) {
26     this.sessionManager = sessionManager;
27   }
28
29   public void handleEvent(EventContext context) {
30     final LockResponseMessage msg = (LockResponseMessage) context;
31     final SessionID sessionID = msg.getLocalSessionID();
32     if(!sessionManager.isCurrentSession(sessionID)) {
33       logger.warn("Ignoring " + msg + " from a previous session:" + sessionID + ", " + sessionManager);
34       return;
35     }
36     if (msg.isLockAward()) {
37       lockManager.awardLock(msg.getLocalSessionID(), msg.getLockID(), msg.getThreadID(), msg.getLockLevel());
38     } else if (msg.isLockRecall()) {
39       lockManager.recall(msg.getLockID(), msg.getThreadID(), msg.getLockLevel());
40     } else if (msg.isLockWaitTimeout()) {
41       lockManager.waitTimedOut(msg.getLockID(), msg.getThreadID());
42     } else if (msg.isLockNotAwarded()) {
43       lockManager.cannotAwardLock(msg.getLocalSessionID(), msg.getLockID(), msg.getThreadID(), msg.getLockLevel());
44     } else if (msg.isLockInfo()) {
45       lockManager.queryLockCommit(msg.getThreadID(), msg.getGlobalLockInfo());
46     } else {
47       logger.error("Unknown lock response message: " + msg);
48     }
49   }
50
51   public void initialize(ConfigurationContext context) {
52     super.initialize(context);
53     ClientConfigurationContext ccc = (ClientConfigurationContext) context;
54     this.lockManager = ccc.getLockManager();
55   }
56
57 }
Popular Tags