Note that the Communication Block must be initialized through the init method of the ComManager class. This init method invokes the corresponding methods of the classes implementing the communication protocols, currently ComPointTCP, ComPointHTTP and ComPointMail. The invocation of the init method of ComPointMail will result in an actual initialization, only if a ComPointMailConfig.txt is present. Otherwise, the mail protocol may not be used. The ComPointMailConfig.txt contains two values: a receiver port which is used by the ComPointMailReceiver to forward the mime-decoded messages from the mail handler to the ComPointMail; and a return mail address to which responses may be sent.
The initiator is the module which sends the first message and the responder is the module receiving it. Here is a sample code for the initiator side:
// Create the address of the responder. ComPointAddress address = new ComPointAddress(protocol, host, port, path); // Open an initiator ComPoint. ComPoint comPoint = ComManager.comPoint(ComPointConstants.COMPOINT_INITIATOR, address); // Send a message. Message message = Message(...); comPoint.write(message); // Receive a response. Response response = (Response)comPoint.read(); // Exchange of more messages and responses. ... ... // Close the initiator ComPoint. comPoint.close();
and here is the corresponding code for the responder side:
// Create the local address. ComPointAddress address = new ComPointAddress(protocol, port); // Open the server ComPoint. serverComPoint = ComManager.comPoint(COMPOINT_SERVER, address); // Accept the connection from the initiator, creating the responder ComPoint. ComPoint comPoint = serverComPoint.accept(); // Receive the message. Message message = (Message)comPoint.read(); // Send the response. Response response = new Response(...); comPoint.write(response); // Exchange of more messages and responses. ... ... // Close the responder ComPoint. comPoint.close(); // Eventually close the server ComPoint. serverComPoint.close();
The only sequence constraint between the initiator and responder code executions is that the server ComPoint must have been opened before the initiator ComPoint. Message and Response are user defined classes implementing Streamable; refer to semper.util.serial.
The implementation of the ComPoint on the mail protocol requires a receiver port. Currently, this port is defined to be 11432. When the initialization of the communication block is modified to use the preference manager, this port will be specified by the configuration file.
// Create the address of the responder. ComPointAddress address = new ComPointAddress(protocol, host, port, path); // Open an initiator ComPoint and initiate a channel. ComPoint comPoint = Channel.openInitiatorChannel(address, options, correlator); // Send a message. String message = new Message(...); comPoint.write(message); // Receive a response. String response = (Response)comPoint.read(); // Exchange of more messages and responses. ... ... // Close the ComPoint and channel. comPoint.close();and here is the corresponding code for the responder:
// Create the local address. ComPointAddress address = new ComPointAddress(protocol, port); // Start a service-point thread. ChannelServicePointThread servicePoint = Channel.startServicePointThread(address); // Accept a channel with a specific correlator and open a responder ComPoint. ComPoint comPoint = servicePoint.openResponderChannel(options, correlator); // Receive the message. String message = (Message)comPoint.read(); // Send the response. String response = new Response(...); comPoint.write(response); // Exchange of more messages and responses. ... ... // Close the responder ComPoint. comPoint.close(); // Eventually stop the service-point thread. servicePoint.stop();
The only sequence constraint between the initiator and responder code executions is that the service-point thread must have been started before the initiator opens the channel.
The following classes implement the ComPoint API:
The following classes implement the Channel API: