[obsolete] Fast Messenger provides blocking calls through FutureReply
Fast Messenger provides FutureReply a mechanism similar to the Future in Java. Sequential OO programs may keep the same program flow while enjoying high concurrency out of asynchronous messaging. When you obtain an instance of FutureReply by sending out a message, your code will continue without blocking. You can perform any work before you decide to check whether a reply is ready. Even the checking offers you two options, you can check, leave (non-blocking) and come back later, or you can wait (blocking) until a reply is ready.
At the core of Fast Messenger, active objects only exchange messages asynchronously. This gives other OO programs headaches when they try to make use of the framework. A recent example is the MessengerFormula class if you still remember the Fibonacci program in one of my previous posts. The situation of MessengerFormula can be illustrated by the following figure.
Figure 1: Without FutureReply
On the left side, there is an OO program. It sends out three messages and expecting three results respectively, then return its own result to its caller based on the three results. First, it has to claim being a receiver so that it may receive results from workers. This separates businessMethod() and onMessage(). Now they have to exchange data using class variables. Second, the onMessage() has to identify the original message for a received result. And last, the program has to handle multithreading. The businessMethod() is called by a caller’s thread and it will wait for results. The onMessage() is called by a Fast Messenger thread.
To be honest, these are trivial things when you are writing highly concurrent programs. But they are annoying. Now Fast Messenger offers a better tool FutureReply for a happier marriage of regular objects and active objects. The following figure shows how a FutureReply is going to ease your pain. It explains itself very well.
Figure 2: With FutureReply
A new BlockingNode class is introduced to the FM framework. It provides an instance of FutureReply when you sends out a message. I also add a new implementation in the com.fastmessenger.example.fibonacci.blocking package to the Fibonacci example. BlockingMain is the main class and BlockingFormula is the key class that uses this feature.