Editing the Request PeopleCode
The PT_OPTCALL Application Engine program serves as a template. It is delivered with all the sections marked as inactive. You can edit the program to suit your needs, then mark the appropriate sections active before running it. You can also use the program as a guide to creating your own Application Engine program.
The program uses these steps to send request messages to perform the following tasks:
-
Load the optimization engine.
-
Wait for the optimization engine load to finish.
-
Run an optimization transaction against the loaded optimization engine.
-
Wait for the optimization transaction to finish running.
-
Set the trace level.
-
Get the trace level.
-
Shut down the optimization engine.
You can edit steps 1 and 3 to run an optimization transaction. You can also use the entire program as a template to create your own Application Engine program.
Loading an Optimization Engine
In step 1, enter the name of your analytic instance. In this example, the name of the analytic instance is FEMALE1.
If you have multiple domains, enter the local node name and the machine name and port number for your application server. In this case, the local node name is %LocalNode and the machine name and port number are foo111111:9000.
Local Message &MSG;
Local Message &response;
Component string &probid;
Component string &isSync;
Component string &procinst;
Local integer &nInst;
Local string &url;
Local Rowset &rs;
Local Row &row;
Local Record &rec;
Local string &stName;
Local integer &stVal;
&MSG = CreateMessage(OPERATION.OPT_CALL);
&rs = &MSG.GetRowset();
&row = &rs.GetRow(1);
&rec = &row.GetRecord(Record.PT_OPTPARMS);
&rec.PARMKEY.Value = "OPTCMD";
&rec.VALUE.Value = "CREATE";
&rs.InsertRow(1);
&rec = &rs.GetRow(2).PT_OPTPARMS;
&rec.PARMKEY.Value = "PROBINST";
&rec.VALUE.Value = "FEMALE1";
&probid = "FEMALE1";
&rs.InsertRow(2);
&rec = &rs.GetRow(3).PT_OPTPARMS;
&rec.PARMKEY.Value = "PROCINSTANCE";
&nInst = Record.PT_OPT_AET.PROCESS_INSTANCE.Value;
&rec.VALUE.Value = String(&nInst);
&procinst = String(&nInst);
&rs.InsertRow(3);
&rec = &rs.GetRow(4).PT_OPTPARMS;
&rec.PARMKEY.Value = "SYNCH";
&rec.VALUE.Value = "N";
&isSync = "N";
/* Specify the Application Server domain URL (foo111111:9000 in this example)
*/
&response = %IntBroker.SyncRequest(%LocalNode, "//foo111111:9000 e");
If &response.ResponseStatus = 0 Then
&stName = &response.GetRowset().GetRow(1).GetRecord(Record.PT_OPTPARMS).Get
Field(Field.PARMKEY).Value;
&stVal = Value(&response.GetRowset().GetRow(1).GetRecord(Record.PT_
OPTPARMS).GetField(Field.VALUE).Value);
If &stName = "STATUS" And
&stVal = %OptEng_Fail Then
/* Check detailed message here */
throw CreateException(148, 2, "Can not send to OptEngine");
End-If;
End-If;
Running An Optimization Transaction
In step 3, enter the name of your optimization transaction and its parameter name/value pairs. In this example, the transaction name is TEST_LONG_TRANS, the first parameter name/value pair is Delay_in_Secs and 30, and the second parameter name/value pair is Sleep0_Work1 and 0.
The parameter values are stored as strings. You may need to convert them in the OnRequest PeopleCode.
Local Message &MSG;
Local Message &response;
Local Rowset &rs, &respRS;
Local Row &row;
Local Record &rec, &msgRec;
Component string &probid;
Component string &procinst;
Component string &isSync;
Local string &url = "";
Local integer &parmCount, &msgSet, &msgNum;
&MSG = CreateMessage(OPERATION.OPT_CALL);
&rs = &MSG.GetRowset();
&row = &rs.GetRow(1);
&rec = &row.GetRecord(Record.PT_OPTPARMS);
&rec.PARMKEY.Value = "OPTCMD";
&rec.VALUE.Value = "RUN";
&rs.InsertRow(1);
&rec = &rs.GetRow(2).PT_OPTPARMS;
&rec.PARMKEY.Value = "PROBINST";
&rec.VALUE.Value = &probid;
&rs.InsertRow(2);
&rec = &rs.GetRow(3).PT_OPTPARMS;
&rec.PARMKEY.Value = "PROCINSTANCE";
&rec.VALUE.Value = &procinst;
&rs.InsertRow(3);
&rec = &rs.GetRow(4).PT_OPTPARMS;
&rec.PARMKEY.Value = "SYNCH";
&rec.VALUE.Value = &isSync;
&rs.InsertRow(4);
&rec = &rs.GetRow(5).PT_OPTPARMS;
&rec.PARMKEY.Value = "TRANSACTION";
&rec.VALUE.Value = "TEST_LONG_TRANS";
&rs.InsertRow(5);
&rec = &rs.GetRow(6).PT_OPTPARMS;
&rec.PARMKEY.Value = "Delay_in_Secs";
&rec.VALUE.Value = "30";
&rs.InsertRow(6);
&rec = &rs.GetRow(7).PT_OPTPARMS;
&rec.PARMKEY.Value = "Sleep0_Work1";
&rec.VALUE.Value = "0";
/* SyncRequest will carry a url */
SQLExec("select URL from PSOPTSTATUS where PROBINST=:1 AND URL NOT LIKE '%:0';",
&probid, &url);
If &url = "" Then
throw CreateException(148, 2, "Can not send to OptEngine");
End-If;
/* Specify the Application Server domain URL.
(This was specified in Step 1 in this example.)
*/
&response = %IntBroker.SyncRequest(%LocalNode, &url);
If &response.ResponseStatus = 0 Then
&stName = &response.GetRowset().GetRow(1).GetRecord(Record.PT_OPTPARMS).Get
Field(Field.PARMKEY).Value;
&stVal = Value(&response.GetRowset().GetRow(1).GetRecord(Record.PT_
OPTPARMS).GetField(Field.VALUE).Value);
If &stName = "STATUS" And
&stVal = %OptEng_Fail Then
throw CreateException(148, 2, "Can not send to OptEngine");
End-If;
/* Check Detailed msg here */
If &isSync = "Y" And
&stVal = %OptEng_Success Then
&respRS = &response.GetRowset();
&rowNum = &respRS.ActiveRowCount;
For &iloop = 1 To &rowNum
&msgRec = &respRS.GetRow(&iloop).GetRecord(Record.PT_OPTDETMSGS);
If (&msgRec.GetField(Field.MSGSET).Value <> 0) Then
&msgSet = Value(&msgRec.GetField(Field.MSGSET).Value);
&msgNum = Value(&msgRec.GetField(Field.MSGNUM).Value);
&parm1 = &msgRec.GetField(Field.MSGPARM1).Value;
&parm2 = &msgRec.GetField(Field.MSGPARM2).Value;
&parm3 = &msgRec.GetField(Field.MSGPARM3).Value;
&parm4 = &msgRec.GetField(Field.MSGPARM4).Value;
&parm5 = &msgRec.GetField(Field.MSGPARM5).Value;
&string = MsgGetText(&msgSet, &msgNum, "Message Not Found", &parm1,
&parm2, &parm3, &parm4, &parm5);
End-If;
End-For;
End-If;
End-If;