Search in sources :

Example 11 with MessageIdData

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;
}
Also used : MessageIdData(org.apache.pulsar.common.api.proto.MessageIdData) IOException(java.io.IOException) IOException(java.io.IOException)

Example 12 with MessageIdData

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) MessageIdData(org.apache.pulsar.common.api.proto.MessageIdData) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) RawMessage(org.apache.pulsar.client.api.RawMessage) NoSuchElementException(java.util.NoSuchElementException)

Example 13 with MessageIdData

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;
}
Also used : CommandAck(org.apache.pulsar.common.api.proto.CommandAck) MessageIdData(org.apache.pulsar.common.api.proto.MessageIdData) BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand) ConcurrentBitSetRecyclable(org.apache.pulsar.common.util.collections.ConcurrentBitSetRecyclable)

Example 14 with MessageIdData

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);
}
Also used : MessageIdData(org.apache.pulsar.common.api.proto.MessageIdData) BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand) CommandRedeliverUnacknowledgedMessages(org.apache.pulsar.common.api.proto.CommandRedeliverUnacknowledgedMessages)

Example 15 with MessageIdData

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);
}
Also used : CommandSeek(org.apache.pulsar.common.api.proto.CommandSeek) MessageIdData(org.apache.pulsar.common.api.proto.MessageIdData) BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand)

Aggregations

MessageIdData (org.apache.pulsar.common.api.proto.MessageIdData)24 ByteBuf (io.netty.buffer.ByteBuf)12 CompletableFuture (java.util.concurrent.CompletableFuture)8 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)8 ArrayList (java.util.ArrayList)7 Collections (java.util.Collections)6 List (java.util.List)6 MessageId (org.apache.pulsar.client.api.MessageId)6 FutureUtil (org.apache.pulsar.common.util.FutureUtil)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)5 Map (java.util.Map)5 Objects (java.util.Objects)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 Collectors (java.util.stream.Collectors)5 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)5 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)5 CommandAck (org.apache.pulsar.common.api.proto.CommandAck)5 InitialPosition (org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition)5 MessageMetadata (org.apache.pulsar.common.api.proto.MessageMetadata)5 IOException (java.io.IOException)4