project BLF > class TDaemonUtility > method StartDaemon
Description
Starts a daemon instance
Parameters
icDaemonName | input | character | |
icDaemonAppserverURL | input | character | Appserver connection URL for the daemon. This parameter is ONLY filled in when the call to this method is done before the AppServer URL can be retrieved from the daemon query. Typical case is the validation of the daemon configuration.If this parameter is not supplied, then the appserver connection is taken from the internal record that contains the daemon configuration (fcDaemon). |
ocMessage | output | character | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
QadFinancials
program code (program1/tdaemonutility.p)
/* ============================================= */
/* Get info on how the daemon should bhe started */
/* ============================================= */
assign icDaemonName = caps (icDaemonName).
<M-4 run GetAppserverConnection
(input icDaemonName (icDaemonName),
input icDaemonAppserverUrl (icDaemonAppserverURL),
output vhAppserver (ohDaemonAppserver),
output vcMessage (ocMessage),
output viFcReturnSuper (oiReturnStatus)) in TDaemonUtility>
if viFcReturnSuper < 0
then do:
assign oiReturnStatus = viFcReturnSuper
ocMessage = vcMessage.
return.
end. /* if viFcReturnSuper < 0 */
/* ============================================= */
/* Start daemon */
/* ============================================= */
if valid-handle(vhAppserver) and vhAppserver:connected()
then do:
/* ================================================================= */
/* run daemon on appserver */
/* ================================================================= */
run program/tdaemonutility.p persistent set vhFcComponent on vhAppserver (input viSessionID).
run StartDaemonInternal in vhFcComponent
(input icDaemonName,
output vcMessage,
output viFcReturnSuper).
run gipr_DeleteProcedure in vhFcComponent.
delete procedure vhFcComponent.
vhAppserver:disconnect().
delete object vhAppserver.
if viFcReturnSuper < 0
then do:
assign oiReturnStatus = viFcReturnSuper
ocMessage = vcMessage.
return.
end. /* if viFcReturnSuper < 0 */
end. /* if valid-handle(vhAppserver) and vhAppserver:connected() */
else do:
/* ================================================================= */
/* call method locally */
/* ================================================================= */
<M-2 run StartDaemonInternal
(input icDaemonName (icDaemonName),
output vcMessage (ocMessage),
output viFcReturnSuper (oiReturnStatus)) in TDaemonUtility>
if viFcReturnSuper < 0
then do:
assign oiReturnStatus = viFcReturnSuper
ocMessage = vcMessage.
return.
end. /* if viFcReturnSuper < 0 */
end. /* Not if valid-handle(vhAppserver) and vhAppserver:connected() */
/* ============================================================================================== */
/* Set the LastUser on the daemon - this has to be done here and not in the actual daemon-process */
/* as the current user there is the user that is specified in the daemon-configuration while here */
/* we need to know the user who started/stopped the daemon. */
/* Here we set the user who last started the daemonbut do note that the user who last stopped the */
/* daemon is set in BBaseDaemon:ControlDaemon() when the status is set to 'Stopping' */
/* ============================================================================================== */
assign viUserIDForDaemonActions = 0. /* that's the default - as that means is started from the OS-Scripts */
/* Get the current user out of the session */
if viSessionID <> 0 and
viSessionID <> ?
then GETUSEROFSESSIONBLOCK: do :
run StartCacherInPool (output vhCacher) no-error.
if error-status:error or
valid-handle(vhCacher) <> true
then leave GETUSEROFSESSIONBLOCK.
assign vhFcComponent = vhCacher.
<M-3 run GetIntegerValueFromSession
(input viSessionId (iiSessionId),
input 'UsrID':U (icDataItemName),
output viUserIDForDaemonActions (oiValue),
output viFcReturnSuper (oiReturnStatus)) in Cacher>
end. /* GETUSEROFSESSIONBLOCK - if viSessionID <> 0 and */
/* First activate the persistence-layer when this was not yet the case - code copied from business.startpersistence */
run StartPersistenceInPool (input {&TARGETPROCEDURE},
output vhFcComponent,
output viFcReturnSuper).
if viFcReturnSuper >= 0 and
valid-handle(vhFcComponent)
then do :
/* Use WriteDirect to set the LastStartedUsr_ID in the fcDaemon-table */
assign vcQueryPrepare = "for each fcDaemon where fcDaemon.DaemonName = '":U + trim(icDaemonName) + "'":U.
<M-26 run WriteDirect
(input 'fcDaemon':U (icTableName),
input vcQueryPrepare (icPrepare),
input 'LastStartedUsr_ID':U (icFieldList),
input 'i':U (icFieldListDataTypes),
input string(viUserIDForDaemonActions) (icAbsolute),
input '' (icIncremental),
input {&TARGETPROCEDURE} (ihClass),
input 'StartDaemon':U (icUserLogin),
output viFcReturnSuper (oiReturnStatus)) in persistence>
end. /* if viFcReturnSuper >= 0 and */
/* ============================================= */
/* Fill the output message */
/* ============================================= */
assign ocMessage = vcMessage.