project BLF > class BBaseDaemonProcessor > method StartDaemonProcessorInstance
Description
This main method contains the generic logic for the processing of a daemon.
It implements the flow of any daemon process.
For the specific daemon implementation, the data item "vcFcDaemonName" must be specified before the <ANCESTOR-CODE> section.
Parameters
ocErrorMessage | output | character | Error message produced by the daemon processor. |
ilStop | input | logical | Stop the daemon? |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
program code (program1/bbasedaemonprocessor.p)
assign oiReturnStatus = -98.
assign ocErrorMessage = ""
vlFcStopDaemon = ilStop.
/* ================================================================= */
/* Check whether the name of the daemon is specified. */
/* ================================================================= */
if vcFcDaemonName = ? or vcFcDaemonName = ""
then do:
assign ocErrorMessage = trim(#T-13'Daemon cannot be started. The name is not supplied.':120(116)T-13#)
oiReturnStatus = -50.
return.
end.
/* ================================================================= */
/* Initialize everything for the proper functioning of the daemon */
/* ================================================================= */
<M-1 run Initialize (output oiReturnStatus (oiReturnStatus)) in BBaseDaemonProcessor>
if oiReturnStatus <> 0
then do :
<M-4 run SetMessageInDaemonLog
(input substitute('DaemonProcessor.StartDaemonProcessorInstance; ':U + #T-14'***Failed to start an instance of the daemon processor (&1).':120(117)T-14#,vcfcDaemonName) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
<M-57 run StopDaemon (output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
return.
end.
/* ================================================================= */
/* If ilStop = true then the daemon should be send a stop request */
/* Else, the daemon should start with the master loop */
/* ================================================================= */
if ilStop
then do :
<M-2 run SetDaemonStopping (output oiReturnStatus (oiReturnStatus)) in BBaseDaemonProcessor>
if oiReturnStatus <> 0
then do:
<M-9 run SetMessageInDaemonLog
(input substitute('DaemonProcessor.StartDaemonProcessorInstance; ':U + #T-16'***An error has occurred while issuing a stop request to the daemon (&1) - return status: &2.':120(119)T-16#,vcfcDaemonName,string(oiReturnStatus)) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
end.
return.
end.
else do :
/* ================================================================= */
/* Mark the daemon as running */
/* ================================================================= */
<M-7 run MarkDaemonRunning (output oiReturnStatus (oiReturnStatus)) in BBaseDaemonProcessor>
if oiReturnStatus <> 0
then do:
<M-8 run SetMessageInDaemonLog
(input trim('DaemonProcessor.StartDaemonProcessorInstance; ':U + #T-15'***Daemon cannot be started. It cannot be marked as active in the system.':120(118)T-15#) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
return.
end.
<M-11 run SetMessageInDaemonLog
(input 'DaemonProcessor.StartDaemonProcessorInstance; ':U + trim(#T-17'Successfully started instance of the daemon processor.':120(120)T-17#) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
if current-language <> ?
then do:
<M-86 run SetMessageInDaemonLog
(input #T-87'Language':40(572)T-87# + '=' + current-language (icMessage),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
end.
<M-3 run LoopForWork (output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
if viFcReturnSuper <> 0
then do :
assign oiReturnStatus = viFcReturnSuper.
/* =============================================================== */
/* We need to tell the system this daemon processor instance is */
/* not active anymore, first... */
/* =============================================================== */
<M-10 run StopDaemon (output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
<M-5 run SetMessageInDaemonLog
(input substitute('DaemonProcessor.StartDaemonProcessorInstance; ':U + #T-18'***The daemon instance exited with an error (&1).':120(121)T-18#,string(oiReturnStatus)) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
end.
else do:
<M-12 run SetMessageInDaemonLog (input 'DaemonProcessor.StartDaemonProcessorInstance; ':U + trim(#T-19'The daemon processor stopped in a normal way.':120(122)t-19#) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
end.
end.
if oiReturnStatus = -98
then assign oiReturnStatus = 0.