Search in sources :

Example 1 with TNonblockingTransport

use of org.apache.thrift.transport.TNonblockingTransport in project pinpoint by naver.

the class TAsyncMethodCallConstructInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    if (validate(target)) {
        TNonblockingTransport transport = ((TNonblockingTransportFieldGetter) target)._$PINPOINT$_getTNonblockingTransport();
        if (validateTransport(transport)) {
            SocketAddress socketAddress = ((SocketAddressFieldAccessor) transport)._$PINPOINT$_getSocketAddress();
            ((SocketAddressFieldAccessor) target)._$PINPOINT$_setSocketAddress(socketAddress);
        }
    }
}
Also used : SocketAddressFieldAccessor(com.navercorp.pinpoint.plugin.thrift.field.accessor.SocketAddressFieldAccessor) TNonblockingTransport(org.apache.thrift.transport.TNonblockingTransport) TNonblockingTransportFieldGetter(com.navercorp.pinpoint.plugin.thrift.field.getter.TNonblockingTransportFieldGetter) SocketAddress(java.net.SocketAddress)

Example 2 with TNonblockingTransport

use of org.apache.thrift.transport.TNonblockingTransport in project commons by twitter.

the class ThriftFactory method createAsyncClientFactory.

private <T> Function<TTransport, T> createAsyncClientFactory(final Class<T> serviceInterface) throws IOException {
    final TAsyncClientManager clientManager = new TAsyncClientManager();
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        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);
            }
        }
    };
}
Also used : TAsyncClient(org.apache.thrift.async.TAsyncClient) TAsyncClientManager(org.apache.thrift.async.TAsyncClientManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) Function(com.google.common.base.Function) TNonblockingTransport(org.apache.thrift.transport.TNonblockingTransport) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TTransport(org.apache.thrift.transport.TTransport)

Aggregations

TNonblockingTransport (org.apache.thrift.transport.TNonblockingTransport)2 Function (com.google.common.base.Function)1 SocketAddressFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.SocketAddressFieldAccessor)1 TNonblockingTransportFieldGetter (com.navercorp.pinpoint.plugin.thrift.field.getter.TNonblockingTransportFieldGetter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SocketAddress (java.net.SocketAddress)1 TAsyncClient (org.apache.thrift.async.TAsyncClient)1 TAsyncClientManager (org.apache.thrift.async.TAsyncClientManager)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TTransport (org.apache.thrift.transport.TTransport)1