1 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.exception.ImplementMe; 10 import com.tc.logging.TCLogger; 11 import com.tc.net.protocol.tcm.ChannelID; 12 import com.tc.net.protocol.tcm.MessageChannel; 13 import com.tc.net.protocol.tcm.TCMessageType; 14 import com.tc.object.msg.LockResponseMessage; 15 import com.tc.object.net.DSOChannelManager; 16 import com.tc.object.net.NoSuchChannelException; 17 import com.tc.objectserver.context.LockResponseContext; 18 import com.tc.objectserver.core.api.ServerConfigurationContext; 19 20 23 public class RespondToRequestLockHandler extends AbstractEventHandler { 24 private DSOChannelManager channelManager; 25 private TCLogger logger; 26 27 public void handleEvent(EventContext context) { 28 LockResponseContext lrc = (LockResponseContext) context; 29 30 ChannelID cid = lrc.getChannelID(); 31 try { 32 MessageChannel channel = channelManager.getActiveChannel(cid); 33 34 LockResponseMessage responseMessage = null; 35 36 if (lrc.isLockAward()) { 37 responseMessage = (LockResponseMessage) channel.createMessage(TCMessageType.LOCK_RESPONSE_MESSAGE); 38 responseMessage.initializeLockAward(lrc.getLockID(), lrc.getThreadID(), lrc.getLockLevel()); 39 } else if (lrc.isLockNotAwarded()) { 40 responseMessage = (LockResponseMessage) channel.createMessage(TCMessageType.LOCK_RESPONSE_MESSAGE); 41 responseMessage.initializeLockNotAwarded(lrc.getLockID(), lrc.getThreadID(), lrc.getLockLevel()); 42 } else if (lrc.isLockRecall()) { 43 responseMessage = (LockResponseMessage) channel.createMessage(TCMessageType.LOCK_RECALL_MESSAGE); 44 responseMessage.initializeLockRecall(lrc.getLockID(), lrc.getThreadID(), lrc.getLockLevel()); 45 } else if (lrc.isLockWaitTimeout()) { 46 responseMessage = (LockResponseMessage) channel.createMessage(TCMessageType.LOCK_RESPONSE_MESSAGE); 47 responseMessage.initializeLockWaitTimeout(lrc.getLockID(), lrc.getThreadID(), lrc.getLockLevel()); 48 } else if (lrc.isLockInfo()) { 49 responseMessage = (LockResponseMessage) channel.createMessage(TCMessageType.LOCK_QUERY_RESPONSE_MESSAGE); 50 responseMessage.initializeLockInfo(lrc.getLockID(), lrc.getThreadID(), lrc.getLockLevel(), lrc.getGlobalLockInfo()); 51 } else { 52 throw new ImplementMe(); 54 } 55 56 responseMessage.send(); 57 58 } catch (NoSuchChannelException e) { 59 logger.info("Failed to send lock response message:" + lrc.getLockID().asString() + " to:" + cid 60 + " because the session is dead."); 61 return; 62 } 63 } 64 65 public void initialize(ConfigurationContext context) { 66 super.initialize(context); 67 ServerConfigurationContext oscc = (ServerConfigurationContext) context; 68 this.channelManager = oscc.getChannelManager(); 69 this.logger = oscc.getLogger(this.getClass()); 70 } 71 72 } | Popular Tags |