KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.objectserver.handler;
6
7 import com.tc.async.api.AbstractEventHandler;
8 import com.tc.async.api.ConfigurationContext;
9 import com.tc.async.api.EventContext;
10 import com.tc.l2.api.ReplicatedClusterStateManager;
11 import com.tc.net.protocol.tcm.MessageChannel;
12 import com.tc.net.protocol.tcm.TCMessageType;
13 import com.tc.object.msg.ObjectIDBatchRequestMessage;
14 import com.tc.object.msg.ObjectIDBatchRequestResponseMessage;
15 import com.tc.objectserver.core.api.ServerConfigurationContext;
16 import com.tc.util.sequence.ObjectIDSequence;
17
18 /**
19  * @author steve
20  */

21 public class RequestObjectIDBatchHandler extends AbstractEventHandler {
22   private final ObjectIDSequence sequenceProvider;
23   private ReplicatedClusterStateManager clusterStateMgr;
24
25   public RequestObjectIDBatchHandler(ObjectIDSequence sequenceProvider) {
26     this.sequenceProvider = sequenceProvider;
27   }
28
29   public synchronized void handleEvent(EventContext context) {
30     ObjectIDBatchRequestMessage m = (ObjectIDBatchRequestMessage) context;
31     int batchSize = m.getBatchSize();
32     long id = m.getRequestID();
33     MessageChannel channel = m.getChannel();
34     ObjectIDBatchRequestResponseMessage response = (ObjectIDBatchRequestResponseMessage) channel
35         .createMessage(TCMessageType.OBJECT_ID_BATCH_REQUEST_RESPONSE_MESSAGE);
36
37     long ids = sequenceProvider.nextObjectIDBatch(batchSize);
38     this.clusterStateMgr.publishNextAvailableObjectID(ids + batchSize);
39     response.initialize(id, ids, ids + batchSize);
40     response.send();
41   }
42
43   public void initialize(ConfigurationContext context) {
44     super.initialize(context);
45     ServerConfigurationContext scc = (ServerConfigurationContext) context;
46     this.clusterStateMgr = scc.getL2Coordinator().getReplicatedClusterStateManager();
47   }
48 }
49
Popular Tags