Search in sources :

Example 81 with TTransport

use of org.apache.thrift.transport.TTransport in project cdap by caskdata.

the class ThriftHelper method getThriftProtocol.

/**
   * generic method to discover a thrift service and start up the
   * thrift transport and protocol layer.
   */
public static TProtocol getThriftProtocol(String serviceName, EndpointStrategy endpointStrategy) throws ServerException {
    Discoverable endpoint = endpointStrategy.pick();
    if (endpoint == null) {
        String message = String.format("Service '%s' is not registered in discovery service.", serviceName);
        LOG.error(message);
        throw new ServerException(message);
    }
    TTransport transport = new TFramedTransport(new TSocket(endpoint.getSocketAddress().getHostName(), endpoint.getSocketAddress().getPort()));
    try {
        transport.open();
    } catch (TTransportException e) {
        String message = String.format("Unable to connect to thrift service %s at %s. Reason: %s", serviceName, endpoint.getSocketAddress(), e.getMessage());
        LOG.error(message);
        throw new ServerException(message, e);
    }
    // now try to connect the thrift client
    return new TBinaryProtocol(transport);
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) ServerException(co.cask.cdap.common.service.ServerException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

TTransport (org.apache.thrift.transport.TTransport)81 TSocket (org.apache.thrift.transport.TSocket)29 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)28 TProtocol (org.apache.thrift.protocol.TProtocol)28 TFramedTransport (org.apache.thrift.transport.TFramedTransport)20 TTransportException (org.apache.thrift.transport.TTransportException)18 Test (org.junit.Test)18 TException (org.apache.thrift.TException)14 IOException (java.io.IOException)11 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)8 ArrayList (java.util.ArrayList)7 Socket (java.net.Socket)5 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)4 TSaslClientTransport (org.apache.thrift.transport.TSaslClientTransport)4 ChannelBuffer (com.alibaba.dubbo.remoting.buffer.ChannelBuffer)3 Request (com.alibaba.dubbo.remoting.exchange.Request)3 Demo (com.alibaba.dubbo.rpc.gen.thrift.Demo)3 SocketFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.SocketFieldAccessor)3 InetSocketAddress (java.net.InetSocketAddress)3 HashMap (java.util.HashMap)3