Search in sources :

Example 1 with LookupDataResult

use of org.apache.pulsar.client.impl.BinaryProtoLookupService.LookupDataResult in project pulsar by apache.

the class ClientCnx method handlePartitionResponse.

@Override
protected void handlePartitionResponse(CommandPartitionedTopicMetadataResponse lookupResult) {
    if (log.isDebugEnabled()) {
        CommandPartitionedTopicMetadataResponse.LookupType response = lookupResult.hasResponse() ? lookupResult.getResponse() : null;
        int partitions = lookupResult.hasPartitions() ? lookupResult.getPartitions() : -1;
        log.debug("Received Broker Partition response: {} {} {}", lookupResult.getRequestId(), response, partitions);
    }
    long requestId = lookupResult.getRequestId();
    CompletableFuture<LookupDataResult> requestFuture = getAndRemovePendingLookupRequest(requestId);
    if (requestFuture != null) {
        if (requestFuture.isCompletedExceptionally()) {
            if (log.isDebugEnabled()) {
                log.debug("{} Request {} already timed-out", ctx.channel(), lookupResult.getRequestId());
            }
            return;
        }
        // Complete future with exception if : Result.response=fail/null
        if (!lookupResult.hasResponse() || CommandPartitionedTopicMetadataResponse.LookupType.Failed.equals(lookupResult.getResponse())) {
            if (lookupResult.hasError()) {
                String message = buildError(lookupResult.getRequestId(), lookupResult.hasMessage() ? lookupResult.getMessage() : null);
                checkServerError(lookupResult.getError(), message);
                requestFuture.completeExceptionally(getPulsarClientException(lookupResult.getError(), message));
            } else {
                requestFuture.completeExceptionally(new PulsarClientException.LookupException("Empty lookup response"));
            }
        } else {
            // return LookupDataResult when Result.response = success/redirect
            requestFuture.complete(new LookupDataResult(lookupResult.getPartitions()));
        }
    } else {
        log.warn("{} Received unknown request id from server: {}", ctx.channel(), lookupResult.getRequestId());
    }
}
Also used : LookupDataResult(org.apache.pulsar.client.impl.BinaryProtoLookupService.LookupDataResult) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) CommandPartitionedTopicMetadataResponse(org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadataResponse)

Example 2 with LookupDataResult

use of org.apache.pulsar.client.impl.BinaryProtoLookupService.LookupDataResult in project pulsar by apache.

the class BinaryProtoLookupServiceTest method createLookupDataResult.

private static LookupDataResult createLookupDataResult(String brokerUrl, boolean redirect) throws Exception {
    LookupDataResult lookupResult = new LookupDataResult(-1);
    Field brokerUrlField = LookupDataResult.class.getDeclaredField("brokerUrl");
    brokerUrlField.setAccessible(true);
    brokerUrlField.set(lookupResult, brokerUrl);
    Field redirectField = LookupDataResult.class.getDeclaredField("redirect");
    redirectField.setAccessible(true);
    redirectField.set(lookupResult, redirect);
    return lookupResult;
}
Also used : Field(java.lang.reflect.Field) LookupDataResult(org.apache.pulsar.client.impl.BinaryProtoLookupService.LookupDataResult)

Example 3 with LookupDataResult

use of org.apache.pulsar.client.impl.BinaryProtoLookupService.LookupDataResult in project pulsar by yahoo.

the class ClientCnx method handlePartitionResponse.

@Override
protected void handlePartitionResponse(CommandPartitionedTopicMetadataResponse lookupResult) {
    if (log.isDebugEnabled()) {
        CommandPartitionedTopicMetadataResponse.LookupType response = lookupResult.hasResponse() ? lookupResult.getResponse() : null;
        int partitions = lookupResult.hasPartitions() ? lookupResult.getPartitions() : -1;
        log.debug("Received Broker Partition response: {} {} {}", lookupResult.getRequestId(), response, partitions);
    }
    long requestId = lookupResult.getRequestId();
    CompletableFuture<LookupDataResult> requestFuture = getAndRemovePendingLookupRequest(requestId);
    if (requestFuture != null) {
        if (requestFuture.isCompletedExceptionally()) {
            if (log.isDebugEnabled()) {
                log.debug("{} Request {} already timed-out", ctx.channel(), lookupResult.getRequestId());
            }
            return;
        }
        // Complete future with exception if : Result.response=fail/null
        if (!lookupResult.hasResponse() || CommandPartitionedTopicMetadataResponse.LookupType.Failed.equals(lookupResult.getResponse())) {
            if (lookupResult.hasError()) {
                String message = buildError(lookupResult.getRequestId(), lookupResult.hasMessage() ? lookupResult.getMessage() : null);
                checkServerError(lookupResult.getError(), message);
                requestFuture.completeExceptionally(getPulsarClientException(lookupResult.getError(), message));
            } else {
                requestFuture.completeExceptionally(new PulsarClientException.LookupException("Empty lookup response"));
            }
        } else {
            // return LookupDataResult when Result.response = success/redirect
            requestFuture.complete(new LookupDataResult(lookupResult.getPartitions()));
        }
    } else {
        log.warn("{} Received unknown request id from server: {}", ctx.channel(), lookupResult.getRequestId());
    }
}
Also used : LookupDataResult(org.apache.pulsar.client.impl.BinaryProtoLookupService.LookupDataResult) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) CommandPartitionedTopicMetadataResponse(org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadataResponse)

Example 4 with LookupDataResult

use of org.apache.pulsar.client.impl.BinaryProtoLookupService.LookupDataResult in project pulsar by yahoo.

the class BinaryProtoLookupServiceTest method createLookupDataResult.

private static LookupDataResult createLookupDataResult(String brokerUrl, boolean redirect) throws Exception {
    LookupDataResult lookupResult = new LookupDataResult(-1);
    Field brokerUrlField = LookupDataResult.class.getDeclaredField("brokerUrl");
    brokerUrlField.setAccessible(true);
    brokerUrlField.set(lookupResult, brokerUrl);
    Field redirectField = LookupDataResult.class.getDeclaredField("redirect");
    redirectField.setAccessible(true);
    redirectField.set(lookupResult, redirect);
    return lookupResult;
}
Also used : Field(java.lang.reflect.Field) LookupDataResult(org.apache.pulsar.client.impl.BinaryProtoLookupService.LookupDataResult)

Example 5 with LookupDataResult

use of org.apache.pulsar.client.impl.BinaryProtoLookupService.LookupDataResult in project incubator-pulsar by apache.

the class BinaryProtoLookupServiceTest method createLookupDataResult.

private static LookupDataResult createLookupDataResult(String brokerUrl, boolean redirect) throws Exception {
    LookupDataResult lookupResult = new LookupDataResult(-1);
    Field brokerUrlField = LookupDataResult.class.getDeclaredField("brokerUrl");
    brokerUrlField.setAccessible(true);
    brokerUrlField.set(lookupResult, brokerUrl);
    Field redirectField = LookupDataResult.class.getDeclaredField("redirect");
    redirectField.setAccessible(true);
    redirectField.set(lookupResult, redirect);
    return lookupResult;
}
Also used : Field(java.lang.reflect.Field) LookupDataResult(org.apache.pulsar.client.impl.BinaryProtoLookupService.LookupDataResult)

Aggregations

LookupDataResult (org.apache.pulsar.client.impl.BinaryProtoLookupService.LookupDataResult)12 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)6 ByteBuf (io.netty.buffer.ByteBuf)3 Field (java.lang.reflect.Field)3 InetSocketAddress (java.net.InetSocketAddress)3 ExecutorService (java.util.concurrent.ExecutorService)3 ClientConfigurationData (org.apache.pulsar.client.impl.conf.ClientConfigurationData)3 CommandLookupTopicResponse (org.apache.pulsar.common.api.proto.CommandLookupTopicResponse)3 CommandPartitionedTopicMetadataResponse (org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadataResponse)3 BeforeMethod (org.testng.annotations.BeforeMethod)3