@Override public void acknowledge(Message message) throws PulsarClientException { try { acknowledge(message.getMessageId()); } catch (NullPointerException npe) { throw new PulsarClientException.InvalidMessageException(npe.getMessage()); } }
@Override public void acknowledge(MessageId messageId) throws PulsarClientException { try { acknowledgeAsync(messageId).get(); } catch (ExecutionException e) { Throwable t = e.getCause(); if (t instanceof PulsarClientException) { throw (PulsarClientException) t; } else { throw new PulsarClientException(t); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PulsarClientException(e); } }
@Override public void acknowledgeCumulative(Message message) throws PulsarClientException { try { acknowledgeCumulative(message.getMessageId()); } catch (NullPointerException npe) { throw new PulsarClientException.InvalidMessageException(npe.getMessage()); } }
@Override public Message receive() throws PulsarClientException { if (listener != null) { throw new PulsarClientException.InvalidConfigurationException( "Cannot use receive() when a listener has been set"); } switch (getState()) { case Ready: case Connecting: break; // Ok case Closing: case Closed: throw new PulsarClientException.AlreadyClosedException("Consumer already closed"); case Failed: case Uninitialized: throw new PulsarClientException.NotConnectedException(); } return internalReceive(); }
@Override public CompletableFuture<Message> receiveAsync() { if (listener != null) { return FutureUtil.failedFuture(new PulsarClientException.InvalidConfigurationException( "Cannot use receive() when a listener has been set")); } switch (getState()) { case Ready: case Connecting: break; // Ok case Closing: case Closed: return FutureUtil.failedFuture(new PulsarClientException.AlreadyClosedException("Consumer already closed")); case Failed: case Uninitialized: return FutureUtil.failedFuture(new PulsarClientException.NotConnectedException()); } return internalReceiveAsync(); }
@Override public CompletableFuture<Void> acknowledgeAsync(MessageId messageId) { return doAcknowledge(messageId, AckType.Individual); }
@Override public void acknowledgeCumulative(MessageId messageId) throws PulsarClientException { try { acknowledgeCumulativeAsync(messageId).get(); } catch (ExecutionException e) { Throwable t = e.getCause(); if (t instanceof PulsarClientException) { throw (PulsarClientException) t; } else { throw new PulsarClientException(t); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PulsarClientException(e); } }
@Override public void close() throws PulsarClientException { try { closeAsync().get(); } catch (ExecutionException e) { Throwable t = e.getCause(); if (t instanceof PulsarClientException) { throw (PulsarClientException) t; } else { throw new PulsarClientException(t); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PulsarClientException(e); } }
@Override public void run(Timeout t) throws Exception { if (isAckTimeout()) { log.warn("[{}] {} messages have timed-out", consumerBase, oldOpenSet.size()); Set<MessageIdImpl> messageIds = new HashSet<>(); oldOpenSet.forEach(messageIds::add); oldOpenSet.clear(); consumerBase.redeliverUnacknowledgedMessages(messageIds); } toggle(); timeout = client.timer().newTimeout(this, ackTimeoutMillis, TimeUnit.MILLISECONDS); } }, ackTimeoutMillis, TimeUnit.MILLISECONDS);
@Override public Message receive(int timeout, TimeUnit unit) throws PulsarClientException { if (conf.getReceiverQueueSize() == 0) { throw new PulsarClientException.InvalidConfigurationException( "Can't use receive with timeout, if the queue size is 0"); } if (listener != null) { throw new PulsarClientException.InvalidConfigurationException( "Cannot use receive() when a listener has been set"); } switch (getState()) { case Ready: case Connecting: break; // Ok case Closing: case Closed: throw new PulsarClientException.AlreadyClosedException("Consumer already closed"); case Failed: case Uninitialized: throw new PulsarClientException.NotConnectedException(); } return internalReceive(timeout, unit); }
@Override public CompletableFuture<Void> acknowledgeCumulativeAsync(MessageId messageId) { if (conf.getSubscriptionType() != SubscriptionType.Exclusive) { return FutureUtil.failedFuture(new PulsarClientException.InvalidConfigurationException( "Cannot use cumulative acks on a non-exclusive subscription")); } return doAcknowledge(messageId, AckType.Cumulative); }
@Override public CompletableFuture<Void> acknowledgeCumulativeAsync(Message message) { try { return acknowledgeCumulativeAsync(message.getMessageId()); } catch (NullPointerException npe) { return FutureUtil.failedFuture(new PulsarClientException.InvalidMessageException(npe.getMessage())); } }
consumersToClose.forEach(c -> futures.add(c.closeAsync()));
@Override public CompletableFuture<Void> acknowledgeAsync(Message message) { try { return acknowledgeAsync(message.getMessageId()); } catch (NullPointerException npe) { return FutureUtil.failedFuture(new PulsarClientException.InvalidMessageException(npe.getMessage())); } }