Consultor Eletrônico



Kbase 19473: APPSERVER - How CANCELLED Works
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   2/2/2000
In Version 9.1A and higher we provide the ability to invoke asynchronous requests against an AppServer.

One of the attributes available in the asynchronous world is the
CANCELLED attribute. This attribute should be checked within the requests event-procedure to determine whether the request was ever actually sent to the AppServer for execution. If this attribute is set to true then the request was cancelled without having been executed and none of the INPUT or INPUT-OUTPUT parameters to the event-procedure exist.

Also note that it is important to test for the STOP attribute being set to true in the event-procedure because the command which cancels active and pending requests (i.e. CANCEL-REQUESTS) will not set the CANCELLED attribute to true for a request that is physically executing on the AppServer. The physically executing program will instead have a 4GL "STOP" condition sent to it and it will cause the STOP attribute to be set to true in the event-procedure.

The following code gives an example of this attribute in action (the code that runs on the AppServer is listed first followed by the code that runs on the client).

This code will return message boxes with the following values:

Request Cancelled Attribute Stop Attribute
------- ------------------- --------------
1 FALSE TRUE
2 TRUE FALSE
3 TRUE FALSE
4 TRUE FALSE


/**
** Program Name: ServerTest03.p
** Description : Used To Test The CANCELLED Attribute
**/

PROCEDURE TheBigPause:
DEFINE INPUT PARAMETER iPause AS INTEGER NO-UNDO.
DEFINE OUTPUT PARAMETER cTime AS CHARACTER NO-UNDO.

PAUSE iPause NO-MESSAGE.

ASSIGN cTime = STRING(TIME,"HH:MM:SS").
END PROCEDURE.


/**
** Program Name: AsyncClientTest03.p
** Description : Used To Call The AppServer & Test The
** CANCELLED Attribute
**/

DEFINE VARIABLE hServer AS HANDLE NO-UNDO.
DEFINE VARIABLE hProc1 AS HANDLE NO-UNDO.
DEFINE VARIABLE hProc2 AS HANDLE NO-UNDO.
DEFINE VARIABLE hAsync AS HANDLE NO-UNDO.
DEFINE VARIABLE lRet AS LOGICAL NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.
DEFINE VARIABLE cData AS CHARACTER NO-UNDO.

CREATE SERVER hServer.

lRet = hServer:CONNECT("-AppService X -H Y -S 5162", "", "") NO-ERROR.

IF lRet = FALSE THEN
DO:
MESSAGE "Connection Failed" VIEW-AS ALERT-BOX.
RETURN.
END.

RUN ServerTest03.p PERSISTENT SET hProc1
ON hServer TRANSACTION DISTINCT.

RUN ServerTest03.p PERSISTENT SET hProc2
ON hServer TRANSACTION DISTINCT.

DO iLoop = 1 TO 2:
RUN TheBigPause IN hProc1 ASYNCHRONOUS SET hAsync
EVENT-PROCEDURE "CallCompleted" ((7 - iLoop), OUTPUT cData).
RUN TheBigPause IN hProc2 ASYNCHRONOUS SET hAsync
EVENT-PROCEDURE "CallCompleted" ((7 - iLoop), OUTPUT cData).
END.

hServer:CANCEL-REQUESTS().

WAIT-FOR END-ERROR OF THIS-PROCEDURE.

DELETE PROCEDURE hProc1.
DELETE PROCEDURE hProc2.

hServer:DISCONNECT().

DELETE OBJECT hServer.

PROCEDURE CallCompleted:
DEFINE INPUT PARAMETER cTime AS CHARACTER NO-UNDO.

IF SELF:CANCELLED = TRUE THEN
MESSAGE "Request Cancelled" VIEW-AS ALERT-BOX.
ELSE
IF SELF:STOP = TRUE THEN
MESSAGE "Request Stopped" VIEW-AS ALERT-BOX.
ELSE
MESSAGE "cTime = " + cTime SKIP
STRING(hProc1:ASYNC-REQUEST-COUNT) SKIP
STRING(hProc2:ASYNC-REQUEST-COUNT) SKIP
STRING(hServer:ASYNC-REQUEST-COUNT)
VIEW-AS ALERT-BOX.
END PROCEDURE.