Java Code Examples for org.apache.pulsar.client.api.PulsarClientException#unwrap()

The following examples show how to use org.apache.pulsar.client.api.PulsarClientException#unwrap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiTopicsConsumerImpl.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Override
protected Message<T> internalReceive(int timeout, TimeUnit unit) throws PulsarClientException {
    Message<T> message;
    try {
        message = incomingMessages.poll(timeout, unit);
        if (message != null) {
            INCOMING_MESSAGES_SIZE_UPDATER.addAndGet(this, -message.getData().length);
            checkArgument(message instanceof TopicMessageImpl);
            unAckedMessageTracker.add(message.getMessageId());
        }
        resumeReceivingFromPausedConsumersIfNeeded();
        return message;
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 2
Source File: PulsarClientImpl.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws PulsarClientException {
    try {
        closeAsync().get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 3
Source File: ConsumerBase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void reconsumeLaterCumulative(Message<?> message, long delayTime, TimeUnit unit) throws PulsarClientException {
    try {
        reconsumeLaterCumulativeAsync(message, delayTime, unit).get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 4
Source File: ConsumerBuilderImpl.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public Consumer<T> subscribe() throws PulsarClientException {
    try {
        return subscribeAsync().get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 5
Source File: ConsumerBase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public MessageId getLastMessageId() throws PulsarClientException {
    try {
        return getLastMessageIdAsync().get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 6
Source File: ConsumerBase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void acknowledge(Messages<?> messages) throws PulsarClientException {
    try {
        acknowledgeAsync(messages).get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 7
Source File: ConsumerBase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void acknowledge(MessageId messageId) throws PulsarClientException {
    try {
        acknowledgeAsync(messageId).get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 8
Source File: ConsumerBase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws PulsarClientException {
    try {
        closeAsync().get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 9
Source File: ConsumerImpl.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void seek(long timestamp) throws PulsarClientException {
    try {
        seekAsync(timestamp).get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 10
Source File: ReaderBuilderImpl.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public Reader<T> create() throws PulsarClientException {
    try {
        return createAsync().get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 11
Source File: ConsumerImpl.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
protected Messages<T> internalBatchReceive() throws PulsarClientException {
    try {
        return internalBatchReceiveAsync().get();
    } catch (InterruptedException | ExecutionException e) {
        State state = getState();
        if (state != State.Closing && state != State.Closed) {
            stats.incrementNumBatchReceiveFailed();
            throw PulsarClientException.unwrap(e);
        } else {
            return null;
        }
    }
}
 
Example 12
Source File: AuthenticationBasic.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public AuthenticationDataProvider getAuthData() throws PulsarClientException {
    try {
        return new AuthenticationDataBasic(userId, password);
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 13
Source File: MultiTopicsConsumerImpl.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void seek(MessageId messageId) throws PulsarClientException {
    try {
        seekAsync(messageId).get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 14
Source File: MultiTopicsConsumerImpl.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
protected Messages<T> internalBatchReceive() throws PulsarClientException {
    try {
        return internalBatchReceiveAsync().get();
    } catch (InterruptedException | ExecutionException e) {
        State state = getState();
        if (state != State.Closing && state != State.Closed) {
            stats.incrementNumBatchReceiveFailed();
            throw PulsarClientException.unwrap(e);
        } else {
            return null;
        }
    }
}
 
Example 15
Source File: MultiTopicsConsumerImpl.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
protected Message<T> internalReceive() throws PulsarClientException {
    Message<T> message;
    try {
        message = incomingMessages.take();
        INCOMING_MESSAGES_SIZE_UPDATER.addAndGet(this, -message.getData().length);
        checkState(message instanceof TopicMessageImpl);
        unAckedMessageTracker.add(message.getMessageId());
        resumeReceivingFromPausedConsumersIfNeeded();
        return message;
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 16
Source File: ProducerBase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws PulsarClientException {
    try {
        closeAsync().get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 17
Source File: ProducerBase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void flush() throws PulsarClientException {
    try {
        flushAsync().get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 18
Source File: ProducerBase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public MessageId send(Message<?> message) throws PulsarClientException {
    try {
        // enqueue the message to the buffer
        CompletableFuture<MessageId> sendFuture = internalSendAsync(message);

        if (!sendFuture.isDone()) {
            // the send request wasn't completed yet (e.g. not failing at enqueuing), then attempt to triggerFlush it out
            triggerFlush();
        }

        return sendFuture.get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 19
Source File: ConsumerBase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void unsubscribe() throws PulsarClientException {
    try {
        unsubscribeAsync().get();
    } catch (Exception e) {
        throw PulsarClientException.unwrap(e);
    }
}
 
Example 20
Source File: ZeroQueueConsumerImpl.java    From pulsar with Apache License 2.0 4 votes vote down vote up
private Message<T> fetchSingleMessageFromBroker() throws PulsarClientException {
    // Just being cautious
    if (incomingMessages.size() > 0) {
        log.error("The incoming message queue should never be greater than 0 when Queue size is 0");
        incomingMessages.clear();
    }

    Message<T> message;
    try {
        // if cnx is null or if the connection breaks the connectionOpened function will send the flow again
        waitingOnReceiveForZeroQueueSize = true;
        synchronized (this) {
            if (isConnected()) {
                sendFlowPermitsToBroker(cnx(), 1);
            }
        }
        do {
            message = incomingMessages.take();
            lastDequeuedMessageId = message.getMessageId();
            ClientCnx msgCnx = ((MessageImpl<?>) message).getCnx();
            // synchronized need to prevent race between connectionOpened and the check "msgCnx == cnx()"
            synchronized (this) {
                // if message received due to an old flow - discard it and wait for the message from the
                // latest flow command
                if (msgCnx == cnx()) {
                    waitingOnReceiveForZeroQueueSize = false;
                    break;
                }
            }
        } while (true);

        stats.updateNumMsgsReceived(message);
        return message;
    } catch (InterruptedException e) {
        stats.incrementNumReceiveFailed();
        throw PulsarClientException.unwrap(e);
    } finally {
        // Finally blocked is invoked in case the block on incomingMessages is interrupted
        waitingOnReceiveForZeroQueueSize = false;
        // Clearing the queue in case there was a race with messageReceived
        incomingMessages.clear();
    }
}