use of com.yahoo.pulsar.common.api.proto.PulsarApi.CommandCloseProducer in project pulsar by yahoo.
the class ServerCnx method handleCloseProducer.
@Override
protected void handleCloseProducer(CommandCloseProducer closeProducer) {
checkArgument(state == State.Connected);
final long producerId = closeProducer.getProducerId();
final long requestId = closeProducer.getRequestId();
CompletableFuture<Producer> producerFuture = producers.get(producerId);
if (producerFuture == null) {
log.warn("[{}] Producer {} was not registered on the connection", remoteAddress, producerId);
ctx.writeAndFlush(Commands.newError(requestId, ServerError.UnknownError, "Producer was not registered on the connection"));
return;
}
if (!producerFuture.isDone() && producerFuture.completeExceptionally(new IllegalStateException("Closed producer before creation was complete"))) {
// We have received a request to close the producer before it was actually completed, we have marked the
// producer future as failed and we can tell the client the close operation was successful. When the actual
// create operation will complete, the new producer will be discarded.
log.info("[{}] Closed producer {} before its creation was completed", remoteAddress, producerId);
ctx.writeAndFlush(Commands.newSuccess(requestId));
return;
} else if (producerFuture.isCompletedExceptionally()) {
log.info("[{}] Closed producer {} that already failed to be created", remoteAddress, producerId);
ctx.writeAndFlush(Commands.newSuccess(requestId));
return;
}
// Proceed with normal close, the producer
Producer producer = producerFuture.getNow(null);
log.info("[{}][{}] Closing producer on cnx {}", producer.getTopic(), producer.getProducerName(), remoteAddress);
producer.close().thenAccept(v -> {
log.info("[{}][{}] Closed producer on cnx {}", producer.getTopic(), producer.getProducerName(), remoteAddress);
ctx.writeAndFlush(Commands.newSuccess(requestId));
producers.remove(producerId, producerFuture);
});
}
use of com.yahoo.pulsar.common.api.proto.PulsarApi.CommandCloseProducer in project pulsar by yahoo.
the class Commands method newCloseProducer.
public static ByteBuf newCloseProducer(long producerId, long requestId) {
CommandCloseProducer.Builder closeProducerBuilder = CommandCloseProducer.newBuilder();
closeProducerBuilder.setProducerId(producerId);
closeProducerBuilder.setRequestId(requestId);
CommandCloseProducer closeProducer = closeProducerBuilder.build();
ByteBuf res = serializeWithSize(BaseCommand.newBuilder().setType(Type.CLOSE_PRODUCER).setCloseProducer(closeProducerBuilder));
closeProducerBuilder.recycle();
closeProducer.recycle();
return res;
}
Aggregations