Home:ALL Converter>Asynchronous Thrift Java Client over UNIX Domain Socket

Asynchronous Thrift Java Client over UNIX Domain Socket

Ask Time:2015-08-05T20:51:06         Author:Torfinn

Json Formatter

I have an application consisting of a Java Thrift Asynchronous client communicating with a Python/Twisted Thrift Asynchronous server over TCP using the loopback interface (localhost).

I want to use a UNIX domain socket instead of a TCP socket for increased throughput, but I cannot find a suitable Asynchronous (Non-blocking) UNIX Domain Socket implementation for Java to use with Thrift.

I had this Python/Twisted TCP Thrift server:

handler = ThriftServiceHandler(am)
processor = ThriftServiceHandler.Processor(handler)
pfactory = TBinaryProtocol.TBinaryProtocolFactory()

reactor.listenTCP(PORT, TTwisted.ThriftServerFactory(processor, pfactory), interface="127.0.0.1")

And I managed to create an Asynchronous UNIX Domain Socket Thrift server with:

handler = ThriftServiceHandler(am)
processor = ThriftServiceHandler.Processor(handler)
pfactory = TBinaryProtocol.TBinaryProtocolFactory()

reactor.listenUNIX("thrift.sock", TTwisted.ThriftServerFactory(processor, pfactory))

Currently I have this Java client:

clientManager = new TAsyncClientManager();
factory = new TBinaryProtocol.Factory();
socket = new TNonblockingSocket("127.0.0.1", thriftConstants.PORT);
client = new ThriftService.AsyncClient(this.factory, this.clientManager, this.socket);

But I am missing how to do the Java Client implementation. I looked at using https://github.com/jnr/jnr-unixsocket and https://github.com/kohlschutter/junixsocket, but I couldn't get them to work with Thrift's Java AsyncClient. Any help would be appreciated.

I am using the latest version of Thrift (0.9.2).

Author:Torfinn,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31833073/asynchronous-thrift-java-client-over-unix-domain-socket
yy