use of org.apache.thrift.transport.TSocket in project hbase by apache.
the class HttpDoAsClient method run.
private void run() throws Exception {
TTransport transport = new TSocket(host, port);
transport.open();
String url = "http://" + host + ":" + port;
THttpClient httpClient = new THttpClient(url);
httpClient.open();
TProtocol protocol = new TBinaryProtocol(httpClient);
Hbase.Client client = new Hbase.Client(protocol);
byte[] t = bytes("demo_table");
//
// Scan all tables, look for the demo table and delete it.
//
System.out.println("scanning tables...");
for (ByteBuffer name : refresh(client, httpClient).getTableNames()) {
System.out.println(" found: " + utf8(name.array()));
if (utf8(name.array()).equals(utf8(t))) {
if (refresh(client, httpClient).isTableEnabled(name)) {
System.out.println(" disabling table: " + utf8(name.array()));
refresh(client, httpClient).disableTable(name);
}
System.out.println(" deleting table: " + utf8(name.array()));
refresh(client, httpClient).deleteTable(name);
}
}
//
// Create the demo table with two column families, entry: and unused:
//
ArrayList<ColumnDescriptor> columns = new ArrayList<>(2);
ColumnDescriptor col;
col = new ColumnDescriptor();
col.name = ByteBuffer.wrap(bytes("entry:"));
col.timeToLive = Integer.MAX_VALUE;
col.maxVersions = 10;
columns.add(col);
col = new ColumnDescriptor();
col.name = ByteBuffer.wrap(bytes("unused:"));
col.timeToLive = Integer.MAX_VALUE;
columns.add(col);
System.out.println("creating table: " + utf8(t));
try {
refresh(client, httpClient).createTable(ByteBuffer.wrap(t), columns);
} catch (AlreadyExists ae) {
System.out.println("WARN: " + ae.message);
}
System.out.println("column families in " + utf8(t) + ": ");
Map<ByteBuffer, ColumnDescriptor> columnMap = refresh(client, httpClient).getColumnDescriptors(ByteBuffer.wrap(t));
for (ColumnDescriptor col2 : columnMap.values()) {
System.out.println(" column: " + utf8(col2.name.array()) + ", maxVer: " + Integer.toString(col2.maxVersions));
}
transport.close();
httpClient.close();
}
use of org.apache.thrift.transport.TSocket in project hive by apache.
the class HiveAuthUtils method getSSLSocket.
public static TTransport getSSLSocket(String host, int port, int loginTimeout, String trustStorePath, String trustStorePassWord) throws TTransportException {
TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters();
params.setTrustStore(trustStorePath, trustStorePassWord);
params.requireClientAuth(true);
// The underlying SSLSocket object is bound to host:port with the given SO_TIMEOUT and
// SSLContext created with the given params
TSocket tSSLSocket = TSSLTransportFactory.getClientSocket(host, port, loginTimeout, params);
return getSSLSocketWithHttps(tSSLSocket);
}
use of org.apache.thrift.transport.TSocket in project zeppelin by apache.
the class ClientFactory method create.
@Override
public Client create() throws Exception {
TSocket transport = new TSocket(host, port);
try {
transport.open();
} catch (TTransportException e) {
throw new InterpreterException(e);
}
TProtocol protocol = new TBinaryProtocol(transport);
Client client = new RemoteInterpreterService.Client(protocol);
synchronized (clientSocketMap) {
clientSocketMap.put(client, transport);
}
return client;
}
use of org.apache.thrift.transport.TSocket in project lucida by claritylab.
the class QAClient method main.
public static void main(String[] args) {
// Collect the port number.
int port = 8083;
if (args.length >= 1) {
port = Integer.parseInt(args[0]);
}
// User.
String LUCID = "Clinc";
QuerySpec create_spec = new QuerySpec();
// Knowledge.
final QueryInput knowledge_text = createQueryInput("text", "Clinc is created by Jason and Lingjia.", "1234567");
final QueryInput knowledge_url = createQueryInput("url", "https://en.wikipedia.org/wiki/Apple_Inc.", "abcdefg");
final QuerySpec knowledge = createQuerySpec("knowledge", new ArrayList<QueryInput>() {
{
add(knowledge_text);
add(knowledge_url);
}
});
// Unlearn.
final QueryInput knowledge_unlearn_input = createQueryInput("unlearn", "", "abcdefg");
final QuerySpec knowledge_unlearn_spec = createQuerySpec("unlearn knowledge", new ArrayList<QueryInput>() {
{
add(knowledge_unlearn_input);
}
});
// Query.
final QueryInput query_input = createQueryInput("text", "Who created Clinc?", "");
final QuerySpec query = createQuerySpec("query", new ArrayList<QueryInput>() {
{
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 server.
transport.open();
System.out.println("///// Connecting to OpenEphyra at port " + port + " ... /////");
// Learn and ask.
client.create(LUCID, create_spec);
client.learn(LUCID, knowledge);
System.out.println("///// Query input: /////");
System.out.println(query_input.data.get(0));
String answer = client.infer(LUCID, query);
// Print the answer.
System.out.println("///// Answer: /////");
System.out.println(answer);
// Unlearn and ask again.
client.learn(LUCID, knowledge_unlearn_spec);
System.out.println("///// Query input: /////");
System.out.println(query_input.data.get(0));
answer = client.infer(LUCID, query);
// Print the answer.
System.out.println("///// Answer: /////");
System.out.println(answer);
transport.close();
} catch (TException x) {
x.printStackTrace();
}
}
use of org.apache.thrift.transport.TSocket in project buck by facebook.
the class ThriftCoordinatorClient method start.
public ThriftCoordinatorClient start() throws IOException {
transport = new TFramedTransport(new TSocket(remoteHost, remotePort));
Stopwatch stopwatch = Stopwatch.createStarted();
while (true) {
try {
transport.open();
break;
} catch (TTransportException e) {
if (stopwatch.elapsed(TimeUnit.SECONDS) > MAX_CONNECT_TIMEOUT_SECONDS) {
throw new IOException(String.format("Failed to connect. Coordinator is still not healthy after [%d] seconds.", MAX_CONNECT_TIMEOUT_SECONDS));
}
LOG.debug("Coordinator server currently not available. Retrying in a bit...");
try {
Thread.sleep(TimeUnit.SECONDS.toMillis(RETRY_TIMEOUT_SECONDS));
} catch (InterruptedException innerException) {
throw new RuntimeException(innerException);
}
}
}
TProtocol protocol = new TBinaryProtocol(transport);
client = new CoordinatorService.Client(protocol);
return this;
}
Aggregations