1 4 package com.tc.objectserver.persistence.impl; 5 6 import com.tc.async.api.AbstractEventHandler; 7 import com.tc.async.api.EventContext; 8 import com.tc.async.api.Sink; 9 import com.tc.objectserver.persistence.api.PersistentSequence; 10 import com.tc.util.sequence.BatchSequenceProvider; 11 import com.tc.util.sequence.BatchSequenceReceiver; 12 13 public class PersistentBatchSequenceProvider extends AbstractEventHandler implements BatchSequenceProvider { 14 15 private Sink requestBatchSink; 16 private final PersistentSequence sequence; 17 18 public PersistentBatchSequenceProvider(PersistentSequence sequence) { 19 this.sequence = sequence; 20 } 21 22 public void setRequestBatchSink(Sink sink) { 23 this.requestBatchSink = sink; 24 } 25 26 public void handleEvent(EventContext context) { 28 GlobalTransactionIDBatchRequestContext ctxt = (GlobalTransactionIDBatchRequestContext)context; 29 BatchSequenceReceiver receiver = ctxt.getReceiver(); 30 long start = sequence.nextBatch(ctxt.getBatchSize()); 31 receiver.setNextBatch(start, start + ctxt.getBatchSize()); 32 } 33 34 public void requestBatch(BatchSequenceReceiver receiver, int size) { 36 this.requestBatchSink.add(new GlobalTransactionIDBatchRequestContext(receiver, size)); 37 } 38 39 public static final class GlobalTransactionIDBatchRequestContext implements EventContext { 40 private final BatchSequenceReceiver receiver; 41 private final int size; 42 43 public GlobalTransactionIDBatchRequestContext(BatchSequenceReceiver receiver, int size) { 44 this.receiver = receiver; 45 this.size = size; 46 } 47 48 public BatchSequenceReceiver getReceiver() { 49 return this.receiver; 50 } 51 52 public int getBatchSize() { 53 return this.size; 54 } 55 } 56 } 57 | Popular Tags |