Search in sources :

Example 46 with TSocket

use of org.apache.thrift.transport.TSocket 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 TSocket

use of org.apache.thrift.transport.TSocket in project brisk by riptano.

the class BriskTool method getConnection.

private Brisk.Iface getConnection() throws IOException {
    TTransport trans = new TFramedTransport(new TSocket(host, port));
    try {
        trans.open();
    } catch (TTransportException e) {
        throw new IOException("unable to connect to brisk server");
    }
    Brisk.Iface client = new Brisk.Client(new TBinaryProtocol(trans));
    return client;
}
Also used : TBinaryProtocol(org.apache.cassandra.thrift.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) Brisk(org.apache.cassandra.thrift.Brisk) Iface(org.apache.cassandra.thrift.Brisk.Iface) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) IOException(java.io.IOException) TSocket(org.apache.thrift.transport.TSocket)

Example 48 with TSocket

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

the class ThriftConnectionFactory method createTransport.

@VisibleForTesting
TTransport createTransport(int timeoutMillis) throws TTransportException, IOException {
    TSocket socket = null;
    if (transportType != TransportType.NONBLOCKING) {
        // can't do a nonblocking create on a blocking transport
        if (timeoutMillis <= 0) {
            return null;
        }
        if (sslTransport) {
            SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
            SSLSocket ssl_socket = (SSLSocket) factory.createSocket(endpoint.getHostName(), endpoint.getPort());
            ssl_socket.setSoTimeout(timeoutMillis);
            return new TSocket(ssl_socket);
        } else {
            socket = new TSocket(endpoint.getHostName(), endpoint.getPort(), timeoutMillis);
        }
    }
    try {
        switch(transportType) {
            case BLOCKING:
                socket.open();
                setSocketTimeout(socket);
                return socket;
            case FRAMED:
                TFramedTransport transport = new TFramedTransport(socket);
                transport.open();
                setSocketTimeout(socket);
                return transport;
            case NONBLOCKING:
                try {
                    return new TNonblockingSocket(endpoint.getHostName(), endpoint.getPort());
                } catch (IOException e) {
                    throw new IOException("Failed to create non-blocking transport to " + endpoint, e);
                }
        }
    } catch (TTransportException e) {
        throw new TTransportException("Failed to create transport to " + endpoint, e);
    }
    throw new IllegalArgumentException("unknown transport type " + transportType);
}
Also used : TNonblockingSocket(org.apache.thrift.transport.TNonblockingSocket) TFramedTransport(org.apache.thrift.transport.TFramedTransport) SSLSocket(javax.net.ssl.SSLSocket) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) TSocket(org.apache.thrift.transport.TSocket) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 49 with TSocket

use of org.apache.thrift.transport.TSocket 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 50 with TSocket

use of org.apache.thrift.transport.TSocket 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)

Aggregations

TSocket (org.apache.thrift.transport.TSocket)66 TTransport (org.apache.thrift.transport.TTransport)43 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)41 TProtocol (org.apache.thrift.protocol.TProtocol)36 TFramedTransport (org.apache.thrift.transport.TFramedTransport)33 IOException (java.io.IOException)16 TException (org.apache.thrift.TException)16 TTransportException (org.apache.thrift.transport.TTransportException)15 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)9 Cassandra (org.apache.cassandra.thrift.Cassandra)5 ImageDatasetService (org.vcell.imagedataset.ImageDatasetService)5 Socket (java.net.Socket)4 SocketException (java.net.SocketException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Hello (org.tech.model.Hello)4 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)3 ByteBuffer (java.nio.ByteBuffer)3 SSLSocket (javax.net.ssl.SSLSocket)3 TBinaryProtocol (org.apache.cassandra.thrift.TBinaryProtocol)3