Class SingletonResourceHandler<R>

java.lang.Object
com.inductiveautomation.ignition.common.lifecycle.AbstractLifecycle
com.inductiveautomation.ignition.gateway.config.SingletonResourceHandler<R>
Type Parameters:
R - The type of configuration object. Expected to be immutable.
All Implemented Interfaces:
Lifecycle

public class SingletonResourceHandler<R> extends AbstractLifecycle

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).

  • Constructor Details

  • Method Details

    • createLogger

      protected org.slf4j.Logger createLogger()
    • onStartup

      protected void onStartup()
      Specified by:
      onStartup in class AbstractLifecycle
    • onShutdown

      protected void onShutdown()
      Specified by:
      onShutdown in class AbstractLifecycle
    • onResourceUpdated

      protected void onResourceUpdated(@Nullable R resource)
      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

      protected void onResourceUpdated(@Nullable R oldResource, @Nullable R newResource)
      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 call onResourceUpdated(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

      public R getResource()
    • updateResource

      public CompletableFuture<Void> updateResource(R resource) throws PushException
      Throws:
      PushException
    • updateResource

      public CompletableFuture<Void> updateResource(R resource, @Nullable String actor) throws PushException
      Throws:
      PushException
    • newBuilder

      public static <R> SingletonResourceHandler.Builder<R> newBuilder(@Nonnull ResourceTypeMeta<R> meta)