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.object.handler;
05:
06: import com.tc.async.api.AbstractEventHandler;
07: import com.tc.async.api.ConfigurationContext;
08: import com.tc.async.api.EventContext;
09: 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
22: .getLogger(LockResponseHandler.class);
23: private ClientLockManager lockManager;
24: private final SessionManager sessionManager;
25:
26: public LockResponseHandler(SessionManager sessionManager) {
27: this .sessionManager = sessionManager;
28: }
29:
30: public void handleEvent(EventContext context) {
31: final LockResponseMessage msg = (LockResponseMessage) context;
32: final SessionID sessionID = msg.getLocalSessionID();
33: if (!sessionManager.isCurrentSession(sessionID)) {
34: logger.warn("Ignoring " + msg + " from a previous session:"
35: + sessionID + ", " + sessionManager);
36: return;
37: }
38: if (msg.isLockAward()) {
39: lockManager
40: .awardLock(msg.getLocalSessionID(),
41: msg.getLockID(), msg.getThreadID(), msg
42: .getLockLevel());
43: } else if (msg.isLockRecall()) {
44: lockManager.recall(msg.getLockID(), msg.getThreadID(), msg
45: .getLockLevel());
46: } else if (msg.isLockWaitTimeout()) {
47: lockManager
48: .waitTimedOut(msg.getLockID(), msg.getThreadID());
49: } else if (msg.isLockNotAwarded()) {
50: lockManager
51: .cannotAwardLock(msg.getLocalSessionID(), msg
52: .getLockID(), msg.getThreadID(), msg
53: .getLockLevel());
54: } else if (msg.isLockInfo()) {
55: lockManager.queryLockCommit(msg.getThreadID(), msg
56: .getGlobalLockInfo());
57: } else if (msg.isLockStatEnabled()) {
58: lockManager.enableStat(msg.getLockID(), msg
59: .getStackTraceDepth(), msg
60: .getStatCollectFrequency());
61: } else if (msg.isLockStatDisabled()) {
62: lockManager.disableStat(msg.getLockID());
63: } else {
64: logger.error("Unknown lock response message: " + msg);
65: }
66: }
67:
68: public void initialize(ConfigurationContext context) {
69: super .initialize(context);
70: ClientConfigurationContext ccc = (ClientConfigurationContext) context;
71: this.lockManager = ccc.getLockManager();
72: }
73:
74: }
|