Search in sources :

Example 41 with TFramedTransport

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

use of org.apache.thrift.transport.TFramedTransport in project eiger by wlloyd.

the class ConfigHelper method createConnection.

public static Cassandra.Client createConnection(String host, Integer port, boolean framed) throws IOException {
    TSocket socket = new TSocket(host, port);
    TTransport trans = framed ? new TFramedTransport(socket) : socket;
    try {
        trans.open();
    } catch (TTransportException e) {
        throw new IOException("unable to connect to server", e);
    }
    return new Cassandra.Client(new TBinaryProtocol(trans));
}
Also used : TBinaryProtocol(org.apache.cassandra.thrift.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) IOException(java.io.IOException) TSocket(org.apache.thrift.transport.TSocket)

Example 43 with TFramedTransport

use of org.apache.thrift.transport.TFramedTransport in project eiger by wlloyd.

the class TestRingCache method setup.

private void setup(String server, int port) throws Exception {
    /* Establish a thrift connection to the cassandra instance */
    TSocket socket = new TSocket(server, port);
    System.out.println(" connected to " + server + ":" + port + ".");
    TBinaryProtocol binaryProtocol = new TBinaryProtocol(new TFramedTransport(socket));
    Cassandra.Client cassandraClient = new Cassandra.Client(binaryProtocol);
    socket.open();
    thriftClient = cassandraClient;
    String seed = DatabaseDescriptor.getSeeds().iterator().next().getHostAddress();
    conf = new Configuration();
    ConfigHelper.setOutputPartitioner(conf, DatabaseDescriptor.getPartitioner().getClass().getName());
    ConfigHelper.setOutputInitialAddress(conf, seed);
    ConfigHelper.setOutputRpcPort(conf, Integer.toString(DatabaseDescriptor.getRpcPort()));
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) Configuration(org.apache.hadoop.conf.Configuration) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 44 with TFramedTransport

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

Example 45 with TFramedTransport

use of org.apache.thrift.transport.TFramedTransport in project eiger by wlloyd.

the class EmbeddedCassandraServiceTest method getClient.

/**
 * Gets a connection to the localhost client
 *
 * @return
 * @throws TTransportException
 */
private Cassandra.Client getClient() throws TTransportException {
    TTransport tr = new TFramedTransport(new TSocket("localhost", DatabaseDescriptor.getRpcPort()));
    TProtocol proto = new TBinaryProtocol(tr);
    Cassandra.Client client = new Cassandra.Client(proto);
    tr.open();
    return client;
}
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

TFramedTransport (org.apache.thrift.transport.TFramedTransport)45 TSocket (org.apache.thrift.transport.TSocket)41 TTransport (org.apache.thrift.transport.TTransport)32 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)25 TProtocol (org.apache.thrift.protocol.TProtocol)24 TException (org.apache.thrift.TException)14 IOException (java.io.IOException)11 TTransportException (org.apache.thrift.transport.TTransportException)11 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)10 Cassandra (org.apache.cassandra.thrift.Cassandra)4 Hello (org.tech.model.Hello)4 SocketException (java.net.SocketException)3 HashMap (java.util.HashMap)3 GameRPC (com.code.server.rpc.idl.GameRPC)2 UnknownHostException (java.net.UnknownHostException)2 SSLSocket (javax.net.ssl.SSLSocket)2 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)2 ConfigurationException (org.apache.cassandra.config.ConfigurationException)2 AuthenticationRequest (org.apache.cassandra.thrift.AuthenticationRequest)2 TBinaryProtocol (org.apache.cassandra.thrift.TBinaryProtocol)2