This part of the configuration process deals with the selection of functions to be used in the running system. The selection is made from a set of functions with the same interface but different implementations. This part of the configuration process corresponds to the part of the venerable C Language development cycle where the system designer specifies the run-time library that will be used by the linker to satisfy function references in the C program. As the Java language does not include a separate linker, a different mechanism is needed. We use a mechanism using an exemplar of a class. Consider the following fragments of the code. The symbol pms is an object that implements the class PMessageSystem. With it, we can send a message:
// create a message and then send it with this simple statement:
pms.send(message);
Obviously, this mechanism is concise and it also enjoys a high run-time efficiency. Before code can send a message it needs to create the exemplar. Here is a fragment of the code in which such an exemplar is created for use in a MessageAgent object:
public class MessageAgent implements Runnable {
...
// keep an exemplar of a PMessageSystem
public PmessageSystem pms;
...
public MessageAgent(Profile p, String me) throws MessageSystemException, ConfigurationError {
...
// get the exemplar from the Profile p
this.pms = p.messageSystem.getPmessageSystem(me);
...
Notice in the above, the code obtains an object from a call to a
member of another object, the Profile object. The profile has
a number of members that define abstractly the choices that make up
the configuration of adapters. Here, for example, are the lines in
class Profile that define the choice for a message system:
/** Configure Communication:
* 1. The desired message delivery system
*
*/
public PmessageSystem messageSystem;
The actual choice of a mechanism is defined by the constructor of
the Profile object. The Profile is abstract so we
need a subclass for each application where the actual constructor is
written. Here is an example of the code in the subclass
ProfileDemo0 where the message system is selected:
/** Configure Communication:
* 1. The desired message delivery system
*
*/
messageSystem = new SimpleMessageSystem(entityName);
In this case, we have selected the SimpleMessageSystem for test and demonstration purposes and the running demonstration code uses the actual functions in the SimpleMessageSystem.
In summary then, all of the configuration choices are coded in a
definition of a subclass of class Profile, illustrated here
by subclass ProfileDemo0. All that remains is to select the
whole configuration package in the application program. For example,
here is how the configuration is set for the BAN part of Demo0 in the
module DemoZero.java:
// create the Blind Agent Negotiator, BAN
Profile pBAN = new ProfileDemo0("BAN", dirPath);
aBAN = new BAN(pBAN, 300, 350);