use of org.apache.thrift.transport.TSocket in project whirr by apache.
the class CassandraServiceTest method waitForCassandra.
private void waitForCassandra() {
for (Instance instance : cluster.getInstances()) {
while (true) {
try {
TSocket socket = new TSocket(instance.getPublicAddress().getHostAddress(), CassandraService.CLIENT_PORT);
socket.open();
TBinaryProtocol protocol = new TBinaryProtocol(socket);
Cassandra.Client client = new Cassandra.Client(protocol);
client.describe_cluster_name();
socket.close();
break;
} catch (TException e) {
System.out.print(".");
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
break;
}
}
}
}
}
use of org.apache.thrift.transport.TSocket in project whirr by apache.
the class CassandraServiceTest method testInstances.
@Test
public void testInstances() throws Exception {
Set<String> endPoints = new HashSet<String>();
for (Instance instance : cluster.getInstances()) {
TSocket socket = new TSocket(instance.getPublicAddress().getHostAddress(), CassandraService.CLIENT_PORT);
socket.open();
TBinaryProtocol protocol = new TBinaryProtocol(socket);
Cassandra.Client client = new Cassandra.Client(protocol);
List<TokenRange> tr = client.describe_ring(KEYSPACE);
for (TokenRange tokenRange : tr) {
endPoints.addAll(tokenRange.endpoints);
}
socket.close();
}
for (Instance instance : cluster.getInstances()) {
String address = instance.getPrivateAddress().getHostAddress();
assertTrue(address + " not in cluster!", endPoints.remove(address));
}
assertTrue("Unknown node returned: " + endPoints.toString(), endPoints.isEmpty());
}
use of org.apache.thrift.transport.TSocket in project hbase by apache.
the class TBoundedThreadPoolServer method serve.
public void serve() {
try {
serverTransport_.listen();
} catch (TTransportException ttx) {
LOG.error("Error occurred during listening.", ttx);
return;
}
Runtime.getRuntime().addShutdownHook(new Thread(getClass().getSimpleName() + "-shutdown-hook") {
@Override
public void run() {
TBoundedThreadPoolServer.this.stop();
}
});
stopped = false;
while (!stopped && !Thread.interrupted()) {
TTransport client = null;
try {
client = serverTransport_.accept();
} catch (TTransportException ttx) {
if (!stopped) {
LOG.warn("Transport error when accepting message", ttx);
continue;
} else {
// The server has been stopped
break;
}
}
ClientConnnection command = new ClientConnnection(client);
try {
executorService.execute(command);
} catch (RejectedExecutionException rex) {
if (client.getClass() == TSocket.class) {
// We expect the client to be TSocket.
LOG.warn(QUEUE_FULL_MSG + " from " + ((TSocket) client).getSocket().getRemoteSocketAddress());
} else {
LOG.warn(QUEUE_FULL_MSG, rex);
}
client.close();
}
}
shutdownServer();
}
use of org.apache.thrift.transport.TSocket in project lucida by claritylab.
the class QADaemon method connectToCMD.
private static void connectToCMD() {
String LUCID = "QA";
QuerySpec spec = new QuerySpec();
spec.name = "" + 8083;
// Initialize thrift objects.
TTransport transport = new TSocket("localhost", 8080);
TProtocol protocol = new TBinaryProtocol(new TFramedTransport(transport));
LucidaService.Client client = new LucidaService.Client(protocol);
try {
transport.open();
System.out.println("Connecting to CMD at port " + 8080);
// Register itself to CMD.
client.create(LUCID, spec);
transport.close();
System.out.println("Successfully connected to CMD");
} catch (TException x) {
x.printStackTrace();
}
}
use of org.apache.thrift.transport.TSocket in project lucida by claritylab.
the class CalendarClient method main.
public static void main(String[] args) {
// Collect the port number.
int port = 8084;
if (args.length == 1) {
port = Integer.parseInt(args[0]);
} else {
System.out.println("Using default port for Calendar Client: " + port);
}
// Query.
String LUCID = "Clinc";
String query_input_data = "What is on my Google calendar for last week?";
QueryInput query_input = new QueryInput();
query_input.type = "query";
query_input.data = new ArrayList<String>();
query_input.data.add(query_input_data);
QuerySpec query_spec = new QuerySpec();
query_spec.content = new ArrayList<QueryInput>();
query_spec.content.add(query_input);
// Initialize thrift objects.
// TTransport transport = new TSocket("clarity08.eecs.umich.edu", port);
TTransport transport = new TSocket("localhost", port);
TProtocol protocol = new TBinaryProtocol(new TFramedTransport(transport));
LucidaService.Client client = new LucidaService.Client(protocol);
try {
// Talk to the Calendar server.
transport.open();
System.out.println(query_input_data);
System.out.println("///// Connecting to Calendar... /////");
String results = client.infer(LUCID, query_spec);
System.out.println("///// Result: /////");
System.out.println(results);
transport.close();
} catch (TException e) {
e.printStackTrace();
}
return;
}
Aggregations