Object AppCommon
-
- All Implemented Interfaces:
public class AppCommonCommon application control and configuration -- e.g. how many times have you written this code?
This is highly opinionated and is not necessarily intended to be a general purpose library for anyone but myself.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceAppCommon.StartableStart/stop things.
-
Field Summary
Fields Modifier and Type Field Description private final ScheduledExecutorServiceexecutorprivate BooleanapplicationRunningprivate final ConfigapplicationConfigprivate final <Error class: unknown class>hasskClientprivate final <Error class: unknown class>mqttClientpublic final static StringREMOTE_PIpublic final static AppCommonINSTANCE
-
Method Summary
Modifier and Type Method Description final UnitawaitTermination()A useful latch for waiting for the application to stop. final UnitwhileRunning(Function0<Unit> block)Run a block if the application is running. final <F extends Any> FignoreErrors(Function0<F> executionBlock, Boolean logIt)final UnitconvenientStartupHook(List<AppCommon.Startable> $self)final UnitconvenientShutdownHook(List<AppCommon.Startable> $self, Boolean logErrors)final ScheduledExecutorServicegetExecutor()A generally sharable executor for running things. final BooleangetApplicationRunning()final UnitsetApplicationRunning(Boolean applicationRunning)final ConfiggetApplicationConfig()Convenience property for the application configuration. final <Error class: unknown class>getHasskClient()HomeAssistant client using the configuration in application.conf.final <Error class: unknown class>getMqttClient()MQTT client using the configuration in application.conf.-
-
Method Detail
-
awaitTermination
final Unit awaitTermination()
A useful latch for waiting for the application to stop. Used with the applicationRunning property.
-
whileRunning
final Unit whileRunning(Function0<Unit> block)
Run a block if the application is running. This is a convenience method for checking the applicationRunning and catching any errors that occur in the block.
-
ignoreErrors
@Deprecated(message = "Use runCatching instead", replaceWith = @ReplaceWith(imports = {}, expression = "runCatching { executionBlock() }.getOrElse { null }")) final <F extends Any> F ignoreErrors(Function0<F> executionBlock, Boolean logIt)
-
convenientStartupHook
final Unit convenientStartupHook(List<AppCommon.Startable> $self)
-
convenientShutdownHook
final Unit convenientShutdownHook(List<AppCommon.Startable> $self, Boolean logErrors)
-
getExecutor
final ScheduledExecutorService getExecutor()
A generally sharable executor for running things. Most apps will rely on either callbacks or futures, so this just provides a simple way to manage the application's threads.
-
getApplicationRunning
final Boolean getApplicationRunning()
-
setApplicationRunning
final Unit setApplicationRunning(Boolean applicationRunning)
-
getApplicationConfig
final Config getApplicationConfig()
Convenience property for the application configuration.
-
getHasskClient
final <Error class: unknown class> getHasskClient()
HomeAssistant client using the configuration in
application.conf.
-
getMqttClient
final <Error class: unknown class> getMqttClient()
MQTT client using the configuration in
application.conf.
-
-
-
-