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

The following examples show how to use org.apache.thrift.async.AsyncMethodCallback#onComplete() . 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: ProducerAsyncServerImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public void sendSync(Message message, long timeout, @SuppressWarnings("rawtypes") AsyncMethodCallback resultHandler) throws TException {
    if (HEARTBEAT_TOPIC.equals(message.topic)) {
        MetricUtils.incRequestCounter(message.topic, MetricUtils.REQUEST_SYNC);
        resultHandler.onComplete(ProxySendResult.OK.getResult());
        return;
    }

    MetricUtils.incRequestCounter(message.topic, MetricUtils.REQUEST_SYNC);
    CarreraRequest request = new CarreraRequest(producerPool, message, timeout, resultHandler);

    if (request.checkValid()) {
        request.registerTimeout(TimeOutHandlerMgr.selectOneTimeOutChecker());
        request.process();
    } else {
        request.onFinish(ProxySendResult.FAIL_ILLEGAL_MSG);
    }
}
 
Example 2
Source File: ConsumerServiceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void responsePull(PullRequest request, AsyncMethodCallback resultHandler, Context context, List<Message> messages) {
    PullResponse response;

    if (CollectionUtils.isEmpty(messages)) {
        response = EMPTY_PULL_RESPONSE;
    } else {
        response = new PullResponse(context, messages);
    }

    stats(request, response);
    if (LOGGER.isDebugEnabled() && CollectionUtils.isNotEmpty(messages)) {
        LOGGER.debug("pull result:context={},clientAddress={},result={}, ", context, getClientAddress(),
                messages.stream()
                        .map(msg -> String.format("[key=%s,offset=%d]", msg.getKey(), msg.getOffset()))
                        .collect(Collectors.toList())
        );
    }

    resultHandler.onComplete(response);
}
 
Example 3
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 4
Source File: ProducerAsyncServerImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public void sendSync(Message message, long timeout, @SuppressWarnings("rawtypes") AsyncMethodCallback resultHandler) throws TException {
    if (HEARTBEAT_TOPIC.equals(message.topic)) {
        MetricUtils.incRequestCounter(message.topic, MetricUtils.REQUEST_SYNC);
        resultHandler.onComplete(ProxySendResult.OK.getResult());
        return;
    }

    MetricUtils.incRequestCounter(message.topic, MetricUtils.REQUEST_SYNC);
    CarreraRequest request = new CarreraRequest(producerPool, message, timeout, resultHandler);

    if (request.checkValid()) {
        request.registerTimeout(TimeOutHandlerMgr.selectOneTimeOutChecker());
        request.process();
    } else {
        request.onFinish(ProxySendResult.FAIL_ILLEGAL_MSG);
    }
}
 
Example 5
Source File: ConsumerServiceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void responsePull(PullRequest request, AsyncMethodCallback resultHandler, Context context, List<Message> messages) {
    PullResponse response;

    if (CollectionUtils.isEmpty(messages)) {
        response = EMPTY_PULL_RESPONSE;
    } else {
        response = new PullResponse(context, messages);
    }

    stats(request, response);
    if (LOGGER.isDebugEnabled() && CollectionUtils.isNotEmpty(messages)) {
        LOGGER.debug("pull result:context={},clientAddress={},result={}, ", context, getClientAddress(),
                messages.stream()
                        .map(msg -> String.format("[key=%s,offset=%d]", msg.getKey(), msg.getOffset()))
                        .collect(Collectors.toList())
        );
    }

    resultHandler.onComplete(response);
}
 
Example 6
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 7
Source File: Main.java    From Jax-RS-Performance-Comparison with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    HelloService.AsyncIface helloHandler = new HelloService.AsyncIface(){
        @Override
        public void hello(AsyncMethodCallback resultHandler) throws TException {
            resultHandler.onComplete("Hello world");
        }
    };

    ServerBuilder sb = new ServerBuilder();
    sb.port(8080, SessionProtocol.HTTP);
    sb.serviceAt("/hello", ThriftService.of(helloHandler, SerializationFormat.THRIFT_BINARY))
            .serviceUnder("/docs/", new DocService());

    Server server= sb.build();
    server.start();
}
 
Example 8
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 9
Source File: CentralDogmaServiceImpl.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
@Override
public void normalizeRevision(String projectName, String repositoryName, Revision revision,
                              AsyncMethodCallback resultHandler) {

    final com.linecorp.centraldogma.common.Revision normalized =
            projectManager.get(projectName).repos().get(repositoryName)
                          .normalizeNow(convert(revision));
    resultHandler.onComplete(convert(normalized));
}
 
Example 10
Source File: ThriftTreeStructureTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void createTree(TreeRequest request, AsyncMethodCallback resultHandler)
        throws TException {
    assertThat(request).isEqualTo(treeRequest);
    resultHandler.onComplete("OK");
}
 
Example 11
Source File: AsyncServer.java    From ThriftBook with Apache License 2.0 5 votes vote down vote up
@Override
public void get_last_sale(String symbol, AsyncMethodCallback callback)
        throws org.apache.thrift.TException {
    if (symbol.length() < 3) {
        manual.add(new FloorQuoteReq(symbol, callback));
    } else {
        callback.onComplete(electronic.get_last_sale(symbol));
    }
}
 
Example 12
Source File: AsyncEchoTestServer.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private static TProcessor getAsyncProcessor() {
    return new EchoService.AsyncProcessor<EchoService.AsyncIface>(new EchoService.AsyncIface() {
        @Override
        public void echo(String message, AsyncMethodCallback<String> resultHandler) throws TException {
            resultHandler.onComplete(message);
        }
    });
}
 
Example 13
Source File: AsyncProcessFunctionMock.java    From thrift-mock with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Object iface, TBase args, AsyncMethodCallback resultHandler) throws TException {
  delay(delay);
  resultHandler.onComplete(new MockResult(methodName, mockResultFunction.apply(args)));
}
 
Example 14
Source File: ConsumerServiceImpl.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public void submit(ConsumeResult result, AsyncMethodCallback resultHandler) {
    stats(result);
    resultHandler.onComplete(doSubmit(result));
}
 
Example 15
Source File: ConsumerServiceImpl.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public void submit(ConsumeResult result, AsyncMethodCallback resultHandler) {
    stats(result);
    resultHandler.onComplete(doSubmit(result));
}
 
Example 16
Source File: AbstractThriftOverHttpTest.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void hello(String name, AsyncMethodCallback resultHandler) throws TException {
    resultHandler.onComplete(getResponse(name));
}