use of org.apache.thrift.protocol.TProtocol 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.protocol.TProtocol 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.protocol.TProtocol 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;
}
use of org.apache.thrift.protocol.TProtocol in project buck by facebook.
the class ThriftUtil method deserialize.
public static void deserialize(ThriftProtocol protocol, InputStream source, TBase<?, ?> dest) throws ThriftException {
try (TIOStreamTransport responseTransport = new TIOStreamTransport(source)) {
TProtocol responseProtocol = newProtocolInstance(protocol, responseTransport);
dest.read(responseProtocol);
} catch (TException e) {
throw new ThriftException(e);
}
}
use of org.apache.thrift.protocol.TProtocol in project dubbo by alibaba.
the class MultiServiceProcessor method process.
public boolean process(TProtocol in, TProtocol out) throws TException {
short magic = in.readI16();
if (magic != ThriftCodec.MAGIC) {
logger.error(new StringBuilder(24).append("Unsupported magic ").append(magic).toString());
return false;
}
in.readI32();
in.readI16();
byte version = in.readByte();
String serviceName = in.readString();
long id = in.readI64();
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
TIOStreamTransport transport = new TIOStreamTransport(bos);
TProtocol protocol = protocolFactory.getProtocol(transport);
TProcessor processor = processorMap.get(serviceName);
if (processor == null) {
logger.error(new StringBuilder(32).append("Could not find processor for service ").append(serviceName).toString());
return false;
}
// todo if exception
boolean result = processor.process(in, protocol);
ByteArrayOutputStream header = new ByteArrayOutputStream(512);
TIOStreamTransport headerTransport = new TIOStreamTransport(header);
TProtocol headerProtocol = protocolFactory.getProtocol(headerTransport);
headerProtocol.writeI16(magic);
headerProtocol.writeI32(Integer.MAX_VALUE);
headerProtocol.writeI16(Short.MAX_VALUE);
headerProtocol.writeByte(version);
headerProtocol.writeString(serviceName);
headerProtocol.writeI64(id);
headerProtocol.getTransport().flush();
out.writeI16(magic);
out.writeI32(bos.size() + header.size());
out.writeI16((short) (0xffff & header.size()));
out.writeByte(version);
out.writeString(serviceName);
out.writeI64(id);
out.getTransport().write(bos.toByteArray());
out.getTransport().flush();
return result;
}
Aggregations