Class SingletonResourceHandler<R>
- Type Parameters:
R
- The type of configuration object. Expected to be immutable.
- All Implemented Interfaces:
Lifecycle
A handler for a singleton resource. This class will manage the interface between a subsystem and its singleton configuration resource. When you start up the handler, it will ensure that the resource exists in the configuration, and if not, use the supplied default to seed the configuration if needed.
If you need to update the resource, you can call updateResource(Object, String)
, which
will encode the object using the ResourceTypeMeta and push the change to the configuration.
To listen for updates to the resource, either subclass this class and override
onResourceUpdated(Object)
, or construct the handler via the builder and register a callback
with the SingletonResourceHandler.Builder.onChange(Consumer)
method.
This class will also listen for changes to the Gateway's redundancy state, and if the Gateway is running as a Backup node, it will use the "backupConfig.json" version of the resource's configuration (if one is defined).
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionSingletonResourceHandler
(ConfigurationManager configManager, RedundancyManager redundancyManager, ResourceTypeMeta<R> meta) SingletonResourceHandler
(GatewayContext context, ResourceTypeMeta<R> meta) -
Method Summary
Modifier and TypeMethodDescriptionprotected org.slf4j.Logger
static <R> SingletonResourceHandler.Builder<R>
newBuilder
(ResourceTypeMeta<R> meta) protected void
onResourceUpdated
(R resource) Override this method to handle the case where the resource is updated.protected void
onResourceUpdated
(R oldResource, R newResource) Override this method to handle the case where the resource is updated.protected void
protected void
updateResource
(R resource) updateResource
(R resource, String actor) Methods inherited from class com.inductiveautomation.ignition.common.lifecycle.AbstractLifecycle
isRunning, shutdown, startup
-
Constructor Details
-
SingletonResourceHandler
-
SingletonResourceHandler
public SingletonResourceHandler(ConfigurationManager configManager, @Nullable RedundancyManager redundancyManager, ResourceTypeMeta<R> meta)
-
-
Method Details
-
createLogger
protected org.slf4j.Logger createLogger() -
onStartup
protected void onStartup()- Specified by:
onStartup
in classAbstractLifecycle
-
onShutdown
protected void onShutdown()- Specified by:
onShutdown
in classAbstractLifecycle
-
onResourceUpdated
Override this method to handle the case where the resource is updated. May also be called on startup if the resource is different from the meta's default config.- Parameters:
resource
- The updated resource, or null if the resource was removed.- See Also:
-
onResourceUpdated
Override this method to handle the case where the resource is updated. May also be called on startup if the resource is different from the meta's default config.The default implementation of this method is to call
onResourceUpdated(Object)
. If you override this method, you should callonResourceUpdated(Object)
if you want to keep the default behavior.- Parameters:
oldResource
- The previous resource value, or null if the resource was just created.newResource
- The updated resource, or null if the resource was removed.
-
getResource
-
updateResource
- Throws:
PushException
-
updateResource
public CompletableFuture<Void> updateResource(R resource, @Nullable String actor) throws PushException - Throws:
PushException
-
newBuilder
-