project BLF > class Housekeeping > method MainBlock

Description

This is the main method of the Housekeeping component. The code in this is executed when the component is started. It can be run in 2 modes (normal or on-line, defined by the ilRunOnline parameter).

If it is run in "normal" mode, the system checks first if there are active sessions in the system (sessions that did not reach the timeout). If there are none, it just deletes all instances that are not draft instances by running the CleanupState() in the persistence layer.
If it is run in "on-line" mode, it deletes all non-draft instances that are linked to timed-out or invalid sessions. It leaves the other instances in the database, which ensures active sessions are not killed.

Instances are deleted by the persistence layer. One functionality included there is that numbers (BNumber) that were "reserved" for a certain instance are released again, ensuring non-interrupted number sequences used in the business transactions.


Parameters


ilRunOnlineinputlogicalThis logical parameter indicates if the HouseKeeping needs to be run on-line or not. If the Housekeeping is run right before the shutdown of the databse before the backup, this is set to false. If the Housekeeping is run on a system where users are still active, so there are active sessions, this is set to true.


Internal usage


BLF
method TApplication.ExecuteAction
method TApplication.StartApplication


program code (program1/housekeeping.p)

/* code copied from generated instance programs (start) */
vlFcOk = no.
publish "ComponentPoolIsRunning" (output vlFcOk).
if vlFcOk = no
then do:
    <M-9 run Main () in ComponentPool>
    session:add-super-procedure(vhFcComponent).
end.

/* code copied from business.startpersistence */
run StartPersistenceInPool (input {&TARGETPROCEDURE},
                            output vhPL,
                            output viFcReturnSuper).
if viFcReturnSuper < 0
then return.

if ilRunOnline
then do:
    assign vhFcComponent = vhPL.
    <M-13 run CleanupStateOnline
       (input  {&TARGETPROCEDURE} (ihClass), 
        output viFcReturnSuper (oiReturnStatus)) in persistence>
end.
else do:
    assign vhFcComponent = vhPL.
    <M-4 run CleanupState (output viFcReturnSuper (oiReturnStatus)) in persistence>

    <M-7 run ApplicationHousekeeping (output viFcReturnSuper (oiReturnStatus)) in Housekeeping>
end.