Kbase P181158: How to connect to another agent from the AppServer where a request is currently executing
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  31/01/2011 |
|
Status: Unverified
GOAL:
How to connect to another agent from the AppServer where a request is currently executing
GOAL:
How to get connection information from within an AppServer agent to connect to another agent on the same broker
GOAL:
While executing a request on an AppServer, how do I extrapolate the connection information I used to get there?
FACT(s) (Environment):
All Supported Operating Systems
Progress 9.x
OpenEdge 10.x
FIX:
When connected to an AppServer agent from an ABL (or other) client, it may become necessary to create an additional connection to the AppServer you're program is executing on in order to execute additional requests in a different context. The following code sample provides a rough idea of how to accomplish this for most situations.
This code uses the values from the -ubpropfile and -logname parameters, which are specified in the _proapsv session's startup command, by parsing the SESSION:STARTUP-PARAMETERS attribute:
DEFINE VARIABLE hServer AS HANDLE NO-UNDO.
DEFINE VARIABLE cLogFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE cPropFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE cStartup AS CHARACTER NO-UNDO.
DEFINE VARIABLE cInput AS CHARACTER NO-UNDO.
DEFINE VARIABLE cAppService AS CHARACTER NO-UNDO.
DEFINE VARIABLE cConnectString AS CHARACTER NO-UNDO.
DEFINE VARIABLE iLocation AS INTEGER NO-UNDO.
DEFINE VARIABLE lStateFree AS LOGICAL NO-UNDO.
DEFINE TEMP-TABLE ttProp NO-UNDO
FIELD appServiceName AS CHARACTER
FIELD propName AS CHARACTER
FIELD propValue AS CHARACTER
INDEX asProp AS PRIMARY UNIQUE appServiceName propName.
ASSIGN cStartup = SESSION:STARTUP-PARAMETERS
iLocation = INDEX(cStartup,"-logname") + 9
cLogFile = ENTRY(1,SUBSTRING(cStartup,iLocation))
iLocation = INDEX(cStartup,"-ubpropfile") + 12
cPropFile = ENTRY(1,SUBSTRING(cStartup,iLocation))
lStateFree = (SESSION:SERVER-OPERATING-MODE EQ "State-free").
INPUT FROM VALUE(cPropFile).
REPEAT:
IMPORT UNFORMATTED cInput.
cInput = TRIM(cInput).
IF cInput BEGINS "[UBroker.AS" THEN DO:
cAppService = LEFT-TRIM(RIGHT-TRIM(REPLACE(cInput,"[UBroker.AS",""),"]"),".").
cInput = "".
APPSRV-BLK:
DO WHILE NOT (cInput BEGINS "["):
IMPORT UNFORMATTED cInput.
cInput = TRIM(cInput).
IF cInput BEGINS "[" THEN LEAVE APPSRV-BLK.
IF (cInput GT "") NE TRUE OR
cInput BEGINS "#" THEN NEXT APPSRV-BLK.
CREATE ttProp.
ASSIGN ttProp.appServiceName = cAppService
ttProp.propName = SUBSTRING(cInput,1,INDEX(cInput,"=") - 1)
ttProp.propValue = SUBSTRING(cInput,INDEX(cInput,"=") + 1).
END.
END.
END.
INPUT CLOSE.
FIND FIRST ttProp WHERE ttProp.propName EQ "srvrLogFile" AND
ttProp.propValue MATCHES "~*." + cLogFile + ".~*"
NO-LOCK NO-ERROR.
IF AVAILABLE ttProp THEN
cAppService .= ttProp.appServiceName.
ELSE cAppService = "".
IF (cAppService GT "") NE TRUE THEN
RETURN.
cConnectString = "-AppService " + ttProp.appServiceName + " -H localhost".
FIND FIRST ttProp WHERE ttProp.appServiceName EQ cAppService AND
ttProp.propName EQ "portNumber"
NO-LOCK NO-ERROR.
IF NOT AVAILABLE ttProp THEN
FIND FIRST ttProp WHERE ttProp.appServiceName EQ "" AND
ttProp.propName EQ "portNumber"
NO-LOCK NO-ERROR.
IF NOT AVAILABLE ttProp THEN
RETURN.
cConnectString = cConnectString + " -S " + ttProp.propValue + " -DirectConnect" +
(IF lStateFree THEN " -sessionModel Session-free" ELSE "").
CREATE SERVER hServer.
hServer:CONNECT(cConnectString) NO-ERROR.
IF ERROR-STATUS:NUM-MESSAGES GT 0 AND
hServer:CONNECTED() EQ FALSE THEN DO:
/* In case there is an inactive AppService defined which happens to use the same
log filename. No two ACTIVE AppServers can output to the same log file, but
there may be ones defined in the properties file that aren't being used and
could have specified the same log filename. */
FOR EACH ttProp WHERE ttProp.appServiceName NE cAppService AND
ttProp.propName EQ 'srvrLogFile' AND
ttProp.propValue MATCHES "~*." + cLogFile + ".~*":
END.
END.
RUN <program>.p ON hServer..