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());
}
}
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;
}
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());
}
}
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;
}
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;
}
Aggregations