project BLF > class TDaemonUtility > method GetAppserverConnection

Description

Get the appserver connection for the daemon. The logic is based on:
* If icDaemonAppserverURL is passed, then that connection is used.
* If icDaemonAppserverURL is not passed, then a query on the daemon configuration is used to retrieve the appserver connection information.


Parameters


icDaemonNameinputcharacterName of the daemon
icDaemonAppserverURLinputcharacter
ohDaemonAppserveroutputhandleHandle to the appserver connection for the machine where the daemon needs to run.
ocMessageoutputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method TDaemonUtility.CreateDirectory
method TDaemonUtility.GetDaemonDebugLevel
method TDaemonUtility.GetDaemonLogFile
method TDaemonUtility.GetDaemonProcessInfo
method TDaemonUtility.GetFileType
method TDaemonUtility.KillDaemonProcesses
method TDaemonUtility.ProcessIsValid
method TDaemonUtility.SetDaemonDebugLevel
method TDaemonUtility.StartDaemon


program code (program1/tdaemonutility.p)

assign oiReturnStatus = -98.

if icDaemonAppserverUrl = ? or icDaemonAppserverUrl = ""
then do:
    /* =============================== */
    /* Retrieve the daemon information */
    /* =============================== */
    <Q-3 run DaemonInfo (all) (Read) (NoCache)
       (input 0, (DaemonId)
        input icDaemonName, (DaemonName)
        input '', (DaemonStatus)
        input '', (DaemonStatusDiffersFrom)
        output dataset tqDaemonInfo) in BBaseDaemon >
    
    find first tqDaemonInfo where tqDaemonInfo.tcDaemonName = icDaemonName no-error.
    if not available tqDaemonInfo
    then do:
        ocMessage = substitute (#T-1'Unable to find the daemon based on its name (&1).':255(33)T-1#, icDaemonName).
        return.
    end.
    
    /* the query itself replaces $ENVAPPSERVERURL */
    vcAppServerConnection = tqDaemonInfo.tcDaemonAppserver.
end.
else do:
    assign vcAppserverConnection = icDaemonAppserverUrl.
    /* Replace URL */
    if vcAppServerConnection = "$ENVAPPSERVERURL"
    then do:
        assign vhFcComponent = ?.
        <M-4 run MainBlock  () in XML>
        <M-5 run ReadXMLNodeValue
           (input  search('server.xml') (icXMLFile), 
            input  'serverConfiguration' (icStartTag), 
            input  'ENVAPPSERVERURL' (icNodeTag), 
            output vcAppServerConnection (ocNodeValue), 
            output viFcReturnSuper (oiReturnStatus)) in XML>
        run gipr_DeleteProcedure in vhFcComponent.
        delete procedure vhFcComponent.
        if viFcReturnSuper < 0
        then do :
            assign ocMessage = #T-6'Error reading the information for ENVAPPSERVERURL from server.xml':255(5200)T-6#
                   oiReturnStatus = -3.
            return.
        end.
        if vcAppServerConnection = ? or vcAppServerConnection = ""
        then do:
            assign ocMessage = substitute(#T-7'The configuration of daemon (&1) contains a reference to ENVAPPSERVERURL, but the value for this is not specified in the server.xml file.':255(5201)T-7#, icDaemonName)
                   oiReturnStatus = -3.
            return.
        end.
    end.
end.
    
if vcAppserverConnection <> ? and vcAppserverConnection <> "" and vcAppserverConnection <> "local"
then do:
    /* ================================================================= */
    /* run daemon on appserver                                           */
    /* ================================================================= */
    create server ohDaemonAppserver.
    ohDaemonAppserver:connect("-URL " + vcAppserverConnection,"","","") no-error.
    if not ohDaemonAppserver:connected()
    then do:
        do viErrCount = 1 to error-status:num-messages:
            assign vcMessage = vcMessage + chr(2) + error-status:get-message(viErrCount).
        end.
        assign ocMessage = substitute(#T-2'Connection to appserver (&1) failed.':255(5163)T-2#,vcAppServerConnection) + vcMessage
               oiReturnStatus = -3.
        delete object ohDaemonAppserver.
        return.
    end.
end.

if oiReturnStatus = -98
then assign oiReturnStatus = 0.