01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.objectserver.handler;
06:
07: import com.tc.async.api.AbstractEventHandler;
08: import com.tc.async.api.ConfigurationContext;
09: 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
39: + batchSize);
40: response.initialize(id, ids, ids + batchSize);
41: response.send();
42: }
43:
44: public void initialize(ConfigurationContext context) {
45: super .initialize(context);
46: ServerConfigurationContext scc = (ServerConfigurationContext) context;
47: this.clusterStateMgr = scc.getL2Coordinator()
48: .getReplicatedClusterStateManager();
49: }
50: }
|