You can use the following conditional annotations:
@BeanAvailable
- Only create the annotated bean if the denoted bean is also available@ClassAvailable
- Only create the annotated bean if the denoted class is on the classpath@OnSystemProperty
- Only create the annotated bean if the denoted system property is set and if it optionally also has the given value
The entry point for your application is the DvalinLifecycleAdapter
. Just extend it and implement a main method that calls the static start
method.
This configures your application to read properties from a file called dvalin.properties
.
You can also use environment variables to configure Dvalin. DVALIN_SOME_VARIABLE=foobar
becomes some.variable=foobar
.
If environment variables are present the file is ignored.
The DvalinLogger
can be used to modify the MDC for a single log line.
There are two different startup modes which can be specified with -DstartupMode=<mode>
:
- run: intended for foreground daemons
- dev: start in development mode
The default mode is dev
. If you want to run the program in production mode make sure you start it with -DstartupMode=run
.
In development mode the program's behavior will differ in some small points:
- No Signal handlers are registered
This method is called to start your program. It must be non blocking. If this method throws any Exception the DaemonFramework stops execution of the daemon.
This method is called on OS signal to stop your program. It must be non blocking. If this method throws any Exception the DaemonFramework stops execution of the daemon.
This method is called when the daemon completed startup successfully.
This method is called when the daemon completed shutdown successfully. Immediatly after this method System.exit(0) is called.
This method is called when the daemon received shutdown signal.
This method is called when the daemon aborts execution. Immediatly after this method System.exit(1) is called.
This method is called when the daemon received the OS signal USR2. You can do what you want within this method.
This method is called when an exception occurs in DaemonStarter. It provides the current phase and the thrown exception.
This method is called to obtain the daemon properties. All properties provided in this map will be available via System.getProperty later on. The properties found in de.taimos.daemon.DaemonProperties are used by the daemon framework itself and should be filled.
In your main method just call startDaemon
to run the daemon framework. You have to provide a service name and an instance of your subclass of DaemonLifecycleAdapter;
DaemonStarter.startDaemon("my-service-name", new MyLifecycleAdapter());
Extends the default DaemonLifecycleAdapter
with defaults to a standard Dvalin Spring application.
Instead of using the lifecycle methods of the daemon framework, register beans of the type ISpringLifecycleListener
.
Davlin will call them with their correct lifecycle state.
Dvalin register a BestEffortPropertyProviderChain
and checks multiple locations for properties.
- It lokks for the System property
property.source
and acts like the daemon framework default. - Loads properties from the file
dvalin.properties
- If the module
dvalin-cloud-aws-ssm
is used, values from SSM ParameterStore are loaded - Environment variables starting with
DVALIN_
are used.DVALIN_SERVER_URL
becomesserver.url