Try OpenEdge Now
skip to main content
Application Migration and Development Guide
Application Development with PAS for OpenEdge : Programming the Progress Application Server for OpenEdge : Handling conditions and returning values : Handling the STOP condition : Raising a timed STOP
 
Raising a timed STOP
The STOP-AFTER phrase on DO, FOR, or REPEAT statement establishes a timer on the block. If the timer expires before execution of the block completes, the ABL session raises the STOP condition. At this point, normal STOP condition processing occurs and you can use the ON STOP phrase to handle the STOP.
The rules for executing synchronous remote procedure calls within a timed code block are essentially the same as those for local procedures. Remote procedures may be called within timed blocks or from blocks within timed blocks.
When a timed remote procedure call is executed on a PAS for OpenEdge instance, the time limit for the procedure is enforced in the client session. If the timeout is exceeded, the STOP condition is raised by the client. In this context, a STOP message is sent to the server session running the remote procedure after the specified time limit has exceeded, which is similar to what happens when an interactive user presses the STOP key.
The following examples illustrate making timed synchronous remote procedure calls on a PAS for OpenEdge instance:
/* clntNested3.p */
DEFINE VARIABLE clntTimeLimit AS INTEGER   NO-UNDO INITIAL 5.
DEFINE VARIABLE hSrv          AS HANDLE    NO-UNDO.
DEFINE VARIABLE cParm         AS CHARACTER NO-UNDO.

CREATE SERVER hSrv.
cParm = FILL("X", 10). /* 10 "X" characters will be sent to server */

hSrv:CONNECT("-URL http://localhost:3090/apsv").
DO STOP-AFTER clntTimeLimit ON STOP UNDO, LEAVE:
  RUN foo.
END.

PROCEDURE foo:
  DEFINE VARIABLE cnt AS INTEGER NO-UNDO.

  FOR EACH Customer NO-LOCK:
    cnt = cnt + 1.
  END.

  cParm = FILL("X", cnt).
  RUN srvrNested3.p ON SERVER hSrv (INPUT-OUTPUT cParm).
END PROCEDURE.
In this example, the client program (clntNested3.p) connects to a PAS for OpenEdge instance running on the local host, and runs the local procedure foo within a timed code block, specifying STOP-AFTER 5. The procedure foo counts the number of customer records, and then fills the character variable cParm with "X" characters. The remote procedure srvrNested3.p is then called. Because this remote procedure call is made from within the timed procedure foo, srvrNested3.p is implicitly run as a timed procedure; the time limit for this call is the time remaining for the timed block calling foo (5 seconds, less the time required to count the number of customer records). The client session begins timing this when the remote procedure call is made. If the call to srvrNested3.p does not return in the client session within the 5 second time limit, the client session will issue a STOP message to the server session running srvrNested3.p. When the PAS for OpenEdge instance receives the STOP message, the STOP condition will be raised in the server session, as shown:
/* srvrNested3.p */
DEFINE INPUT-OUTPUT PARAMETER p1 AS CHARACTER NO-UNDO.

DEFINE VARIABLE srvrTimeLimit AS INTEGER NO-UNDO INITIAL 10.
DEFINE VARIABLE spinLimit     AS INT64   NO-UNDO INITIAL 15000.

p1 = FILL("Y", 30). /* 30 "Y" characters will be sent to the client */
DO STOP-AFTER srvrTimeLimit:
  RUN spinHere (spinLimit).
END.

RETURN "30 Ys".
PROCEDURE spinHere:
  DEFINE INPUT PARAMETER spinLimit AS INT64 NO-UNDO.

  DEFINE VARIABLE loopFlag AS LOGICAL NO-UNDO.
  DEFINE VARIABLE endTime  AS INT64   NO-UNDO.

  ASSIGN
    loopFlag = TRUE
    endTime  = ETIME(FALSE) + spinLimit.

  DO WHILE loopFlag:
    IF (ETIME(FALSE) > endTime) THEN
      loopFlag = FALSE.
  END.
END PROCEDURE.
In srvrNested3.p running in the server session, the INPUT-OUTPUT parameter p1 is filled with 30 "Y" characters, and the spinHere procedure is called from within a timed code block, with the time limit of 10 seconds (the value of srvrTimeLimit). In this example, spinHere is supposed to return after 15 seconds (the value of spinLimit). The procedure will ostensibly time out after 10 seconds, and the STOP condition will be raised. However, the client session will issue the STOP message to the server after 5 seconds, the STOP condition will be raised in the client after 5 seconds (approximately).
Because srvrNested3.p employs default STOP handling (that is, the srvrNested3.p program does not specify an ON STOP phrase), the STOP condition is not handled by the server session. The timeout is consequently propagated back to the client session.
It is important to note that the remote procedure call could also be made within an explicit timed block. As with the local case, the actual time limit value used by the RUN would be the smaller of the implicit and the explicit time limit values.