Immediate program switching for JMP and JBP applications
The IMS Java™ dependent region resource adapter supports immediate program switching in JMP and JBP applications. An immediate program switch passes the conversation directly to another conversational program that is specified by an alternate PCB.
When an application makes an immediate program switch, the first
MessageQueue.insert
call sends the SPA to the other conversational program, but
subsequent MessageQueue.insert
calls will send messages to the new program. The
program does not return or respond to the original terminal.
The
setAlternatePCBName method of the
com.ibm.ims.dli.tm.MessageDestinationSpec class sets the name of the alternate
PCB for the program switch. The setAlternatePCBName method issues the DL/I
CHNG
call.
To make an immediate program switch in a JMP or JBP application:
Procedure
- Call the MessageDestinationSpec.setAlternatePCBName method to set the name of the alternate PCB.
-
Call the
MessageQueue.insert
method to send the message to the alternate PCB.
Code sample of immediate program switching
The following code sample demonstrates how immediate program switching is performed in a JMP application.
package sample.jmp;
import com.ibm.ims.dli.tm.Application;
import com.ibm.ims.dli.tm.ApplicationFactory;
import com.ibm.ims.dli.tm.IOMessage;
import com.ibm.ims.dli.tm.MessageDestinationSpec;
import com.ibm.ims.dli.tm.MessageQueue;
import com.ibm.ims.dli.tm.Transaction;
public class SampleJMPImmediatePgmSwitch {
private static IOMessage outputMessage = null;
private static MessageQueue msgQueue = null;
private static Application app = null;
private static IOMessage inputMessage = null;
public static void main(String[] args) {
try {
app = (Application) ApplicationFactory.createApplication();
msgQueue = (MessageQueue) app.getMessageQueue();
inputMessage
= app.getIOMessage("class://sample.jmp.InMessage");
outputMessage
= app.getIOMessage("class://sample.jmp.OutMessage");
//Define Message Destinations Specs
MessageDestinationSpec mds2
= new MessageDestinationSpec();
mds2.setAlternatePCBName("TPPCB1");
mds2.setDestination("JAVTRANJ");
String in = new String("");
while (msgQueue.getUnique(inputMessage)){
in = inputMessage.getString("Message").trim();
if(in.equalsIgnoreCase("ImmediatePGMSwitch1")){
outputMessage.setString("Message",
"Running ImmediatePGMSwitch1 Call");
msgQueue.insert(outputMessage,
MessageQueue.DEFAULT_DESTINATION);
// Insert Message to JAVTRANJ TPPCB1: DLIWithCommit
outputMessage.setString("Message",
"Insert Message to JAVTRANJ TPPCB1");
msgQueue.insert(outputMessage,
MessageQueue.DEFAULT_DESTINATION);
outputMessage.setString("Message", "DLIWithCommit");
outputMessage.setTransactionName("JAVTRANJ");
// Insert message to JAVTRANJ
msgQueue.insert(outputMessage, mds2);
// Commit transaction
Transaction tran = app.getTransaction();
tran.commit();
} else {
outputMessage.setString("Message",
"Invalid input - valid input is 'ImmediatePGMSwitch1'");
msgQueue.insert(outputMessage,
MessageQueue.DEFAULT_DESTINATION);
Transaction tran = app.getTransaction();
tran.commit();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
To perform immediate program switching in a JBP application, the steps are similar to a JMP application. In the main module, setup a MessageDestinationSpec instance then issue an insert call to another transaction. For example:
MessageDestinationSpec mds2 = new MessageDestinationSpec();
mds2.setAlternatePCBName("TPPCB1");
mds2.setDestination("JAVTRANJ");
...
outputMessage.setString("Message", "Some Message");
outputMessage.setTransactionName("JAVTRANJ");
msgQueue.insert(outputMessage, mds2);