use of org.apache.pulsar.common.util.collections.ConcurrentBitSetRecyclable in project pulsar by apache.
the class AcknowledgementsGroupingTrackerTest method testDoIndividualBatchAckAsync.
@Test
public void testDoIndividualBatchAckAsync() throws Exception {
ConsumerConfigurationData<?> conf = new ConsumerConfigurationData<>();
AcknowledgmentsGroupingTracker tracker = new PersistentAcknowledgmentsGroupingTracker(consumer, conf, eventLoopGroup);
MessageId messageId1 = new BatchMessageIdImpl(5, 1, 0, 3, 10, BatchMessageAckerDisabled.INSTANCE);
BitSet bitSet = new BitSet(20);
for (int i = 0; i < 20; i++) {
bitSet.set(i, true);
}
MessageId messageId2 = new BatchMessageIdImpl(3, 2, 0, 5, 20, BatchMessageAcker.newAcker(bitSet));
Method doIndividualBatchAckAsync = PersistentAcknowledgmentsGroupingTracker.class.getDeclaredMethod("doIndividualBatchAckAsync", BatchMessageIdImpl.class);
doIndividualBatchAckAsync.setAccessible(true);
doIndividualBatchAckAsync.invoke(tracker, messageId1);
doIndividualBatchAckAsync.invoke(tracker, messageId2);
Field pendingIndividualBatchIndexAcks = PersistentAcknowledgmentsGroupingTracker.class.getDeclaredField("pendingIndividualBatchIndexAcks");
pendingIndividualBatchIndexAcks.setAccessible(true);
ConcurrentHashMap<MessageIdImpl, ConcurrentBitSetRecyclable> batchIndexAcks = (ConcurrentHashMap<MessageIdImpl, ConcurrentBitSetRecyclable>) pendingIndividualBatchIndexAcks.get(tracker);
MessageIdImpl position1 = new MessageIdImpl(5, 1, 0);
MessageIdImpl position2 = new MessageIdImpl(3, 2, 0);
assertTrue(batchIndexAcks.containsKey(position1));
assertNotNull(batchIndexAcks.get(position1));
assertEquals(batchIndexAcks.get(position1).cardinality(), 9);
assertTrue(batchIndexAcks.containsKey(position2));
assertNotNull(batchIndexAcks.get(position2));
assertEquals(batchIndexAcks.get(position2).cardinality(), 19);
tracker.close();
}
use of org.apache.pulsar.common.util.collections.ConcurrentBitSetRecyclable in project pulsar by apache.
the class PersistentAcknowledgmentsGroupingTracker method doIndividualBatchAckAsync.
private void doIndividualBatchAckAsync(BatchMessageIdImpl batchMessageId) {
ConcurrentBitSetRecyclable bitSet = pendingIndividualBatchIndexAcks.computeIfAbsent(new MessageIdImpl(batchMessageId.getLedgerId(), batchMessageId.getEntryId(), batchMessageId.getPartitionIndex()), (v) -> {
ConcurrentBitSetRecyclable value;
if (batchMessageId.getAcker() != null && !(batchMessageId.getAcker() instanceof BatchMessageAckerDisabled)) {
value = ConcurrentBitSetRecyclable.create(batchMessageId.getAcker().getBitSet());
} else {
value = ConcurrentBitSetRecyclable.create();
value.set(0, batchMessageId.getOriginalBatchSize());
}
return value;
});
bitSet.clear(batchMessageId.getBatchIndex());
}
use of org.apache.pulsar.common.util.collections.ConcurrentBitSetRecyclable in project pulsar by apache.
the class Commands method newMultiMessageAckCommon.
private static BaseCommand newMultiMessageAckCommon(List<Triple<Long, Long, ConcurrentBitSetRecyclable>> entries) {
BaseCommand cmd = localCmd(Type.ACK);
CommandAck ack = cmd.setAck();
int entriesCount = entries.size();
for (int i = 0; i < entriesCount; i++) {
long ledgerId = entries.get(i).getLeft();
long entryId = entries.get(i).getMiddle();
ConcurrentBitSetRecyclable bitSet = entries.get(i).getRight();
MessageIdData msgId = ack.addMessageId().setLedgerId(ledgerId).setEntryId(entryId);
if (bitSet != null) {
long[] ackSet = bitSet.toLongArray();
for (int j = 0; j < ackSet.length; j++) {
msgId.addAckSet(ackSet[j]);
}
bitSet.recycle();
}
}
return cmd;
}
Aggregations