KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > handler > RequestRootHandler


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.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.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.getActiveChannel(rrm.getChannelID());
33
34       RequestRootResponseMessage rrrm = (RequestRootResponseMessage) channel
35           .createMessage(TCMessageType.REQUEST_ROOT_RESPONSE_MESSAGE);
36       rrrm.initialize(rrm.getRootName(), rootID);
37       rrrm.send();
38     } catch (NoSuchChannelException e) {
39       logger.info("Failed to send root request response because channel:" + rrm.getChannelID() + " is disconnected.");
40       return;
41     }
42   }
43
44   public void initialize(ConfigurationContext context) {
45     super.initialize(context);
46     ServerConfigurationContext oscc = (ServerConfigurationContext) context;
47
48     objectManager = oscc.getObjectManager();
49     this.channelManager = oscc.getChannelManager();
50     this.logger = oscc.getLogger(this.getClass());
51   }
52 }
Popular Tags