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.objectserver.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.net.protocol.tcm.MessageChannel;
11: import com.tc.net.protocol.tcm.TCMessageType;
12: import com.tc.object.ObjectID;
13: import com.tc.object.msg.RequestRootMessage;
14: import com.tc.object.msg.RequestRootResponseMessage;
15: import com.tc.object.net.DSOChannelManager;
16: import com.tc.object.net.NoSuchChannelException;
17: import com.tc.objectserver.api.ObjectManager;
18: import com.tc.objectserver.core.api.ServerConfigurationContext;
19:
20: /**
21: * @author steve
22: */
23: public class RequestRootHandler extends AbstractEventHandler {
24: private ObjectManager objectManager;
25: private DSOChannelManager channelManager;
26: private TCLogger logger;
27:
28: public void handleEvent(EventContext context) {
29: RequestRootMessage rrm = (RequestRootMessage) context;
30: ObjectID rootID = objectManager.lookupRootID(rrm.getRootName());
31: try {
32: MessageChannel channel = channelManager
33: .getActiveChannel(rrm.getClientID());
34:
35: RequestRootResponseMessage rrrm = (RequestRootResponseMessage) channel
36: .createMessage(TCMessageType.REQUEST_ROOT_RESPONSE_MESSAGE);
37: rrrm.initialize(rrm.getRootName(), rootID);
38: rrrm.send();
39: } catch (NoSuchChannelException e) {
40: logger
41: .info("Failed to send root request response because channel:"
42: + rrm.getClientID() + " is disconnected.");
43: return;
44: }
45: }
46:
47: public void initialize(ConfigurationContext context) {
48: super .initialize(context);
49: ServerConfigurationContext oscc = (ServerConfigurationContext) context;
50:
51: objectManager = oscc.getObjectManager();
52: this.channelManager = oscc.getChannelManager();
53: this.logger = oscc.getLogger(this.getClass());
54: }
55: }
|