use of org.apache.pulsar.common.api.proto.MessageIdData in project pulsar by apache.
the class MessageIdImpl method fromByteArray.
public static MessageId fromByteArray(byte[] data) throws IOException {
Objects.requireNonNull(data);
MessageIdData idData = LOCAL_MESSAGE_ID.get();
try {
idData.parseFrom(Unpooled.wrappedBuffer(data, 0, data.length), data.length);
} catch (Exception e) {
throw new IOException(e);
}
MessageIdImpl messageId;
if (idData.hasBatchIndex()) {
if (idData.hasBatchSize()) {
messageId = new BatchMessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition(), idData.getBatchIndex(), idData.getBatchSize(), BatchMessageAcker.newAcker(idData.getBatchSize()));
} else {
messageId = new BatchMessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition(), idData.getBatchIndex());
}
} else if (idData.hasFirstChunkMessageId()) {
MessageIdData firstChunkIdData = idData.getFirstChunkMessageId();
messageId = new ChunkMessageIdImpl(new MessageIdImpl(firstChunkIdData.getLedgerId(), firstChunkIdData.getEntryId(), firstChunkIdData.getPartition()), new MessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition()));
} else {
messageId = new MessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition());
}
return messageId;
}
use of org.apache.pulsar.common.api.proto.MessageIdData in project pulsar by apache.
the class CompactedTopicImpl method readOneMessageId.
private static CompletableFuture<MessageIdData> readOneMessageId(LedgerHandle lh, long entryId) {
CompletableFuture<MessageIdData> promise = new CompletableFuture<>();
lh.asyncReadEntries(entryId, entryId, (rc, _lh, seq, ctx) -> {
if (rc != BKException.Code.OK) {
promise.completeExceptionally(BKException.create(rc));
} else {
// Need to release buffers for all entries in the sequence
if (seq.hasMoreElements()) {
LedgerEntry entry = seq.nextElement();
try (RawMessage m = RawMessageImpl.deserializeFrom(entry.getEntryBuffer())) {
entry.getEntryBuffer().release();
while (seq.hasMoreElements()) {
seq.nextElement().getEntryBuffer().release();
}
promise.complete(m.getMessageIdData());
}
} else {
promise.completeExceptionally(new NoSuchElementException(String.format("No such entry %d in ledger %d", entryId, lh.getId())));
}
}
}, null);
return promise;
}
use of org.apache.pulsar.common.api.proto.MessageIdData 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;
}
use of org.apache.pulsar.common.api.proto.MessageIdData in project pulsar by apache.
the class Commands method newRedeliverUnacknowledgedMessages.
public static ByteBuf newRedeliverUnacknowledgedMessages(long consumerId, List<MessageIdData> messageIds) {
BaseCommand cmd = localCmd(Type.REDELIVER_UNACKNOWLEDGED_MESSAGES);
CommandRedeliverUnacknowledgedMessages req = cmd.setRedeliverUnacknowledgedMessages().setConsumerId(consumerId);
messageIds.forEach(msgId -> {
MessageIdData m = req.addMessageId().setLedgerId(msgId.getLedgerId()).setEntryId(msgId.getEntryId());
if (msgId.hasBatchIndex()) {
m.setBatchIndex(msgId.getBatchIndex());
}
});
return serializeWithSize(cmd);
}
use of org.apache.pulsar.common.api.proto.MessageIdData in project pulsar by apache.
the class Commands method newSeek.
public static ByteBuf newSeek(long consumerId, long requestId, long ledgerId, long entryId, long[] ackSet) {
BaseCommand cmd = localCmd(Type.SEEK);
CommandSeek seek = cmd.setSeek().setConsumerId(consumerId).setRequestId(requestId);
MessageIdData messageId = seek.setMessageId().setLedgerId(ledgerId).setEntryId(entryId);
for (int i = 0; i < ackSet.length; i++) {
messageId.addAckSet(ackSet[i]);
}
return serializeWithSize(cmd);
}
Aggregations