Kbase P129528: How to reuse connections to the application server in the Webspeed
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  3/10/2009 |
|
Status: Unverified
GOAL:
How to reuse application server connection in WebSpeed agent
GOAL:
How to connect Application Server from a WebSpeed application.
FACT(s) (Environment):
OpenEdge 10.x
Progress 9.x
WebSpeed 2.x
WebSpeed 3.x
All Supported Operating Systems
FIX:
WebSpeed Agents have several ways to interact with Application Server. This document, shows one approach, where the agent connects the broker the very first time it needs to run code in the application server and stays connected up to the agent shutdown. This approach is more useful when mostly web applications uses the Application Server, and there are lots of users for the web application. The main goal is to save time to connect/disconnect the broker as well not overload the networking by creating and destroying lots of connections in a short period.
The chosen design for this document was to use a super procedure added to the session. This super procedures holds a temp-table that stores a broker name and a handle. This procedure also expose a connect procedure to be used in the WebSpeed application.
Bellow, there is the file listing and a sample
/* AppServerConn.i
*
*This include starts the super procedure case it's not already started. Should be
*added to all webspeed applications that wants to run code in the App server
*
*/
DEF VAR myProcHandle__ AS HANDLE.
DEF VAR mySessionSuperProcs____ AS CHAR.
mySessionSuperProcs____ = SESSION:SUPER-PROCEDURES.
DEFINE VARIABLE i___ AS INTEGER NO-UNDO.
DEF VAR lfound___ AS LOGICAL.
REPEAT i___ = 1 TO NUM-ENTRIES (mySessionSuperProcs____):
DEFINE VARIABLE procHandle AS HANDLE NO-UNDO.
procHandle = WIDGET-HANDLE(ENTRY(i___, mySessionSuperProcs____)).
IF procHandle:NAME = "app/connectAppServer.p" THEN DO:
lFound___ = TRUE.
LEAVE.
END.
END.
IF NOT lfound___ THEN DO:
RUN "app/connectAppServer.p" PERSISTENT SET myProcHandle__.
SESSION:ADD-SUPER-PROCEDURE(myProcHandle__).
END.
/**
*app/connectAppServer.p
*
* Defines the connect procedure and a temp-table to store broker name and handle.
*
*
*/
/*Stores the brokers names and handles */
DEFINE TEMP-TABLE appServerConn
FIELD broker AS CHAR
FIELD brokerHandle AS HANDLE.
PROCEDURE connectAppServer:
DEFINE INPUT PARAM broker AS CHAR.
DEFINE INPUT PARAM host AS CHAR.
DEFINE INPUT PARAM nameServerPort AS CHAR.
DEFINE OUTPUT PARAMETER hServer AS HANDLE.
DEF VAR h AS HANDLE.
FIND FIRST appServerConn WHERE appserverconn.broker = broker NO-LOCK NO-ERROR.
IF NOT AVAIL appServerConn THEN DO:
/* connects this broker. It's the first time it was referred in the agent*/
CREATE SERVER h.
h:CONNECT("-AppService " + broker + " -H " + host + " -S " + nameServerPort).
CREATE appServerConn.
ASSIGN appserverconn.broker = broker.
appServerConn.broker = broker.
appServerConn.brokerHandle = h.
hServer = h.
END.
ELSE DO:
IF appserverconn.brokerHandle:CONNECTED() THEN DO:
hServer = brokerHandle.
END.
ELSE DO:
/* Needs to be reconnected. Broker was .stopped since last execution or something happens*/
IF VALID-HANDLE(h) THEN
DELETE OBJECT h.
CREATE SERVER h.
h:CONNECT("-AppService " + broker + " -H localhost -S 5162").
appServerConn.broker = broker.
appServerConn.brokerHandle = h.
hServer = h.
END.
END.
END.
/*
* Sample WebSpeed application
*
*/
{src/web/method/e4gl.i}
/* Starts the super procedure */
{appserverconn.i}.
DEFINE VARIABLE myHandle AS HANDLE NO-UNDO. /* all the times will be always the same value for each agent while the agent is alive */
RUN connectAppServer(INPUT "asbroker1", "localhost", "5162", OUTPUT myHandle).
DEFINE VARIABLE ret AS CHARACTER NO-UNDO.
RUN <yourAppliction> ON SERVER myHandle(OUTPUT ret).
{&out} ret.
.