Search in sources :

Example 71 with TopicName

use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.

the class NonPersistentTopicsImpl method getStatsAsync.

@Override
public CompletableFuture<NonPersistentTopicStats> getStatsAsync(String topic) {
    TopicName topicName = validateTopic(topic);
    final CompletableFuture<NonPersistentTopicStats> future = new CompletableFuture<>();
    WebTarget path = topicPath(topicName, "stats");
    asyncGetRequest(path, new InvocationCallback<NonPersistentTopicStats>() {

        @Override
        public void completed(NonPersistentTopicStats response) {
            future.complete(response);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) NonPersistentTopicStats(org.apache.pulsar.common.policies.data.NonPersistentTopicStats) WebTarget(javax.ws.rs.client.WebTarget) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 72 with TopicName

use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.

the class PersistentTopicsImpl method getSubscriptionsAsync.

@Override
public CompletableFuture<List<String>> getSubscriptionsAsync(String topic) {
    TopicName tn = validateTopic(topic);
    WebTarget path = topicPath(tn, "subscriptions");
    final CompletableFuture<List<String>> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<List<String>>() {

        @Override
        public void completed(List<String> response) {
            future.complete(response);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) List(java.util.List) ArrayList(java.util.ArrayList) WebTarget(javax.ws.rs.client.WebTarget) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 73 with TopicName

use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.

the class PersistentTopicsImpl method getPartitionedTopicMetadataAsync.

@Override
public CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadataAsync(String topic) {
    TopicName tn = validateTopic(topic);
    WebTarget path = topicPath(tn, "partitions");
    final CompletableFuture<PartitionedTopicMetadata> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<PartitionedTopicMetadata>() {

        @Override
        public void completed(PartitionedTopicMetadata response) {
            future.complete(response);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) WebTarget(javax.ws.rs.client.WebTarget) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 74 with TopicName

use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.

the class PersistentTopicsImpl method peekNthMessage.

private CompletableFuture<List<Message<byte[]>>> peekNthMessage(String topic, String subName, int messagePosition) {
    TopicName tn = validateTopic(topic);
    String encodedSubName = Codec.encode(subName);
    WebTarget path = topicPath(tn, "subscription", encodedSubName, "position", String.valueOf(messagePosition));
    final CompletableFuture<List<Message<byte[]>>> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<Response>() {

        @Override
        public void completed(Response response) {
            try {
                future.complete(getMessageFromHttpResponse(response));
            } catch (Exception e) {
                future.completeExceptionally(getApiException(e));
            }
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : Response(javax.ws.rs.core.Response) CompletableFuture(java.util.concurrent.CompletableFuture) List(java.util.List) ArrayList(java.util.ArrayList) WebTarget(javax.ws.rs.client.WebTarget) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) ClientErrorException(javax.ws.rs.ClientErrorException) WebApplicationException(javax.ws.rs.WebApplicationException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ExecutionException(java.util.concurrent.ExecutionException) ServerErrorException(javax.ws.rs.ServerErrorException) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 75 with TopicName

use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.

the class PersistentTopicsImpl method expireMessagesForAllSubscriptionsAsync.

@Override
public CompletableFuture<Void> expireMessagesForAllSubscriptionsAsync(String topic, long expireTimeInSeconds) {
    TopicName tn = validateTopic(topic);
    WebTarget path = topicPath(tn, "all_subscription", "expireMessages", String.valueOf(expireTimeInSeconds));
    return asyncPostRequest(path, Entity.entity("", MediaType.APPLICATION_JSON));
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) TopicName(org.apache.pulsar.common.naming.TopicName)

Aggregations

TopicName (org.apache.pulsar.common.naming.TopicName)127 Test (org.testng.annotations.Test)54 CompletableFuture (java.util.concurrent.CompletableFuture)43 WebTarget (javax.ws.rs.client.WebTarget)32 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)23 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)23 Logger (org.slf4j.Logger)23 LoggerFactory (org.slf4j.LoggerFactory)23 List (java.util.List)22 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)22 Map (java.util.Map)20 ExecutionException (java.util.concurrent.ExecutionException)20 TimeUnit (java.util.concurrent.TimeUnit)20 NamingException (org.apache.pulsar.broker.service.BrokerServiceException.NamingException)18 Field (java.lang.reflect.Field)17 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)17 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)17 ByteBuf (io.netty.buffer.ByteBuf)15 Set (java.util.Set)15 ServerMetadataException (org.apache.pulsar.broker.service.BrokerServiceException.ServerMetadataException)14