public boolean containsKey(long key) { return get(key) != null; }
void removeConsumer(final long consumerId) { consumers.remove(consumerId); }
public V remove(long key) { long h = hash(key); return getSection(h).remove(key, null, (int) h); }
CompletableFuture<String> sendRequestWithId(ByteBuf cmd, long requestId) { CompletableFuture<String> future = new CompletableFuture<>(); pendingRequests.put(requestId, future); ctx.writeAndFlush(cmd).addListener(writeFuture -> { if (!writeFuture.isSuccess()) { log.warn("{} Failed to send request to broker: {}", ctx.channel(), writeFuture.cause().getMessage()); pendingRequests.remove(requestId); future.completeExceptionally(writeFuture.cause()); } }); return future; }
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); remoteAddress); ctx.writeAndFlush(Commands.newSuccess(requestId)); producers.remove(producerId, producerFuture); });
CompletableFuture<LedgerHandle> getLedgerHandle(long ledgerId) { CompletableFuture<LedgerHandle> ledgerHandle = ledgerCache.get(ledgerId); if (ledgerHandle != null) { return ledgerHandle; return ledgerCache.computeIfAbsent(ledgerId, lid -> { if (rc != BKException.Code.OK) { ledgerCache.remove(ledgerId, future); future.completeExceptionally(new ManagedLedgerException(BKException.getMessage(rc))); } else {
CompletableFuture<Consumer> existingConsumerFuture = consumers.putIfAbsent(consumerId, consumerFuture); remoteAddress, consumer, e.getMessage()); consumers.remove(consumerId, consumerFuture); exception.getCause().getMessage())); consumers.remove(consumerId, consumerFuture);
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { super.channelInactive(ctx); log.info("{} Disconnected", ctx.channel()); if (!connectionFuture.isDone()) { connectionFuture.completeExceptionally(new PulsarClientException("Connection already closed")); } PulsarClientException e = new PulsarClientException( "Disconnected from server at " + ctx.channel().remoteAddress()); // Fail out all the pending ops pendingRequests.forEach((key, future) -> future.completeExceptionally(e)); pendingLookupRequests.forEach((key, future) -> future.completeExceptionally(e)); // Notify all attached producers/consumers so they have a chance to reconnect producers.forEach((id, producer) -> producer.connectionClosed(this)); consumers.forEach((id, consumer) -> consumer.connectionClosed(this)); }
boolean hasConsumer(long consumerId) { return consumers.containsKey(consumerId); }
public ServerCnx(BrokerService service) { super(service.getKeepAliveIntervalSeconds(), TimeUnit.SECONDS); this.service = service; this.state = State.Start; // This maps are not heavily contended since most accesses are within the cnx thread this.producers = new ConcurrentLongHashMap<>(8, 1); this.consumers = new ConcurrentLongHashMap<>(8, 1); this.replicatorPrefix = service.pulsar().getConfiguration().getReplicatorPrefix(); }
long consumerId = closeConsumer.getConsumerId(); CompletableFuture<Consumer> consumerFuture = consumers.get(consumerId); if (consumerFuture == null) { log.warn("[{}] Consumer was not registered on the connection: {}", consumerId, remoteAddress); try { consumer.close(); consumers.remove(consumerId, consumerFuture); ctx.writeAndFlush(Commands.newSuccess(requestId)); log.info("[{}] Closed consumer {}", remoteAddress, consumer);
CompletableFuture<Producer> existingProducerFuture = producers.putIfAbsent(producerId, producerFuture); producers.remove(producerId, producerFuture); return; producers.remove(producerId, producerFuture); }).exceptionally(exception -> { Throwable cause = exception.getCause(); cause.getMessage())); producers.remove(producerId, producerFuture);
public boolean remove(long key, Object value) { checkNotNull(value); long h = hash(key); return getSection(h).remove(key, value, (int) h) != null; }
@Override protected void handleMessage(CommandMessage cmdMessage, ByteBuf headersAndPayload) { checkArgument(state == State.Ready); if (log.isDebugEnabled()) { log.debug("{} Received a message from the server: {}", ctx.channel(), cmdMessage); } ConsumerImpl consumer = consumers.get(cmdMessage.getConsumerId()); if (consumer != null) { consumer.messageReceived(cmdMessage.getMessageId(), headersAndPayload, this); } }
void removeProducer(final long producerId) { producers.remove(producerId); }
public V put(long key, V value) { checkNotNull(value); long h = hash(key); return getSection(h).put(key, value, (int) h, false, null); }
@Override protected void handleReachedEndOfTopic(CommandReachedEndOfTopic commandReachedEndOfTopic) { final long consumerId = commandReachedEndOfTopic.getConsumerId(); log.info("[{}] Broker notification reached the end of topic: {}", remoteAddress, consumerId); ConsumerImpl consumer = consumers.get(consumerId); if (consumer != null) { consumer.setTerminated(); } }
private CompletableFuture<LookupDataResult> getAndRemovePendingLookupRequest(long requestId) { CompletableFuture<LookupDataResult> result = pendingLookupRequests.remove(requestId); if (result != null) { pendingLookupRequestSemaphore.release(); } return result; }