for (Producer<T> producer : producers) { if (producer != null) { producer.closeAsync().handle((closed, ex) -> { if (ex != null) { closeFail.compareAndSet(null, ex);
@Override public void stop() { this.state = State.STOPPING; producer.closeAsync(); producer = null; this.state = State.STOPPED; }
@Override public void close() throws IOException { if (producer != null) { if (!this.service.removeProducer(this)) { log.warn("[{}] Failed to remove producer handler", producer.getTopic()); } producer.closeAsync().thenAccept(x -> { if (log.isDebugEnabled()) { log.debug("[{}] Closed producer asynchronously", producer.getTopic()); } }).exceptionally(exception -> { log.warn("[{}] Failed to close producer", producer.getTopic(), exception); return null; }); } }
for (Producer<T> producer : producers) { if (producer != null) { producer.closeAsync().handle((closed, ex) -> { if (ex != null) { closeFail.compareAndSet(null, ex);
public void start() throws Exception { Producer producer = getNewProducer(); final Consumer consumer = consumerFuture.get(); while (!stop.get()) { final MutableBoolean wellnessFlag = new MutableBoolean(); final Function<Throwable, ? extends MessageId> exceptionHandler = e -> { // Unset the well flag in the case of an exception so we can // try to get a new Producer. wellnessFlag.value = false; return null; }; while (!stop.get() && wellnessFlag.value) { producer.sendAsync(payload.get()).exceptionally(exceptionHandler); rateLimiter.acquire(); } producer.closeAsync(); if (!stop.get()) { // The Producer failed due to an exception: attempt to get // another producer. producer = getNewProducer(); } else { // We are finished: close the consumer. consumer.closeAsync(); } } } }