Search in sources :

Example 1 with CommandPartitionedTopicMetadataResponse

use of org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadataResponse 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 CommandPartitionedTopicMetadataResponse

use of org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadataResponse 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 3 with CommandPartitionedTopicMetadataResponse

use of org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadataResponse in project incubator-pulsar by apache.

the class Commands method newPartitionMetadataResponseCommand.

public static BaseCommand newPartitionMetadataResponseCommand(ServerError error, String errorMsg, long requestId) {
    BaseCommand cmd = localCmd(Type.PARTITIONED_METADATA_RESPONSE);
    CommandPartitionedTopicMetadataResponse response = cmd.setPartitionMetadataResponse().setRequestId(requestId).setError(error).setResponse(CommandPartitionedTopicMetadataResponse.LookupType.Failed);
    if (errorMsg != null) {
        response.setMessage(errorMsg);
    }
    return cmd;
}
Also used : BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand) CommandPartitionedTopicMetadataResponse(org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadataResponse)

Example 4 with CommandPartitionedTopicMetadataResponse

use of org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadataResponse in project incubator-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 5 with CommandPartitionedTopicMetadataResponse

use of org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadataResponse in project pulsar by yahoo.

the class Commands method newPartitionMetadataResponseCommand.

public static BaseCommand newPartitionMetadataResponseCommand(ServerError error, String errorMsg, long requestId) {
    BaseCommand cmd = localCmd(Type.PARTITIONED_METADATA_RESPONSE);
    CommandPartitionedTopicMetadataResponse response = cmd.setPartitionMetadataResponse().setRequestId(requestId).setError(error).setResponse(CommandPartitionedTopicMetadataResponse.LookupType.Failed);
    if (errorMsg != null) {
        response.setMessage(errorMsg);
    }
    return cmd;
}
Also used : BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand) CommandPartitionedTopicMetadataResponse(org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadataResponse)

Aggregations

CommandPartitionedTopicMetadataResponse (org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadataResponse)6 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)3 LookupDataResult (org.apache.pulsar.client.impl.BinaryProtoLookupService.LookupDataResult)3 BaseCommand (org.apache.pulsar.common.api.proto.BaseCommand)3