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);
}
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));
}
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()));
}
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);
}
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;
}
Aggregations