Search in sources :

Example 46 with TBinaryProtocol

use of org.apache.thrift.protocol.TBinaryProtocol in project logprocessing by cloudian.

the class CassandraClient method open.

public void open() throws IOException {
    try {
        this.currentServer = this.serverSet.get();
    } catch (ServerSet.NoServersAvailableException e) {
        throw new IOException("No Cassandra servers available.");
    }
    int splitIndex = this.currentServer.indexOf(':');
    if (splitIndex == -1) {
        throw new IOException("Bad host:port pair: " + this.currentServer);
    }
    String host = this.currentServer.substring(0, splitIndex);
    int port = Integer.parseInt(this.currentServer.substring(splitIndex + 1));
    TSocket sock = new TSocket(host, port);
    this.transport = new TFramedTransport(sock);
    TProtocol protocol = new TBinaryProtocol(transport);
    this.client = new Cassandra.Client(protocol);
    try {
        this.transport.open();
        this.client.set_keyspace(this.keyspace);
    } catch (TException texc) {
        throw new IOException(texc.getMessage());
    } catch (InvalidRequestException exc) {
        throw new IOException(exc.getMessage());
    }
}
Also used : TException(org.apache.thrift.TException) Cassandra(org.apache.cassandra.thrift.Cassandra) IOException(java.io.IOException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) TSocket(org.apache.thrift.transport.TSocket)

Example 47 with TBinaryProtocol

use of org.apache.thrift.protocol.TBinaryProtocol in project commons by twitter.

the class PingPongClient method run.

@Override
public void run() {
    TTransport transport = new TSocket("localhost", THRIFT_PORT.get());
    try {
        transport.open();
    } catch (TTransportException e) {
        throw new RuntimeException(e);
    }
    TProtocol protocol = new TBinaryProtocol(transport);
    PingPong.Client client = new PingPong.Client(protocol);
    try {
        LOG.info("Pinging...");
        LOG.info(client.ping());
    } catch (TException e) {
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) PingPong(com.twitter.common.examples.pingpong.PingPong) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 48 with TBinaryProtocol

use of org.apache.thrift.protocol.TBinaryProtocol in project distributedlog by twitter.

the class Utils method parseMessage.

public static Message parseMessage(byte[] data) throws TException {
    Message msg = new Message();
    TMemoryInputTransport transport = new TMemoryInputTransport(data);
    TBinaryProtocol protocol = new TBinaryProtocol(transport);
    msg.read(protocol);
    return msg;
}
Also used : Message(com.twitter.distributedlog.benchmark.thrift.Message) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TMemoryInputTransport(org.apache.thrift.transport.TMemoryInputTransport)

Example 49 with TBinaryProtocol

use of org.apache.thrift.protocol.TBinaryProtocol in project akela by mozilla-metrics.

the class ClusterHealth method testThrift.

private static boolean testThrift(String host) {
    boolean ret = false;
    TTransport transport = null;
    try {
        transport = new TSocket(host, 9090, 3000);
        Hbase.Client client = new Hbase.Client(new TBinaryProtocol(transport));
        transport.open();
        client.getColumnDescriptors(ByteBuffer.wrap(META_TABLE_NAME));
        System.out.println(String.format("%s ThriftServer - [ ALIVE ]", new Object[] { host }));
        ret = true;
    } catch (TTransportException e) {
        System.out.println(String.format("%s ThriftServer - [ DEAD ] - %s", new Object[] { host, e.getMessage() }));
    } catch (IOError e) {
        System.out.println(String.format("%s ThriftServer - [ DEAD ] - %s", new Object[] { host, e.getMessage() }));
    } catch (TException e) {
        System.out.println(String.format("%s ThriftServer - [ DEAD ] - %s", new Object[] { host, e.getMessage() }));
    } finally {
        if (transport != null) {
            transport.close();
        }
    }
    return ret;
}
Also used : TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) IOError(org.apache.hadoop.hbase.thrift.generated.IOError) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) DFSClient(org.apache.hadoop.hdfs.DFSClient) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase) TSocket(org.apache.thrift.transport.TSocket)

Example 50 with TBinaryProtocol

use of org.apache.thrift.protocol.TBinaryProtocol in project eiger by wlloyd.

the class ClientOnlyExample method createConnection.

private static Cassandra.Client createConnection(String host, Integer port, boolean framed) throws TTransportException {
    TSocket socket = new TSocket(host, port);
    TTransport trans = framed ? new TFramedTransport(socket) : socket;
    trans.open();
    TProtocol protocol = new TBinaryProtocol(trans);
    return new Cassandra.Client(protocol);
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)59 TSocket (org.apache.thrift.transport.TSocket)41 TProtocol (org.apache.thrift.protocol.TProtocol)32 TTransport (org.apache.thrift.transport.TTransport)32 TFramedTransport (org.apache.thrift.transport.TFramedTransport)22 TException (org.apache.thrift.TException)18 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)11 IOException (java.io.IOException)10 TTransportException (org.apache.thrift.transport.TTransportException)9 TMessage (org.apache.thrift.protocol.TMessage)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 ImageDatasetService (org.vcell.imagedataset.ImageDatasetService)5 URL (com.alibaba.dubbo.common.URL)4 Channel (com.alibaba.dubbo.remoting.Channel)4