Posted by rexyoung
on July 26, 2013 at 1:20 PM PDT
In previous tutorials, we have introduced that an active object behaves like an human individual who takes jobs and executes them one at a time from his private FIFO inbox. It means for a user program that the most straightforward way to invoke a service on an active object would be placing a request in the inbox of the target active object. The sendMessage () is designed to do exactly that for user programs.
100 messenger.sendMessage ("calculator:multiply", n1, n2);
Active objects are virtual objects living inside messenger objects. A user program can not directly interact with them. The first thing is to obtain a messenger object that contains the active object the user program wants to invoke. Then the user program can use sendMessage () method as line 100 illustrates.
The first parameter is a string containing names of target active object and service. Note that service and port are interchangeable terms in FMP. In general, a messenger object may contain a number of active objects that effectively form a namespace. That is why a user program provides names to the messenger object as a first thing. The messenger object uses the name to identify the target active object.
The goal of sendMessage () method is to place a request in the inbox of the target active object. Note that request, message, job and work order are interchangeable terms in FMP. FMP does not define a fixed format for messages. A FMP implementation may choose whatever format that is native to the underlying programming language. Our FMP Java reference implementation decides to represent a message with an array of objects. Of course, a message could be empty.
After a user program executes the sendMessage () as shown at line 100, the request would be placed in the inbox of the active object. The user program will continue without blocking. The active object could start immediately to process the request if it is the only request. Or the request would have to wait for its turn if the active object is processing a current message.
In the end, FMP is able to keep its promises on all languages (so far) that active objects will be asynchronous appearing outside and sequential inside.