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