When more than one Login Broker is started, there is no direct link that can be used to establish "which login broker spawned" a specific remote server that was needed for a remote client connection.
One method of associating servers with the Login Broker which started them would be to explicitly define a unique
-minport -maxport range when starting each login broker. Then, the
_servers._server-portnum VST can be used to identify which Login Broker (BROKER 0, BROKER <n>), started any given remote server.
The below code assumes the database was started using the following parameters:
{primary login broker}:
proserve dbname <..startup parameters..> -S 10000 -minport 10001 -maxport 10099
{secondary login broker}:
proserve dbname -m3 <..startup parameters..> -S 10100 -minport 10101 -maxport 10199
{tertiary login broker}:
proserve dbname -m3 <..startup parameters..> -S 10200 -minport 10201 -maxport 10299
Note that, only relevant parameters to this discussion are listed here.
The following example code uses the
_connect and
_servers Virtual System Tables (VST) to find the following:
- Which Login Broker a remote client connected to when they accessed the database.
- The Remote Server that remote client is currently connected to
- The Port Number of the remote server in relation to the port number of the Login Broker.
DEFINE TEMP-TABLE ttServers NO-UNDO
FIELD tiServerNum AS INTEGER LABEL "SVR_num" FORMAT ">>9"
FIELD tiServerPid AS INTEGER LABEL "Server Pid" FORMAT ">>>>>>>>>9"
FIELD tcServerType AS CHARACTER LABEL "Server Type" FORMAT "x(14)"
FIELD tiPortNum AS INTEGER LABEL "Port Number" FORMAT ">>>>>>>>>9"
FIELD tiParentSrv AS INTEGER LABEL "Parent Srv" FORMAT ">>9"
FIELD tiNumUsers AS INTEGER LABEL "Num Users"
FIELD tiMaxUsers AS INTEGER LABEL "Max Users"
INDEX idxServers IS PRIMARY UNIQUE tiPortNum.
DEFINE BUFFER buffServers FOR ttServers.
DEFINE QUERY qBrokers FOR ttServers SCROLLING.
DEFINE BROWSE bBrokers QUERY qBrokers
DISPLAY ttServers.tiServerNum LABEL "Broker"
ttServers.tiServerPid LABEL "PID"
ttServers.tcServerType
ttServers.tiPortNum
ttServers.tiNumUsers
ttServers.tiMaxUsers
WITH 2 DOWN WIDTH 78 TITLE "Brokers".
DEFINE QUERY qServers FOR buffServers SCROLLING.
DEFINE BROWSE bServers QUERY qServers
DISPLAY buffServers.tiServerNum LABEL "Server"
buffServers.tiServerPid LABEL "PID"
buffServers.tcServerType
buffServers.tiPortNum
buffServers.tiNumUsers
buffServers.tiMaxUsers
WITH 8 DOWN WIDTH 78 TITLE "Servers".
DEFINE QUERY qUsers FOR _connect SCROLLING.
DEFINE BROWSE bUsers QUERY qUsers
DISPLAY _connect-server LABEL "Server Num"
_Connect-ClientType LABEL "Type"
_connect-pid LABEL "PID"
_connect-device LABEL "Device"
_connect-usr LABEL "User Num"
_connect-name LABEL "User ID"
SUBSTRING(_connect-time,5,6) LABEL "Conn Date"
SUBSTRING(_connect-time,12,8) LABEL "Conn Time"
WITH 8 DOWN WIDTH 78 TITLE "Connected Users".
DEFINE FRAME fBrokersAndServers bBrokers SKIP(1)
bServers SKIP(1)
bUsers
WITH THREE-D TITLE "Servers by Broker".
DEFINE VARIABLE iParentSrv AS INTEGER NO-UNDO.
ON VALUE-CHANGED OF BROWSE bBrokers DO:
IF NOT AVAILABLE ttServers THEN DO:
CLOSE QUERY qServers.
LEAVE.
END.
OPEN QUERY qServers FOR EACH buffServers
WHERE buffServers.tiParentSrv EQ ttServers.tiServerNum
BY tiPortNum.
APPLY "VALUE-CHANGED" TO BROWSE bServers.
END.
ON VALUE-CHANGED OF BROWSE bServers DO:
IF NOT AVAILABLE buffServers THEN DO:
CLOSE QUERY qUsers.
LEAVE.
END.
OPEN QUERY qUsers FOR EACH _connect
WHERE _connect._connect-server EQ buffServers.tiServerNum
BY _connect-time.
END.
/* Sort by Port Number in order to read and identify the servers and brokers in order */
FOR EACH _servers NO-LOCK
WHERE _servers._Server-type NE "Inactive" BY _Servers._Server-PortNum:
/* This is a Broker */
IF _servers._server-type NE "LOGIN" THEN DO:
IF _servers._server-portnum GT 10000 AND
_servers._server-portnum LT 10100 THEN
iParentSrv = 0.
ELSE IF _servers._server-portnum GT 10100 AND
_servers._server-portnum LT 10200 THEN
iParentSrv = 1.
ELSE iParentSrv = 2.
END.
ELSE iParentSrv = ?.
CREATE ttServers.
ASSIGN ttServers.tiServerNum = _servers._server-num
ttServers.tiServerPid = _servers._server-pid
ttServers.tcServerType = _servers._server-type
ttServers.tiPortNum = _servers._server-portnum
ttServers.tiParentSrv = iParentSrv
ttServers.tiNumUsers = _servers._server-currusers
ttServers.tiMaxUsers = _servers._server-maxusers.
END.
OPEN QUERY qBrokers FOR EACH ttServers
WHERE ttServers.tcServerType EQ "LOGIN"
BY ttServers.tiPortNum.
ENABLE ALL WITH FRAME fBrokersAndServers.
APPLY "ENTRY" TO BROWSE bBrokers.
WAIT-FOR CLOSE OF THIS-PROCEDURE.