joelpm / bidithrift Goto Github PK
View Code? Open in Web Editor NEWAn example of how to use Thrift for bi-directional async RPC
Home Page: http://www.joelpm.com/2009/04/03/thrift-bidirectional-async-rpc.html
An example of how to use Thrift for bi-directional async RPC
Home Page: http://www.joelpm.com/2009/04/03/thrift-bidirectional-async-rpc.html
java -jar Server/target/BidiMessages.Server-0.9-jar-with-dependencies.jar 10101 ✹ ✭
2012-10-11 12:29:55,769 INFO main com.joelpm.bidiMessages.server.Server:48 - Server started
2012-10-11 12:30:28,823 INFO pool-2-thread-1 com.joelpm.bidiMessages.server.MessageDistributor:36 - Added client at 127.0.0.1
2012-10-11 12:30:28,841 INFO pool-2-thread-1 com.joelpm.bidiMessages.server.MessageDistributor:66 - Adding message to queue:
Message(clientName:client1, message:Hello there!)
12:30:28.854 [pool-2-thread-1] ERROR o.a.thrift.server.TThreadPoolServer - Error occurred during processing of message.
java.lang.NullPointerException: null
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:34) ~[BidiMessages.Server-0.9-jar-with-dependencies.jar:na]
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:34) ~[BidiMessages.Server-0.9-jar-with-dependencies.jar:na]
at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:176) ~[BidiMessages.Server-0.9-jar-with-dependencies.jar:na]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_29]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_29]
at java.lang.Thread.run(Thread.java:680) [na:1.6.0_29]
2012-10-11 12:30:35,832 INFO pool-2-thread-2 com.joelpm.bidiMessages.server.MessageDistributor:36 - Added client at 127.0.0.1
2012-10-11 12:30:35,834 INFO pool-2-thread-2 com.joelpm.bidiMessages.server.MessageDistributor:66 - Adding message to queue:
Message(clientName:client1, message:Message 2)
2012-10-11 12:30:35,834 INFO Thread-2 com.joelpm.bidiMessages.server.MessageDistributor:53 - Removing 127.0.0.1 from client list.
12:30:35.835 [pool-2-thread-2] ERROR o.a.thrift.server.TThreadPoolServer - Error occurred during processing of message.
java.lang.NullPointerException: null
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:34) ~[BidiMessages.Server-0.9-jar-with-dependencies.jar:na]
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:34) ~[BidiMessages.Server-0.9-jar-with-dependencies.jar:na]
at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:176) ~[BidiMessages.Server-0.9-jar-with-dependencies.jar:na]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_29]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_29]
at java.lang.Thread.run(Thread.java:680) [na:1.6.0_29]
java -jar Client/target/BidiMessages.Client-0.9-jar-with-dependencies.jar client1 localhost 10101 ✹ ✭
2012-10-11 12:30:28,807 INFO Thread-3 com.joelpm.bidiMessages.client.ConnectionRequiredRunnable:42 - Message Sender waiting for connection to be established.
2012-10-11 12:30:28,807 INFO Thread-4 com.joelpm.bidiMessages.client.ConnectionRequiredRunnable:42 - Message Receiver waiting for connection to be established.
2012-10-11 12:30:28,814 INFO Thread-3 com.joelpm.bidiMessages.client.ConnectionRequiredRunnable:48 - Message Sender notified of connection, resuming execution
2012-10-11 12:30:28,814 INFO Thread-4 com.joelpm.bidiMessages.client.ConnectionRequiredRunnable:48 - Message Receiver notified of connection, resuming execution
Got msg: Message(clientName:client1, message:Hello there!)
Exception in thread "Thread-4" java.lang.NullPointerException
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:34)
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:34)
at com.joelpm.bidiMessages.client.MessageReceiver.run(MessageReceiver.java:31)
at java.lang.Thread.run(Thread.java:680)
2012-10-11 12:30:30,827 INFO Thread-3 com.joelpm.bidiMessages.client.ConnectionRequiredRunnable:30 - Message Sender detected a disconnect from the server.
2012-10-11 12:30:30,828 INFO Thread-3 com.joelpm.bidiMessages.client.ConnectionRequiredRunnable:42 - Message Sender waiting for connection to be established.
2012-10-11 12:30:35,831 INFO Thread-3 com.joelpm.bidiMessages.client.ConnectionRequiredRunnable:48 - Message Sender notified of connection, resuming execution
2012-10-11 12:30:37,836 INFO Thread-3 com.joelpm.bidiMessages.client.ConnectionRequiredRunnable:30 - Message Sender detected a disconnect from the server.
2012-10-11 12:30:37,838 INFO Thread-3 com.joelpm.bidiMessages.client.ConnectionRequiredRunnable:42 - Message Sender waiting for connection to be established.
Take a look at MasseGuillaume/BidirectionalThriftScala
I ported your example in Scala.
Glad you shared this piece of code !
I am unable to get maven to compile the project. Getting the following error on console:
Failed to execute goal on project BidiMessages.Common: Could not resolve dependencies for project com.joelpm:BidiMessages.Common:jar:0.9: Could not find artifact org.apache:thrift:jar:1.0 in Central (http://repo1.maven.org/maven2)
Please advise.
EDIT:
Looks like thrift API and versioning system have both changed since this was written.
Looking at the new API, it seems like doing bidirectional transport might not be straightforward since TServerTransport does not provide the TSocket interface. Am I right?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.