use of org.apache.thrift.transport.TTransport 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;
}
use of org.apache.thrift.transport.TTransport 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.TTransport 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.TTransport in project eiger by wlloyd.
the class CustomTThreadPoolServer method serve.
public void serve() {
try {
serverTransport_.listen();
} catch (TTransportException ttx) {
LOGGER.error("Error occurred during listening.", ttx);
return;
}
stopped_ = false;
while (!stopped_) {
// block until we are under max clients
while (activeClients.get() >= args.maxWorkerThreads) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new AssertionError(e);
}
}
try {
TTransport client = serverTransport_.accept();
activeClients.incrementAndGet();
WorkerProcess wp = new WorkerProcess(client);
executorService_.execute(wp);
} catch (TTransportException ttx) {
if (// thrift sucks
ttx.getCause() instanceof SocketTimeoutException)
continue;
if (!stopped_) {
LOGGER.warn("Transport error occurred during acceptance of message.", ttx);
}
}
if (activeClients.get() >= args.maxWorkerThreads)
LOGGER.warn("Maximum number of clients " + args.maxWorkerThreads + " reached");
}
executorService_.shutdown();
// Thrift's default shutdown waits for the WorkerProcess threads to complete. We do not,
// because doing that allows a client to hold our shutdown "hostage" by simply not sending
// another message after stop is called (since process will block indefinitely trying to read
// the next meessage header).
//
// The "right" fix would be to update thrift to set a socket timeout on client connections
// (and tolerate unintentional timeouts until stopped_ is set). But this requires deep
// changes to the code generator, so simply setting these threads to daemon (in our custom
// CleaningThreadPool) and ignoring them after shutdown is good enough.
//
// Remember, our goal on shutdown is not necessarily that each client request we receive
// gets answered first [to do that, you should redirect clients to a different coordinator
// first], but rather (1) to make sure that for each update we ack as successful, we generate
// hints for any non-responsive replicas, and (2) to make sure that we quickly stop
// accepting client connections so shutdown can continue. Not waiting for the WorkerProcess
// threads here accomplishes (2); MessagingService's shutdown method takes care of (1).
//
// See CASSANDRA-3335 and CASSANDRA-3727.
}
use of org.apache.thrift.transport.TTransport 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