001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.objectserver.handler;
006:
007: import com.tc.async.api.AbstractEventHandler;
008: import com.tc.async.api.ConfigurationContext;
009: import com.tc.async.api.EventContext;
010: import com.tc.logging.TCLogger;
011: import com.tc.net.groups.NodeID;
012: import com.tc.net.protocol.tcm.MessageChannel;
013: import com.tc.net.protocol.tcm.TCMessageType;
014: import com.tc.object.msg.LockResponseMessage;
015: import com.tc.object.net.DSOChannelManager;
016: import com.tc.object.net.NoSuchChannelException;
017: import com.tc.objectserver.context.LockResponseContext;
018: import com.tc.objectserver.core.api.ServerConfigurationContext;
019:
020: /**
021: * @author steve
022: */
023: public class RespondToRequestLockHandler extends AbstractEventHandler {
024: private DSOChannelManager channelManager;
025: private TCLogger logger;
026:
027: public void handleEvent(EventContext context) {
028: LockResponseContext lrc = (LockResponseContext) context;
029:
030: NodeID cid = lrc.getNodeID();
031: try {
032: MessageChannel channel = channelManager
033: .getActiveChannel(cid);
034:
035: LockResponseMessage responseMessage = null;
036:
037: if (lrc.isLockAward()) {
038: responseMessage = (LockResponseMessage) channel
039: .createMessage(TCMessageType.LOCK_RESPONSE_MESSAGE);
040: responseMessage.initializeLockAward(lrc.getLockID(),
041: lrc.getThreadID(), lrc.getLockLevel());
042: } else if (lrc.isLockNotAwarded()) {
043: responseMessage = (LockResponseMessage) channel
044: .createMessage(TCMessageType.LOCK_RESPONSE_MESSAGE);
045: responseMessage.initializeLockNotAwarded(lrc
046: .getLockID(), lrc.getThreadID(), lrc
047: .getLockLevel());
048: } else if (lrc.isLockRecall()) {
049: responseMessage = (LockResponseMessage) channel
050: .createMessage(TCMessageType.LOCK_RECALL_MESSAGE);
051: responseMessage.initializeLockRecall(lrc.getLockID(),
052: lrc.getThreadID(), lrc.getLockLevel());
053: } else if (lrc.isLockWaitTimeout()) {
054: responseMessage = (LockResponseMessage) channel
055: .createMessage(TCMessageType.LOCK_RESPONSE_MESSAGE);
056: responseMessage.initializeLockWaitTimeout(lrc
057: .getLockID(), lrc.getThreadID(), lrc
058: .getLockLevel());
059: } else if (lrc.isLockInfo()) {
060: responseMessage = (LockResponseMessage) channel
061: .createMessage(TCMessageType.LOCK_QUERY_RESPONSE_MESSAGE);
062: responseMessage.initializeLockInfo(lrc.getLockID(), lrc
063: .getThreadID(), lrc.getLockLevel(), lrc
064: .getGlobalLockInfo());
065: } else if (lrc.isLockStatEnabled()) {
066: responseMessage = (LockResponseMessage) channel
067: .createMessage(TCMessageType.LOCK_STAT_MESSAGE);
068: responseMessage.initializeLockStatEnable(lrc
069: .getLockID(), lrc.getThreadID(), lrc
070: .getLockLevel(), lrc.getStackTraceDepth(), lrc
071: .getStatCollectFrequency());
072: } else if (lrc.isLockStatDisabled()) {
073: responseMessage = (LockResponseMessage) channel
074: .createMessage(TCMessageType.LOCK_STAT_MESSAGE);
075: responseMessage.initializeLockStatDisable(lrc
076: .getLockID(), lrc.getThreadID(), lrc
077: .getLockLevel());
078: } else {
079: throw new AssertionError(
080: "Unknown lock response context : " + lrc);
081: }
082:
083: responseMessage.send();
084:
085: } catch (NoSuchChannelException e) {
086: logger.info("Failed to send lock response message:"
087: + lrc.getLockID().asString() + " to:" + cid
088: + " because the session is dead.");
089: return;
090: }
091: }
092:
093: public void initialize(ConfigurationContext context) {
094: super .initialize(context);
095: ServerConfigurationContext oscc = (ServerConfigurationContext) context;
096: this.channelManager = oscc.getChannelManager();
097: this.logger = oscc.getLogger(this.getClass());
098: }
099:
100: }
|