use of org.apache.thrift.transport.TTransport in project brisk by riptano.
the class CassandraStorage method createConnection.
private 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 simba-os by cegeka.
the class ThriftServlet method doService.
@Override
protected void doService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
TTransport inTransport;
TTransport outTransport;
try {
response.setContentType("application/x-thrift");
InputStream in = request.getInputStream();
OutputStream out = response.getOutputStream();
TTransport transport = new TIOStreamTransport(in, out);
inTransport = transport;
outTransport = transport;
TProtocol inProtocol = protocolFactory.getProtocol(inTransport);
TProtocol outProtocol = protocolFactory.getProtocol(outTransport);
getProcessor(getRequestedServiceName(request)).process(inProtocol, outProtocol);
out.flush();
} catch (TException te) {
throw new ServletException(te);
}
}
use of org.apache.thrift.transport.TTransport in project cogcomp-nlp by CogComp.
the class CuratorClient method addRecordViewFromCurator.
/**
* Does the network call to the Curator and fetches a record that has a particular view.
*
* @param text The raw text (this will be used if {@link #respectTokenization} is false.
* @param sentences The list of tokenized sentences (will be {@code null} if
* {@link #respectTokenization} is true.
* @param viewName The view to get (according to the Curator lingo.)
* @return A {@link edu.illinois.cs.cogcomp.thrift.curator.Record} with the requested view
*/
private Record addRecordViewFromCurator(String text, List<String> sentences, String viewName) throws ServiceUnavailableException, AnnotationFailedException, TException, SocketException {
viewName = convertCuratorViewName(viewName);
TTransport transport = new TSocket(this.curatorHost, this.curatorPort);
logger.debug("Calling curator on host '" + curatorHost + "', port '" + curatorPort + "' for view '" + viewName + "'...");
try {
((TSocket) transport).getSocket().setReuseAddress(true);
} catch (SocketException e) {
logger.error("Unable to setReuseAddress!", e);
throw e;
}
transport = new TFramedTransport(transport);
TProtocol protocol = new TBinaryProtocol(transport);
transport.open();
Curator.Client client = new Curator.Client(protocol);
Record newRecord;
if (respectTokenization) {
newRecord = client.wsprovide(viewName, sentences, forceUpdate);
} else {
newRecord = client.provide(viewName, text, forceUpdate);
}
transport.close();
return newRecord;
}
use of org.apache.thrift.transport.TTransport in project dubbo by alibaba.
the class ThriftCodecTest method testEncodeRequest.
@Test
public void testEncodeRequest() throws Exception {
Request request = createRequest();
ChannelBuffer output = ChannelBuffers.dynamicBuffer(1024);
codec.encode(channel, output, request);
byte[] bytes = new byte[output.readableBytes()];
output.readBytes(bytes);
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
TTransport transport = new TIOStreamTransport(bis);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
// frame
byte[] length = new byte[4];
transport.read(length, 0, 4);
if (bis.markSupported()) {
bis.mark(0);
}
// magic
Assert.assertEquals(ThriftCodec.MAGIC, protocol.readI16());
// message length
int messageLength = protocol.readI32();
Assert.assertEquals(messageLength + 4, bytes.length);
// header length
short headerLength = protocol.readI16();
// version
Assert.assertEquals(ThriftCodec.VERSION, protocol.readByte());
// service name
Assert.assertEquals(Demo.Iface.class.getName(), protocol.readString());
// dubbo request id
Assert.assertEquals(request.getId(), protocol.readI64());
// test message header length
if (bis.markSupported()) {
bis.reset();
bis.skip(headerLength);
}
TMessage message = protocol.readMessageBegin();
Demo.echoString_args args = new Demo.echoString_args();
args.read(protocol);
protocol.readMessageEnd();
Assert.assertEquals("echoString", message.name);
Assert.assertEquals(TMessageType.CALL, message.type);
Assert.assertEquals("Hello, World!", args.getArg());
}
use of org.apache.thrift.transport.TTransport in project brisk by riptano.
the class ThriftUtils method createNamenodeClient.
/**
* Creates a Thrift name node client.
*
* @param conf the HDFS instance
* @return a Thrift name node client.
*/
public static Namenode.Client createNamenodeClient(Configuration conf) throws Exception {
String s = conf.get(NamenodePlugin.THRIFT_ADDRESS_PROPERTY, NamenodePlugin.DEFAULT_THRIFT_ADDRESS);
// TODO(todd) use fs.default.name here if set to 0.0.0.0 - but share this with the code in
// SecondaryNameNode that does the same
InetSocketAddress addr = NetUtils.createSocketAddr(s);
// in the thrift config.
if (addr.getAddress().isAnyLocalAddress()) {
InetSocketAddress nnAddr = NameNode.getAddress(conf);
addr = new InetSocketAddress(nnAddr.getAddress(), addr.getPort());
}
TTransport t = new TSocket(addr.getHostName(), addr.getPort());
if (UserGroupInformation.isSecurityEnabled()) {
t = new HadoopThriftAuthBridge.Client().createClientTransport(conf.get(DFSConfigKeys.DFS_NAMENODE_USER_NAME_KEY), addr.getHostName(), "KERBEROS", t);
}
t.open();
TProtocol p = new TBinaryProtocol(t);
return new Namenode.Client(p);
}
Aggregations