Java Code Examples for org.apache.thrift.async.AsyncMethodCallback#onError()

The following examples show how to use org.apache.thrift.async.AsyncMethodCallback#onError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsumerServiceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public void ack(AckResult result, AsyncMethodCallback resultHandler) throws TException {
    LOGGER.info("ack:{}", result);
    MetricUtils.incPullStatCount(result.getGroupId(),
            null, null, "ack");
    if (MapUtils.isEmpty(result.getOffsets())) {
        resultHandler.onComplete(true);
        return;
    }
    try {
        AckChain ackChain = new AckChain(result, resultHandler);
        ackChain.doNext();
        LOGGER.trace("[lowlevel] AckChain start. consumer num:{}, group:{}", ackChain.getConsumerNum(), result.getGroupId());
    } catch (Exception e) {
        LOGGER.error("exception in ack:" + result, e);
        resultHandler.onError(e);
    }
}
 
Example 2
Source File: ConsumerServiceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public void ack(AckResult result, AsyncMethodCallback resultHandler) throws TException {
    LOGGER.info("ack:{}", result);
    MetricUtils.incPullStatCount(result.getGroupId(),
            null, null, "ack");
    if (MapUtils.isEmpty(result.getOffsets())) {
        resultHandler.onComplete(true);
        return;
    }
    try {
        AckChain ackChain = new AckChain(result, resultHandler);
        ackChain.doNext();
        LOGGER.trace("[lowlevel] AckChain start. consumer num:{}, group:{}", ackChain.getConsumerNum(), result.getGroupId());
    } catch (Exception e) {
        LOGGER.error("exception in ack:" + result, e);
        resultHandler.onError(e);
    }
}
 
Example 3
Source File: ConsumerServiceImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void getConsumeStats(ConsumeStatsRequest request, AsyncMethodCallback resultHandler) {
    try {
        executor.execute(() -> doGetConsumeStats(request.topic, request.group, resultHandler));
        LOGGER.info("getConsumeStats group:{}, sdk version:{}", request.getGroup(), request.getVersion());
    } catch (RejectedExecutionException e) {
        resultHandler.onError(e);
        LOGGER.info("Error while submit doGetConsumeStats task to thread pool. err.msg:{}", e.getMessage(), e);
    }
}
 
Example 4
Source File: ConsumerServiceImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void fetch(FetchRequest request, AsyncMethodCallback resultHandler) throws TException {
    LOGGER.trace("fetch:{}", request);
    MetricUtils.incPullStatCount(request.getGroupId(),
            null, null, "fetch");
    try {
        FetchChain fetchAction = new FetchChain(request, resultHandler);
        fetchAction.doNext();
        LOGGER.trace("[lowlevel] FetchChain start. consumer num:{}, group:{}.", fetchAction.getConsumerNum(), request.groupId);
    } catch (Exception e) {
        LOGGER.error("exception in fetch:" + request, e);
        resultHandler.onError(e);
    }
}
 
Example 5
Source File: ConsumerServiceImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void getConsumeStats(ConsumeStatsRequest request, AsyncMethodCallback resultHandler) {
    try {
        executor.execute(() -> doGetConsumeStats(request.topic, request.group, resultHandler));
        LOGGER.info("getConsumeStats group:{}, sdk version:{}", request.getGroup(), request.getVersion());
    } catch (RejectedExecutionException e) {
        resultHandler.onError(e);
        LOGGER.info("Error while submit doGetConsumeStats task to thread pool. err.msg:{}", e.getMessage(), e);
    }
}
 
Example 6
Source File: ConsumerServiceImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void fetch(FetchRequest request, AsyncMethodCallback resultHandler) throws TException {
    LOGGER.trace("fetch:{}", request);
    MetricUtils.incPullStatCount(request.getGroupId(),
            null, null, "fetch");
    try {
        FetchChain fetchAction = new FetchChain(request, resultHandler);
        fetchAction.doNext();
        LOGGER.trace("[lowlevel] FetchChain start. consumer num:{}, group:{}.", fetchAction.getConsumerNum(), request.groupId);
    } catch (Exception e) {
        LOGGER.error("exception in fetch:" + request, e);
        resultHandler.onError(e);
    }
}
 
Example 7
Source File: CentralDogmaServiceImpl.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
private static void handle(Callable<?> task, AsyncMethodCallback resultHandler) {
    try {
        resultHandler.onComplete(task.call());
    } catch (Throwable cause) {
        resultHandler.onError(convert(cause));
    }
}
 
Example 8
Source File: CentralDogmaServiceImpl.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
@Override
public void createRepository(String projectName, String repositoryName,
                             AsyncMethodCallback resultHandler) {
    // HTTP v1 API will return '403 forbidden' in this case, but we deal it as '400 bad request' here.
    if (isReservedRepoName(repositoryName)) {
        resultHandler.onError(convert(RESERVED_REPOSITORY_EXCEPTION));
        return;
    }
    handleAsVoidResult(executor.execute(Command.createRepository(SYSTEM, projectName, repositoryName))
                               .thenCompose(unused -> mds.addRepo(SYSTEM, projectName, repositoryName)),
                       resultHandler);
}
 
Example 9
Source File: CentralDogmaServiceImpl.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
@Override
public void removeRepository(String projectName, String repositoryName,
                             AsyncMethodCallback resultHandler) {
    // HTTP v1 API will return '403 forbidden' in this case, but we deal it as '400 bad request' here.
    if (isReservedRepoName(repositoryName)) {
        resultHandler.onError(convert(RESERVED_REPOSITORY_EXCEPTION));
        return;
    }
    handleAsVoidResult(executor.execute(Command.removeRepository(SYSTEM, projectName, repositoryName))
                               .thenCompose(unused -> mds.removeRepo(SYSTEM, projectName, repositoryName)),
                       resultHandler);
}
 
Example 10
Source File: AsyncMethodCallbacks.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes {@link AsyncMethodCallback#onError(Exception)}. If the specified {@code cause} is not an
 * {@link Exception}, it will be wrapped with a {@link CompletionException}.
 */
public static void invokeOnError(AsyncMethodCallback<?> callback, Throwable cause) {
    requireNonNull(callback, "callback");
    requireNonNull(cause, "cause");
    if (cause instanceof Exception) {
        callback.onError((Exception) cause);
    } else {
        callback.onError(new CompletionException(cause.toString(), cause));
    }
}
 
Example 11
Source File: CentralDogmaServiceImpl.java    From centraldogma with Apache License 2.0 4 votes vote down vote up
private static void rejectInvalidWatchTimeout(String operationName, AsyncMethodCallback resultHandler) {
    final CentralDogmaException cde = new CentralDogmaException(ErrorCode.BAD_REQUEST);
    CentralDogmaExceptions.log(operationName, cde);
    resultHandler.onError(cde);
}
 
Example 12
Source File: CentralDogmaServiceImpl.java    From centraldogma with Apache License 2.0 4 votes vote down vote up
private static void logAndInvokeOnError(
        String operationName, AsyncMethodCallback resultHandler, Throwable cause) {
    final CentralDogmaException cde = convert(cause);
    CentralDogmaExceptions.log(operationName, cde);
    resultHandler.onError(cde);
}
 
Example 13
Source File: CentralDogmaServiceImpl.java    From centraldogma with Apache License 2.0 4 votes vote down vote up
private static void unimplemented(AsyncMethodCallback resultHandler) {
    resultHandler.onError(new CentralDogmaException(ErrorCode.UNIMPLEMENTED));
}