1 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 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 |