Package com.github.jpmsilva.jsystemd
Class Systemd
java.lang.Object
com.github.jpmsilva.jsystemd.Systemd
- All Implemented Interfaces:
AutoCloseable
public class Systemd extends Object implements AutoCloseable
The main systemd integration class.
Implements and exposes most of the sd_notify
protocol, as well as some convenience methods.
Since this object sets up some timers for periodic communication with systemd, client code is expected to call close()
then they no longer need
Systemd instances. The implementation also implements AutoCloseable
to ease implementation in DI containers that support the semantic.
- Author:
- Joao Silva
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Systemd.Builder
Specialized build class ofSystemd
objects. -
Method Summary
Modifier and Type Method Description void
addStatusProviders(int index, SystemdNotifyStatusProvider... providers)
Adds the status providers to the the list of providers in the specified position.void
addStatusProviders(int index, List<SystemdNotifyStatusProvider> providers)
Adds the status providers to the the list of providers in the specified position.void
addStatusProviders(SystemdNotifyStatusProvider... providers)
Adds the status providers to the end of the list of providers.static @NotNull Systemd.Builder
builder()
Provides a dedicated builder instance that knows how to create Systemd instances.void
close()
void
extendTimeout()
Forces the timeout to be extended.Optional<HealthProvider>
getHealthProvider()
Returns the current health provider.@NotNull List<SystemdNotifyStatusProvider>
getStatusProviders()
Returns a read only view of the current providers.boolean
isReady()
Returns if the application as completed startup.void
ready()
Notifies systemd that the unit is ready.void
setHealthProvider(@Nullable HealthProvider provider)
Sets the current health provider, overrides any other previously set.void
setStatusProviders(@NotNull List<SystemdNotifyStatusProvider> providers)
Sets the current providers, unregistering any other previously added.void
updateStatus()
Forces the current status to be calculated and sent to systemd.void
watchdog()
Forces the watchdog timestamp to be updated.
-
Method Details
-
builder
Provides a dedicated builder instance that knows how to create Systemd instances.- Returns:
- a builder instance
-
addStatusProviders
Adds the status providers to the the list of providers in the specified position.- Parameters:
index
- position to add the providersproviders
- the providers to add
-
addStatusProviders
Adds the status providers to the end of the list of providers.- Parameters:
providers
- the providers to add
-
addStatusProviders
Adds the status providers to the the list of providers in the specified position.- Parameters:
index
- position to add the providersproviders
- the providers to add
-
getStatusProviders
Returns a read only view of the current providers.- Returns:
- the current list of providers
-
setStatusProviders
Sets the current providers, unregistering any other previously added.- Parameters:
providers
- the providers to set
-
getHealthProvider
Returns the current health provider.- Returns:
- the current provider
-
setHealthProvider
Sets the current health provider, overrides any other previously set.- Parameters:
provider
- the provider to set, ornull
to disable the watchdog health integration
-
updateStatus
public void updateStatus()Forces the current status to be calculated and sent to systemd. The methodenableStatusUpdate(long, TimeUnit)
can be used to enable periodic status updates. -
extendTimeout
public void extendTimeout()Forces the timeout to be extended. The amount of time to extend is specified when the Systemd instance is build withenableExtendTimeout(long, TimeUnit, long)
, or 29 seconds if otherwise. Timeout extensions can only be sent during startup. -
watchdog
public void watchdog()Forces the watchdog timestamp to be updated. The methodenableWatchdog(long, TimeUnit)
can be used to enable periodic watchdog updates.If health provider is set and returns unhealthy the watchdog timestamp is not updated.
-
ready
public void ready()Notifies systemd that the unit is ready. -
isReady
public boolean isReady()Returns if the application as completed startup.- Returns:
true
if and only ifready
has been called.
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-