Nov 9, 2021 3:45:22 PM Thomas Dumont avatar

Daemon

Definition

A daemon is a process that runs at regular intervals. Lutece has a centralized interface for managing daemons. Each daemon has its own frequency of execution. In addition, he must provide a report of the treatment carried out. This one is thus searchable in the daemons management interface.

Creation

Implementation

A daemon must extend Lutece's Daemon class. The only method to implement is the run method within which you must call the setLastRunLogs method to pass the execution report to it.

import en.paris.lutece.portal.service.daemon.Daemon;

/ **
 * My Daemon
 * /
public class MyDaemon extends Daemon
{
    / **
     * {@inheritDoc}
     * /
    @Override
    public void run( )
    {
        setLastRunLogs( MyProcess ( ) );
    }
}

Declaration

The Daemon must be declared in 2 places :

Declaration in the plugin XML file

This declaration defines the Java class of the daemon as well as the name and description of the daemon by its i18n keys (to manage the language of the user who consults the centralized interface).

<!-- Daemons -->
<daemons>
    <daemon>
        <daemon-id>myDaemon</daemon-id>
        <daemon-name>myplugin.daemon.myDaemon.name</daemon-name>
        <daemon-description>myplugin.daemon.myDaemon.description</daemon-description>
        <daemon-class>fr.paris.lutece.plugins.myplugin.service.MyDaemon</daemon-class>
    </daemon>
    ...
</daemons>

Declaration in the plugin properties file

This statement is about daemon launch settings.

daemon.myDaemon.interval=86400
daemon.myDaemon.onstartup=1

These values ​​are by default in the properties file of the plugin, but they can be placed in any properties file read by Lutece (ex: daemons.properties)

IMPORTANT From Lutece v4:

The values ​​in this file are read only for the first launch. These values ​​are then stored in the LUTECE Datastore and can only be modified by the centralized daemon management interface.