Object AppCommon
-
- All Implemented Interfaces:
public class AppCommon
Common 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 interface
AppCommon.Startable
Start/stop things.
-
Field Summary
Fields Modifier and Type Field Description private final ScheduledExecutorService
executor
private Boolean
applicationRunning
private final Config
applicationConfig
private final <Error class: unknown class>
hasskClient
private final <Error class: unknown class>
mqttClient
public final static String
REMOTE_PI
public final static AppCommon
INSTANCE
-
Method Summary
Modifier and Type Method Description final Unit
awaitTermination()
A useful latch for waiting for the application to stop. final Unit
whileRunning(Function0<Unit> block)
Run a block if the application is running. final <F extends Any> F
ignoreErrors(Function0<F> executionBlock, Boolean logIt)
final Unit
convenientStartupHook(List<AppCommon.Startable> $self)
final Unit
convenientShutdownHook(List<AppCommon.Startable> $self, Boolean logErrors)
final ScheduledExecutorService
getExecutor()
A generally sharable executor for running things. final Boolean
getApplicationRunning()
final Unit
setApplicationRunning(Boolean applicationRunning)
final Config
getApplicationConfig()
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
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
.
-
-
-
-