List of usage examples for org.apache.thrift.async TAsyncClientManager stop
public void stop()
From source file:com.twitter.common.thrift.ThriftFactory.java
License:Apache License
private <T> Function<TTransport, T> createAsyncClientFactory(final Class<T> serviceInterface) throws IOException { final TAsyncClientManager clientManager = new TAsyncClientManager(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override/*from ww w. j av a 2 s. c o m*/ public void run() { clientManager.stop(); } }); final Constructor<? extends T> implementationConstructor = findAsyncImplementationConstructor( serviceInterface); return new Function<TTransport, T>() { @Override public T apply(TTransport transport) { Preconditions.checkNotNull(transport); Preconditions.checkArgument(transport instanceof TNonblockingTransport, "Invalid transport provided to client factory: " + transport.getClass()); try { T client = implementationConstructor.newInstance(new TBinaryProtocol.Factory(), clientManager, transport); if (socketTimeout != null) { ((TAsyncClient) client).setTimeout(socketTimeout.as(Time.MILLISECONDS)); } return client; } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } }; }
From source file:io.airlift.drift.transport.apache.TestApacheThriftMethodInvoker.java
License:Apache License
private static int logThriftAsync(HostAndPort address, List<LogEntry> messages) { try {/* ww w . j av a 2 s . c o m*/ TAsyncClientManager asyncClientManager = new TAsyncClientManager(); try (TNonblockingSocket socket = new TNonblockingSocket(address.getHost(), address.getPort())) { scribe.AsyncClient client = new scribe.AsyncClient(new Factory(), asyncClientManager, socket); SettableFuture<ResultCode> futureResult = SettableFuture.create(); client.Log(messages, new AsyncMethodCallback<ResultCode>() { @Override public void onComplete(ResultCode resultCode) { try { futureResult.set(resultCode); } catch (Throwable exception) { futureResult.setException(exception); } } @Override public void onError(Exception exception) { futureResult.setException(exception); } }); assertEquals(futureResult.get(), ResultCode.OK); } finally { asyncClientManager.stop(); } } catch (Exception e) { throw new RuntimeException(e); } return 1; }
From source file:io.airlift.drift.transport.netty.client.TestDriftNettyMethodInvoker.java
License:Apache License
private static int logThriftAsync(HostAndPort address, List<LogEntry> messages) { try {//from w w w.ja v a 2 s . c om TAsyncClientManager asyncClientManager = new TAsyncClientManager(); try (TNonblockingSocket socket = new TNonblockingSocket(address.getHost(), address.getPort())) { scribe.AsyncClient client = new scribe.AsyncClient(new TBinaryProtocol.Factory(), asyncClientManager, socket); SettableFuture<ResultCode> futureResult = SettableFuture.create(); client.Log(messages, new AsyncMethodCallback<ResultCode>() { @Override public void onComplete(ResultCode resultCode) { try { futureResult.set(resultCode); } catch (Throwable exception) { futureResult.setException(exception); } } @Override public void onError(Exception exception) { futureResult.setException(exception); } }); assertEquals(futureResult.get(), ResultCode.OK); } finally { asyncClientManager.stop(); } } catch (Exception e) { throw new RuntimeException(e); } return 1; }
From source file:io.airlift.drift.transport.netty.TestDriftNettyMethodInvoker.java
License:Apache License
private static int logThriftAsync(HostAndPort address, List<LogEntry> messages) { try {// www. j a va 2 s.c o m TAsyncClientManager asyncClientManager = new TAsyncClientManager(); try (TNonblockingSocket socket = new TNonblockingSocket(address.getHost(), address.getPort())) { scribe.AsyncClient client = new scribe.AsyncClient(new TBinaryProtocol.Factory(), asyncClientManager, socket); SettableFuture<ResultCode> futureResult = SettableFuture.create(); client.Log(messages, new AsyncMethodCallback<Log_call>() { @Override public void onComplete(Log_call response) { try { futureResult.set(response.getResult()); } catch (Throwable exception) { futureResult.setException(exception); } } @Override public void onError(Exception exception) { futureResult.setException(exception); } }); assertEquals(futureResult.get(), ResultCode.OK); } finally { asyncClientManager.stop(); } } catch (Exception e) { throw new RuntimeException(e); } return 1; }