org.apache.thrift.async.AsyncMethodCallback Java Examples

The following examples show how to use org.apache.thrift.async.AsyncMethodCallback. 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: 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 #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: LegacyCentralDogmaTest.java    From centraldogma with Apache License 2.0 6 votes vote down vote up
@Test
void listRepositories() throws Exception {
    doAnswer(invocation -> {
        final AsyncMethodCallback<List<Repository>> callback = invocation.getArgument(1);
        final Repository repository = new Repository("repo").setHead(
                new TCommit(new TRevision(42),
                            new TAuthor("hitchhiker", "[email protected]"),
                            "1978-03-08T00:00:00Z", "The primary phrase",
                            new Comment(""), null));
        callback.onComplete(ImmutableList.of(repository));
        return null;
    }).when(iface).listRepositories(any(), any());
    assertThat(client.listRepositories("project").get()).isEqualTo(ImmutableMap.of(
            "repo", new RepositoryInfo("repo", new Revision(42))));
    verify(iface).listRepositories(eq("project"), any());
}
 
Example #4
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 #5
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 #6
Source File: CentralDogmaServiceImpl.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
@Override
public void getHistory(String projectName, String repositoryName, Revision from, Revision to,
                       String pathPattern, AsyncMethodCallback resultHandler) {

    handle(projectManager.get(projectName).repos().get(repositoryName)
                         .history(convert(from), convert(to), pathPattern)
                         .thenApply(commits -> commits.stream()
                                                      .map(Converter::convert)
                                                      .collect(toList())),
           resultHandler);
}
 
Example #7
Source File: LegacyCentralDogmaTest.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
@Test
void listProjects() throws Exception {
    doAnswer(invocation -> {
        final AsyncMethodCallback<List<Project>> callback = invocation.getArgument(0);
        callback.onComplete(ImmutableList.of(new Project("project")));
        return null;
    }).when(iface).listProjects(any());
    assertThat(client.listProjects().get()).isEqualTo(ImmutableSet.of("project"));
    verify(iface).listProjects(any());
}
 
Example #8
Source File: ConfigurationService.java    From xio with Apache License 2.0 5 votes vote down vote up
public void removeIpRule(
    IpRule ipRule, org.apache.thrift.async.AsyncMethodCallback resultHandler)
    throws org.apache.thrift.TException {
  checkReady();
  removeIpRule_call method_call =
      new removeIpRule_call(ipRule, resultHandler, this, ___protocolFactory, ___transport);
  this.___currentMethod = method_call;
  ___manager.call(method_call);
}
 
Example #9
Source File: CentralDogmaServiceImpl.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
@Override
public void unremoveProject(String name, AsyncMethodCallback resultHandler) {
    // Restore the project first then update its metadata as 'active'.
    handleAsVoidResult(executor.execute(Command.unremoveProject(SYSTEM, name))
                               .thenCompose(unused -> mds.restoreProject(SYSTEM, name)),
                       resultHandler);
}
 
Example #10
Source File: TestService.java    From Firefly with Apache License 2.0 5 votes vote down vote up
public AsyncMethodCallback<Void> getResultHandler(final AsyncFrameBuffer fb, final int seqid) {
  final org.apache.thrift.AsyncProcessFunction fcall = this;
  return new AsyncMethodCallback<Void>() { 
    public void onComplete(Void o) {
    }
    public void onError(Exception e) {
    }
  };
}
 
Example #11
Source File: ConfigurationService.java    From xio with Apache License 2.0 5 votes vote down vote up
public void removeHttp1Rule(
    com.xjeffrose.xio.marshall.thrift.Http1Rule http1Rule,
    org.apache.thrift.async.AsyncMethodCallback resultHandler)
    throws org.apache.thrift.TException {
  checkReady();
  removeHttp1Rule_call method_call =
      new removeHttp1Rule_call(
          http1Rule, resultHandler, this, ___protocolFactory, ___transport);
  this.___currentMethod = method_call;
  ___manager.call(method_call);
}
 
Example #12
Source File: Ourea.java    From ourea with Apache License 2.0 5 votes vote down vote up
public void queryEcho(String request, org.apache.thrift.async.AsyncMethodCallback resultHandler)
        throws org.apache.thrift.TException {
    checkReady();
    queryEcho_call method_call = new queryEcho_call(request, resultHandler, this, ___protocolFactory,
            ___transport);
    this.___currentMethod = method_call;
    ___manager.call(method_call);
}
 
Example #13
Source File: ConfigurationService.java    From xio with Apache License 2.0 5 votes vote down vote up
public void start(
    I iface,
    removeHttp1Rule_args args,
    org.apache.thrift.async.AsyncMethodCallback<Result> resultHandler)
    throws TException {
  iface.removeHttp1Rule(args.http1Rule, resultHandler);
}
 
Example #14
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 #15
Source File: ConfigurationService.java    From xio with Apache License 2.0 5 votes vote down vote up
public void start(
    I iface,
    addIpRule_args args,
    org.apache.thrift.async.AsyncMethodCallback<Result> resultHandler)
    throws TException {
  iface.addIpRule(args.ipRule, args.ruleType, resultHandler);
}
 
Example #16
Source File: ConfigurationService.java    From xio with Apache License 2.0 5 votes vote down vote up
public void start(
    I iface,
    removeIpRule_args args,
    org.apache.thrift.async.AsyncMethodCallback<Result> resultHandler)
    throws TException {
  iface.removeIpRule(args.ipRule, resultHandler);
}
 
Example #17
Source File: CentralDogmaServiceImpl.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
@Override
public void mergeFiles(String projectName, String repositoryName, Revision revision,
                       MergeQuery mergeQuery, AsyncMethodCallback resultHandler) {
    handle(projectManager.get(projectName).repos().get(repositoryName)
                         .mergeFiles(convert(revision), convert(mergeQuery))
                         .thenApply(merged -> new MergedEntry(convert(merged.revision()),
                                                              convert(merged.type()),
                                                              merged.contentAsText(),
                                                              merged.paths())),
           resultHandler);
}
 
Example #18
Source File: LegacyCentralDogmaTest.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
@Test
void diffFile() throws Exception {
    doAnswer(invocation -> {
        final AsyncMethodCallback<DiffFileResult> callback = invocation.getArgument(5);
        callback.onComplete(new DiffFileResult(ChangeType.UPSERT_TEXT, "some_text"));
        return null;
    }).when(iface).diffFile(any(), any(), any(), any(), any(), any());
    assertThat(client.getDiff("project", "repo", new Revision(1), new Revision(3),
                              Query.ofText("/a.txt")).get())
            .isEqualTo(Change.ofTextUpsert("/a.txt", "some_text"));
    verify(iface).diffFile(eq("project"), eq("repo"), any(), any(), any(), any());
}
 
Example #19
Source File: ThriftTest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Test
public void asyncMany() throws Exception {
  TestUtil.setGlobalTracer(tracer);

  startAsyncServer();

  final AtomicInteger counter = new AtomicInteger();
  for (int i = 0; i < 4; ++i) {
    final Factory protocolFactory = new Factory();
    final TNonblockingTransport transport = new TNonblockingSocket("localhost", port);
    final TAsyncClientManager clientManager = new TAsyncClientManager();
    final AsyncClient asyncClient = new AsyncClient(protocolFactory, clientManager, transport);
    asyncClient.withDelay(1, new AsyncMethodCallback<String>() {
      @Override
      public void onComplete(final String response) {
        assertEquals("delay 1", response);
        assertNotNull(GlobalTracer.get().activeSpan());
        counter.incrementAndGet();
      }

      @Override
      public void onError(final Exception exception) {
        exception.printStackTrace();
      }
    });
  }

  await().atMost(15, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(8));
  assertEquals(4, counter.get());

  final List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(8, spans.size());

  assertNull(tracer.activeSpan());
  verify(tracer, times(8)).buildSpan(anyString());
  verify(tracer, times(4)).inject(any(SpanContext.class), any(Format.class), any());
}
 
Example #20
Source File: SuroService.java    From suro with Apache License 2.0 4 votes vote down vote up
public getStatus_call(AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws TException {
  super(client, protocolFactory, transport, resultHandler, false);
}
 
Example #21
Source File: ProducerService.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public sendAsync_call(Message message, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
  super(client, protocolFactory, transport, resultHandler, false);
  this.message = message;
}
 
Example #22
Source File: TestThriftService.java    From thrift-pool-client with Artistic License 2.0 4 votes vote down vote up
public void start(I iface, echo_args args,
        org.apache.thrift.async.AsyncMethodCallback<String> resultHandler)
        throws TException {
    iface.echo(args.message, resultHandler);
}
 
Example #23
Source File: ConsumerService.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public ack_call(AckResult result, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
  super(client, protocolFactory, transport, resultHandler, false);
  this.result = result;
}
 
Example #24
Source File: TestThriftService.java    From thrift-client-pool-java with Artistic License 2.0 4 votes vote down vote up
public void start(I iface, echo_args args,
        org.apache.thrift.async.AsyncMethodCallback<String> resultHandler)
        throws TException {
    iface.echo(args.message, resultHandler);
}
 
Example #25
Source File: ProducerService.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public sendDelaySync_call(DelayMessage delayMessage, long timeout, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
  super(client, protocolFactory, transport, resultHandler, false);
  this.delayMessage = delayMessage;
  this.timeout = timeout;
}
 
Example #26
Source File: SuroService.java    From suro with Apache License 2.0 4 votes vote down vote up
public void start(I iface, getName_args args, AsyncMethodCallback<String> resultHandler) throws TException {
  iface.getName(resultHandler);
}
 
Example #27
Source File: AckChain.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public AckChain(AckResult request, AsyncMethodCallback<Boolean> resultHandler) {
    super(request.getGroupId(), request, true, resultHandler);
}
 
Example #28
Source File: HelloService.java    From octo-rpc with Apache License 2.0 4 votes vote down vote up
public void sayBye(String username, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException {
  checkReady();
  sayBye_call method_call = new sayBye_call(username, resultHandler, this, ___protocolFactory, ___transport);
  this.___currentMethod = method_call;
  ___manager.call(method_call);
}
 
Example #29
Source File: Pistachios.java    From Pistachio with Apache License 2.0 4 votes vote down vote up
public void start(I iface, processEvent_args args, org.apache.thrift.async.AsyncMethodCallback<Boolean> resultHandler) throws TException {
  iface.processEvent(args.event, args.jar_url, args.class_full_name,resultHandler);
}
 
Example #30
Source File: ConsumerService.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public void fetch(FetchRequest request, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException {
  checkReady();
  fetch_call method_call = new fetch_call(request, resultHandler, this, ___protocolFactory, ___transport);
  this.___currentMethod = method_call;
  ___manager.call(method_call);
}