JUMPCommand is base class that encapsulates any command that
is sent from the executive to an isolate (and vice-versa). The
JUMPCommand abstracts the contents of the data part (payload)
of the JUMPMessage . The following code samples shows sending
and receiving of JUMPCommand using the messaging
infrastructure.
Sending a JUMPCommand.
JUMPCommand command; // JUMPRequest or JUMPResponse
JUMPMessagingService thisProcess; // JUMPExecutive or JUMPIsolateProcess
JUMPMessageSender target; // JUMPIsolateProcessProxy or JUMPProcessProxy
JUMPCommand command = new JUMPRequest(<id>, args);
// create a message of the command type
JUMPOutgoingMessage message = command.toMessage(thisProcess);
// (a) synchronous send of a message
JUMPMessage responseMessage = target.sendMessage(message, 0L);
JUMPResponse response = JUMPResponse.fromMessage(responseMessage);
// (b) asynchronous send of a message
JUMPMessageDispatcher disp = thisProcess.getMessageDispatcher();
// Register a handler for a response to this message
Object token = disp.registerHandler(message, ResponseHandler.getInstance());
// send the message to the isolate
target.sendMessage(message);
Receving a JUMPResponse
public class ResponseHandler implements JUMPMessageHandler {
void handleMessage(JUMPMessage message) {
JUMPResponse response = JUMPResponse.fromMessage(message);
// "response" usage follows ...
// Unregister registration for this transaction.
disp.cancelRegistration(token);
}
}
Receiving a JUMPCommand and sending a response.
public class RequestHandler implements JUMPMessageHandler {
void handleMessage(JUMPMessage message) {
JUMPRequest request = JUMPRequest.fromMessage(message);
JUMPMessageResponseSender requestSender = message.getSender();
// process request
// ...
JUMPResponse response = new JUMPResponse(<responseId>);
// fill in response...
// ...
JUMPMessagingService myProcess; // JUMPExecutive or
JUMPIsolateProcess
// create a response message of the command type
JUMPOutgoingMessage responseMessage =
response.toMessage(myProcess);
// The response goes back to the sender
requestSender.sendResponseMessage(responseMessage);
}
}
|