@Override public CompletableFuture<List<String>> getPartitionsForTopic(String topic) { return getPartitionedTopicMetadata(topic).thenApply(metadata -> { if (metadata.partitions > 1) { TopicName topicName = TopicName.get(topic); List<String> partitions = new ArrayList<>(metadata.partitions); for (int i = 0; i < metadata.partitions; i++) { partitions.add(topicName.getPartition(i).toString()); } return partitions; } else { return Collections.singletonList(topic); } }); }
private CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadata(InetSocketAddress socketAddress, TopicName topicName) { CompletableFuture<PartitionedTopicMetadata> partitionFuture = new CompletableFuture<PartitionedTopicMetadata>(); client.getCnxPool().getConnection(socketAddress).thenAccept(clientCnx -> { long requestId = client.newRequestId(); ByteBuf request = Commands.newPartitionMetadataRequest(topicName.toString(), requestId); clientCnx.newLookup(request, requestId).thenAccept(lookupDataResult -> { try { partitionFuture.complete(new PartitionedTopicMetadata(lookupDataResult.partitions)); } catch (Exception e) { partitionFuture.completeExceptionally(new PulsarClientException.LookupException( format("Failed to parse partition-response redirect=%s , partitions with %s", lookupDataResult.redirect, lookupDataResult.partitions, e.getMessage()))); } }).exceptionally((e) -> { log.warn("[{}] failed to get Partitioned metadata : {}", topicName.toString(), e.getCause().getMessage(), e); partitionFuture.completeExceptionally(e); return null; }); }).exceptionally(connectionException -> { partitionFuture.completeExceptionally(connectionException); return null; }); return partitionFuture; }
ByteBuf request = Commands.newLookup(topicName.toString(), authoritative, requestId); clientCnx.newLookup(request, requestId).thenAccept(lookupDataResult -> { URI uri = null; }).exceptionally((lookupException) -> { log.warn("[{}] lookup failed : {}", topicName.toString(), lookupException.getMessage(), lookupException); addressFuture.completeExceptionally(lookupException); log.warn("[{}] invalid url {} : {}", topicName.toString(), uri, parseUrlException.getMessage(), parseUrlException); addressFuture.completeExceptionally(parseUrlException); log.warn("[{}] failed to send lookup request : {}", topicName.toString(), sendException.getMessage(), sendException instanceof ClosedChannelException ? null : sendException); addressFuture.completeExceptionally(sendException);
@Override public CompletableFuture<Optional<SchemaInfo>> getSchema(TopicName topicName) { return client.getCnxPool().getConnection(serviceNameResolver.resolveHost()).thenCompose(clientCnx -> { long requestId = client.newRequestId(); ByteBuf request = Commands.newGetSchema(requestId, topicName.toString(), Optional.empty()); return clientCnx.sendGetSchema(request, requestId); }); }
AtomicInteger completed = new AtomicInteger(); for (int partitionIndex = 0; partitionIndex < topicMetadata.numPartitions(); partitionIndex++) { String partitionName = TopicName.get(topic).getPartition(partitionIndex).toString(); ProducerImpl<T> producer = new ProducerImpl<>(client, partitionName, conf, new CompletableFuture<>(), partitionIndex, schema, interceptors);
.mapToObj( partitionIndex -> { String partitionName = TopicName.get(topicName).getPartition(partitionIndex).toString(); CompletableFuture<Consumer<T>> subFuture = new CompletableFuture<>(); ConsumerImpl<T> newConsumer = new ConsumerImpl<>(client, partitionName, configurationData,
final MessageImpl<T> message = new MessageImpl<>(topicName.toString(), batchMessageIdImpl, msgMetadata, singleMessageMetadataBuilder.build(), singleMessagePayload, createEncryptionContext(msgMetadata), cnx, schema, redeliveryCount);
final MessageImpl<T> message = new MessageImpl<>(topicName.toString(), msgId, msgMetadata, uncompressedPayload, createEncryptionContext(msgMetadata), cnx, schema, redeliveryCount);
public static MessageId fromByteArrayWithTopic(byte[] data, TopicName topicName) throws IOException { checkNotNull(data); ByteBufCodedInputStream inputStream = ByteBufCodedInputStream.get(Unpooled.wrappedBuffer(data, 0, data.length)); PulsarApi.MessageIdData.Builder builder = PulsarApi.MessageIdData.newBuilder(); PulsarApi.MessageIdData idData; try { idData = builder.mergeFrom(inputStream, null).build(); } catch (UninitializedMessageException e) { throw new IOException(e); } MessageId messageId; if (idData.hasBatchIndex()) { messageId = new BatchMessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition(), idData.getBatchIndex()); } else { messageId = new MessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition()); } if (idData.getPartition() > -1 && topicName != null) { messageId = new TopicMessageIdImpl( topicName.getPartition(idData.getPartition()).toString(), topicName.toString(), messageId); } inputStream.recycle(); builder.recycle(); idData.recycle(); return messageId; }
private void put(TopicName topicName, PendingBookieOpsStats bookieOpsStats) { String namespace = topicName.getNamespace(); if (!nsBookieClientStatsMap.containsKey(namespace)) { Map<String, PendingBookieOpsStats> destBookieClientStatsMap = Maps.newTreeMap(); destBookieClientStatsMap.put(topicName.toString(), bookieOpsStats); nsBookieClientStatsMap.put(namespace, destBookieClientStatsMap); } else { nsBookieClientStatsMap.get(namespace).put(topicName.toString(), bookieOpsStats); } } }
@Override public void completed(Response response) { try { future.complete(getMessageFromHttpResponse(tn.toString(), response)); } catch (Exception e) { future.completeExceptionally(getApiException(e)); } }
private boolean checkCluster(TopicName topicName) { if (topicName.isGlobal() || conf.getClusterName().equals(topicName.getCluster())) { return true; } else { if (log.isDebugEnabled()) { log.debug("Topic [{}] does not belong to local cluster [{}]", topicName.toString(), conf.getClusterName()); } return false; } }
@Override public boolean includes(TopicName topicName) { if (!this.nsname.equals(topicName.getNamespaceObject())) { return false; } return this.keyRange.contains(factory.getLongHashCode(topicName.toString())); }
private Topic getTopicReference(TopicName topicName) { return pulsar().getBrokerService().getTopicIfExists(topicName.toString()).join() .orElseThrow(() -> new RestException(Status.NOT_FOUND, "Topic not found")); } }
private Topic getTopicReference(TopicName topicName) { return pulsar().getBrokerService().getTopicIfExists(topicName.toString()).join() .orElseThrow(() -> new RestException(Status.NOT_FOUND, "Topic not found")); } }
/** * Get the Topic object reference from the Pulsar broker */ private Topic getTopicReference(TopicName topicName) { return pulsar().getBrokerService().getTopicIfExists(topicName.toString()).join() .orElseThrow(() -> new RestException(Status.NOT_FOUND, "Topic not found")); }
@Override public CompletableFuture<Optional<SchemaInfo>> getSchema(TopicName topicName) { return client.getCnxPool().getConnection(serviceAddress).thenCompose(clientCnx -> { long requestId = client.newRequestId(); ByteBuf request = Commands.newGetSchema(requestId, topicName.toString(), Optional.empty()); return clientCnx.sendGetSchema(request, requestId); }); }
static String validateNonPersistentTopic(List<String> params) { String topic = checkArgument(params); TopicName topicName = TopicName.get(topic); if (topicName.getDomain() != TopicDomain.non_persistent) { throw new ParameterException("Need to provide a non-persistent topic name"); } return topicName.toString(); }