Search in sources :

Example 51 with TBinaryProtocol

use of org.apache.thrift.protocol.TBinaryProtocol in project yyl_example by Relucent.

the class HelloClient method main.

public static void main(String[] args) {
    TTransport transport = null;
    try {
        transport = new TSocket("localhost", 8090);
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        HelloService.Client client = new HelloService.Client(protocol);
        System.out.println(client.hello("thrift world"));
    } catch (TException e) {
        e.printStackTrace();
    } finally {
        transport.close();
    }
}
Also used : TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 52 with TBinaryProtocol

use of org.apache.thrift.protocol.TBinaryProtocol 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

TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)52 TSocket (org.apache.thrift.transport.TSocket)34 TProtocol (org.apache.thrift.protocol.TProtocol)26 TTransport (org.apache.thrift.transport.TTransport)25 TFramedTransport (org.apache.thrift.transport.TFramedTransport)21 TException (org.apache.thrift.TException)16 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)11 IOException (java.io.IOException)10 TMessage (org.apache.thrift.protocol.TMessage)8 TTransportException (org.apache.thrift.transport.TTransportException)8 Test (org.junit.Test)7 Request (com.alibaba.dubbo.remoting.exchange.Request)6 Demo (com.alibaba.dubbo.rpc.gen.thrift.Demo)6 ChannelBuffer (com.alibaba.dubbo.remoting.buffer.ChannelBuffer)5 RpcResult (com.alibaba.dubbo.rpc.RpcResult)5 RandomAccessByteArrayOutputStream (com.alibaba.dubbo.rpc.protocol.thrift.io.RandomAccessByteArrayOutputStream)5 Hbase (org.apache.hadoop.hbase.thrift.generated.Hbase)5 URL (com.alibaba.dubbo.common.URL)4 Channel (com.alibaba.dubbo.remoting.Channel)4 Response (com.alibaba.dubbo.remoting.exchange.Response)4