Java 类org.apache.thrift.async.TAsyncClientManager 实例源码

项目:framework    文件:ThriftUtil.java   
public static Constructor<?> getClientConstructor(Class<?> svcInterface) {
    String client = svcInterface.getName().indexOf("Async") > 0 ? ASYNC_CLIENT_NAME : CLIENT_NAME;
    Class<?>[] args = svcInterface.getName().indexOf("Async") > 0 ? new Class[]{TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class} : new Class[]{TProtocol.class};

    Class<?> clientClass = getThriftServiceInnerClassOrNull(svcInterface.getEnclosingClass(), client, false);
    if (clientClass == null) {
        throw new ThriftRuntimeException("the client class is null");
    }

    Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(clientClass, args);
    if (constructor == null) {
        throw new ThriftRuntimeException("the clientClass constructor is null");
    }

    return constructor;
}
项目:rpc-comparison    文件:FunctionTest.java   
@Test
@Ignore
public void testAsync() throws TException, IOException, ExecutionException, InterruptedException {
    AskerServer server = new AskerServer(port, false);
    server.start();

    try (SocketChannel socketChannel = SocketChannel.open()) {
        socketChannel.connect(new InetSocketAddress("localhost", port));
        TNonblockingTransport transport = new TNonblockingSocket(socketChannel);

        final Asker.AsyncClient client = new Asker.AsyncClient(
                new TCompactProtocol.Factory(),
                new TAsyncClientManager(), transport);

        Helper helper = new Helper(collector);

        helper.checkEcho(client);
        helper.checkCount(client);
        helper.checkReverse(client);
        helper.checkUpperCast(client);
        helper.checkLowerCast(client);

        helper.checkRandom(client, 5 + random.nextInt(10));
    }
    server.stop();
}
项目:trpc    文件:AsyncTrpcClient.java   
@Override
@SuppressWarnings("unchecked")
public <X extends TAsyncClient> X getClient(final Class<X> clazz) {
    return (X) super.clients.computeIfAbsent(ClassNameUtils.getOuterClassName(clazz), (className) -> {
        TProtocolFactory protocolFactory = (TProtocolFactory) tTransport -> {
            TProtocol protocol = new TBinaryProtocol(tTransport);
            return new TMultiplexedProtocol(protocol, className);
        };
        try {
            return clazz.getConstructor(TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class)
                    .newInstance(protocolFactory, this.clientManager, this.transport);
        } catch (Throwable e) {
            if (e instanceof UnresolvedAddressException) {
                this.isOpen = false;
            }
            return null;
        }
    });
}
项目:spring-remoting-thrift    文件:ThriftUtil.java   
public static Constructor<?> getClientConstructor(Class<?> svcInterface) {
    String client = svcInterface.getName().indexOf("Async") > 0 ? ASYNC_CLIENT_NAME : CLIENT_NAME;
    Class<?>[] args = svcInterface.getName().indexOf("Async") > 0 ? new Class[]{TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class} : new Class[]{TProtocol.class};

    Class<?> clientClass = getThriftServiceInnerClassOrNull(svcInterface.getEnclosingClass(), client, false);
    if (clientClass == null) {
        throw new ThriftRuntimeException("the client class is null");
    }

    Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(clientClass, args);
    if (constructor == null) {
        throw new ThriftRuntimeException("the clientClass constructor is null");
    }

    return constructor;
}
项目:trpc    文件:AsyncTrpcClient.java   
@Override
public void open() {
    try {
        //异步调用管理器
        this.clientManager = new TAsyncClientManager();
        //设置传输通道,调用非阻塞IO。
        this.transport = new TNonblockingSocket(this.serverInfo.getIp(), this.serverInfo.getPort(), 1000);
    } catch (Exception e) {
        log.error("create AsyncTrpcClient:" + this.serverInfo + " error", e);
        throw new TRpcException("create AsyncTrpcClient:" + this.serverInfo + " error", e);
    }
}
项目:ikasoa    文件:ServerTest.java   
@Test
public void testAysncDefaultThriftServerImpl() {
    int serverPort = 39004;
    TProcessor p = new ThriftSimpleService.Processor<Iface>(new ThriftSimpleServiceImpl());
    ThriftServerConfiguration thriftServerConfiguration = new ThriftServerConfiguration();
    thriftServerConfiguration.setProtocolFactory(new TCompactProtocol.Factory());
    thriftServerConfiguration.setProcessorFactory(new TProcessorFactory(p));
    thriftServerConfiguration.setServerArgsAspect(new ServerArgsAspect() {
        @Override
        public TThreadPoolServer.Args TThreadPoolServerArgsAspect(TThreadPoolServer.Args args) {
            args.stopTimeoutVal = 1;
            return args;
        }
    });
    Factory factory = new GeneralFactory(thriftServerConfiguration);
    ThriftServer thriftServer = factory.getThriftServer(serverName, serverPort, p);
    thriftServer.run();
    try {
        ThriftSimpleService.AsyncClient thriftClient = new ThriftSimpleService.AsyncClient(
                new TCompactProtocol.Factory(), new TAsyncClientManager(),
                new TNonblockingSocket(LOCAL_HOST, serverPort));
        Thread.sleep(500);
        TestCallback callback = new TestCallback();
        thriftClient.get(testString, callback);
        Thread.sleep(1000);
    } catch (Exception e) {
        fail();
    } finally {
        thriftServer.stop();
    }
}
项目:eagle    文件:ThriftClientPool.java   
public ThriftClientPool(MakerFactory<T> maker) {
  pool = new GenericKeyedObjectPool<InetSocketAddress, T>(new PoolFactory(maker),
      getPoolConfig());
  try {
    clientManager = new TAsyncClientManager();
  } catch (IOException e) {
    LOG.fatal(e);
  }
}
项目:pinpoint    文件:AsyncEchoTestClient.java   
@Override
public void verifyTraces(PluginTestVerifier verifier, String expectedMessage) throws Exception {
    final InetSocketAddress actualServerAddress = this.environment.getServerAddress();
    // ********** Asynchronous Traces
    // SpanEvent - Asynchronous Invocation
    ExpectedTrace asyncInvocationTrace = event("ASYNC", "Asynchronous Invocation");

    // SpanEvent - TAsyncMethodCall.cleanUpAndFireCallback
    Method cleanUpAndFireCallback = TAsyncMethodCall.class.getDeclaredMethod("cleanUpAndFireCallback",
            SelectionKey.class);
    ExpectedTrace cleanUpAndFireCallbackTrace = event("THRIFT_CLIENT_INTERNAL", cleanUpAndFireCallback);

    // SpanEvent - TServiceClient.receiveBase
    Method receiveBase = TServiceClient.class.getDeclaredMethod("receiveBase", TBase.class, String.class);
    ExpectedAnnotation thriftResult = Expectations.annotation("thrift.result", "echo_result(success:"
            + expectedMessage + ")");
    ExpectedTrace receiveBaseTrace = event("THRIFT_CLIENT_INTERNAL", // ServiceType
            receiveBase, // Method
            thriftResult // Annotation("thrift.result")
    );

    // ********** Root trace for Asynchronous traces
    // SpanEvent - TAsyncClientManager.call
    Method call = TAsyncClientManager.class.getDeclaredMethod("call", TAsyncMethodCall.class);
    ExpectedAnnotation thriftUrl = Expectations.annotation("thrift.url", actualServerAddress.getHostName() + ":"
            + actualServerAddress.getPort() + "/com/navercorp/pinpoint/plugin/thrift/dto/EchoService/echo_call");
    ExpectedTrace callTrace = event("THRIFT_CLIENT", // ServiceType
            call, // Method
            null, // rpc
            null, // endPoint
            actualServerAddress.getHostName() + ":" + actualServerAddress.getPort(), // destinationId
            thriftUrl // Annotation("thrift.url")
    );
    verifier.verifyTrace(async(callTrace, asyncInvocationTrace, cleanUpAndFireCallbackTrace, receiveBaseTrace));
}
项目:nettythrift    文件:DemoClientTraditionalTEST.java   
@Test
public void test_AsyncClient() throws Throwable {
    Random rnd = new Random(System.nanoTime());

    TProtocolFactory[] protfacs = new TProtocolFactory[] { new TCompactProtocol.Factory(),
            new TBinaryProtocol.Factory(), new TJSONProtocol.Factory(),
            new TSimpleJSONProtocol.Factory(TCalculator.Iface.class, false) };

    TProtocolFactory protocolFactory = protfacs[rnd.nextInt(protfacs.length)];

    System.out.println("protocolFactory: " + protocolFactory);

    TAsyncClientManager clientManager = new TAsyncClientManager();
    TNonblockingTransport transport = new TNonblockingSocket(HOST, PORT);
    TCalculator.AsyncClient client = new TCalculator.AsyncClient(protocolFactory, clientManager, transport);
    final int num1 = rnd.nextInt(Integer.MAX_VALUE / 2 - 1);
    final int num2 = rnd.nextInt(Integer.MAX_VALUE / 2 - 1);

    final CountDownLatch latch = new CountDownLatch(1);
    final Throwable[] exceptions = new Throwable[1];
    AsyncMethodCallback<TCalculator.AsyncClient.add_call> resultHandler = new AsyncMethodCallback<TCalculator.AsyncClient.add_call>() {
        @Override
        public void onComplete(TCalculator.AsyncClient.add_call response) {
            System.out.println("onComplete!");
            try {
                int result = response.getResult();
                Assert.assertEquals(num1 + num2, result);
            } catch (Throwable e) {
                exceptions[0] = e;
            } finally {
                latch.countDown();
            }
        }

        @Override
        public void onError(Exception exception) {
            System.err.println("onError!");
            exception.printStackTrace();
            latch.countDown();
        }

    };
    client.add(num1, num2, resultHandler);
    latch.await();
    transport.close();
    if (exceptions[0] != null) {
        throw exceptions[0];
    }
}
项目:ikasoa    文件:AsyncServiceClientImpl.java   
public AsyncServiceClientImpl(TProtocolFactory protocolFactory, TAsyncClientManager manager,
        TNonblockingTransport transport) {
    super(protocolFactory, manager, transport);
}
项目:ikasoa    文件:AsyncServiceClientImpl.java   
public AsyncServiceClientImpl(TProtocolFactory protocolFactory, TNonblockingTransport transport)
        throws IOException {
    super(protocolFactory, new TAsyncClientManager(), transport);
}
项目:eagle    文件:ThriftClientPool.java   
public T create(TNonblockingTransport tr, TAsyncClientManager mgr,
TProtocolFactory factory);
项目:eagle    文件:ThriftClientPool.java   
@Override
public InternalService.AsyncClient create(TNonblockingTransport tr,
    TAsyncClientManager mgr, TProtocolFactory factory) {
  return new InternalService.AsyncClient(factory, mgr, tr);
}
项目:eagle    文件:ThriftClientPool.java   
@Override
public NodeMonitorService.AsyncClient create(TNonblockingTransport tr,
    TAsyncClientManager mgr, TProtocolFactory factory) {
  return new NodeMonitorService.AsyncClient(factory, mgr, tr);
}
项目:eagle    文件:ThriftClientPool.java   
@Override
public SchedulerService.AsyncClient create(TNonblockingTransport tr,
    TAsyncClientManager mgr, TProtocolFactory factory) {
  return new SchedulerService.AsyncClient(factory, mgr, tr);
}
项目:eagle    文件:ThriftClientPool.java   
@Override
public FrontendService.AsyncClient create(TNonblockingTransport tr,
    TAsyncClientManager mgr, TProtocolFactory factory) {
  return new FrontendService.AsyncClient(factory, mgr, tr);
}
项目:eagle    文件:ThriftClientPool.java   
@Override
public GetTaskService.AsyncClient create(TNonblockingTransport tr,
    TAsyncClientManager mgr, TProtocolFactory factory) {
  return new GetTaskService.AsyncClient(factory, mgr, tr);
}
项目:eagle    文件:ThriftClientPool.java   
@Override
public PongService.AsyncClient create(TNonblockingTransport tr,
    TAsyncClientManager mgr, TProtocolFactory factory) {
  return new PongService.AsyncClient(factory, mgr, tr);
}
项目:ThriftBook    文件:AsyncClient.java   
public static void main(String[] args) 
        throws IOException, InterruptedException, TException {
    //Async client and I/O stack setup
    TNonblockingSocket trans_ep = new TNonblockingSocket("localhost", 9090);
    TAsyncClientManager client_man = new TAsyncClientManager();
    TradeReporting.TradeHistory.AsyncClient client = 
        new TradeReporting.TradeHistory.AsyncClient(new TBinaryProtocol.Factory(),
                                                    client_man, trans_ep);

    //get_last_sale() async callback handler
    WaitableCallback<TradeReport> wc = 
            new WaitableCallback<TradeReport>() {

        @Override
        public void onComplete(TradeReport tr) {
            try {
                System.out.println("[Client] received [" + tr.seq_num + "] " + 
                                   tr.symbol + " : " + tr.size + " @ " + tr.price);
            } finally {
                complete();
            }
        }
    };

    //Make async calls
    wc.reset();
    client.get_last_sale("IBM", wc);
    System.out.println("[Client] get_last_sale() executing asynch...");
    wc.wait(500);
    wc.reset();
    client.get_last_sale("F", wc);
    wc.wait(25000);

    //Make an async call which will time out
    client.setTimeout(1000);
    wc.reset();
    client.get_last_sale("GE", wc);
    wc.wait(5000);

    //Shutdown async client manager and close network socket
    client_man.stop();
    trans_ep.close();
}
项目:NeverwinterDP-Commons    文件:scribe.java   
public Factory(TAsyncClientManager clientManager, TProtocolFactory protocolFactory) {
  this.clientManager = clientManager;
  this.protocolFactory = protocolFactory;
}
项目:NeverwinterDP-Commons    文件:scribe.java   
public AsyncClient(TProtocolFactory protocolFactory, TAsyncClientManager clientManager, TNonblockingTransport transport) {
  super(protocolFactory, clientManager, transport);
}
项目:hat-vldb2014-code    文件:ThriftUtil.java   
public static ReplicaService.AsyncClient getReplicaServiceAsyncClient(
        String host, int port) throws TTransportException, IOException {
    return new ReplicaService.AsyncClient(new TBinaryProtocol.Factory(),
                                          new TAsyncClientManager(),
                                          new TNonblockingSocket(host, port, Config.getSocketTimeout()));
}
项目:hat-vldb2014-code    文件:ThriftUtil.java   
public static AntiEntropyService.AsyncClient getAntiEntropyServiceAsyncClient(
        String host, int port) throws TTransportException, IOException {
    return new AntiEntropyService.AsyncClient(new TBinaryProtocol.Factory(), new TAsyncClientManager(),
                                              new TNonblockingSocket(host, port, Config.getSocketTimeout()));
}
项目:rain    文件:SampleThriftClient.java   
public SampleThriftClient() throws IOException, TException {

        socket = new TNonblockingSocket("localhost", ThriftService.DEFAULT_PORT);
        client = new RainService.AsyncClient(new TBinaryProtocol.Factory(), new TAsyncClientManager(), socket);

        client.startBenchmark(System.currentTimeMillis(), new StartCallback());
    }