Class BaseModuleHandlerFactory

java.lang.Object
org.openhab.core.automation.handler.BaseModuleHandlerFactory
All Implemented Interfaces:
ModuleHandlerFactory
Direct Known Subclasses:
AnnotatedThingActionModuleTypeProvider

@NonNullByDefault public abstract class BaseModuleHandlerFactory extends Object implements ModuleHandlerFactory
This class provides a ModuleHandlerFactory base implementation. It is used by its subclasses for base implementation of creating and disposing ModuleHandler instances. They only have to implement internalCreate(Module, String) method for creating concrete instances needed for the operation of the Modules.
Author:
Kai Kreuzer - Initial contribution, Benedikt Niehues - change behavior for unregistering ModuleHandler
  • Constructor Details

    • BaseModuleHandlerFactory

      public BaseModuleHandlerFactory()
  • Method Details

    • deactivate

      protected void deactivate()
      Should be overridden by the implementations that extend this base class. Called from DS to deactivate the ModuleHandlerFactory.
    • getHandlers

      protected Map<String,ModuleHandler> getHandlers()
      Provides all available ModuleHandlers created by concrete factory implementation.
      Returns:
      a map with keys calculated by concatenated rule UID and module Id and values representing ModuleHandler created for concrete module corresponding to the module Id and belongs to rule with such UID.
    • getHandler

      public @Nullable ModuleHandler getHandler(Module module, String ruleUID)
      Description copied from interface: ModuleHandlerFactory
      Creates a ModuleHandler instance needed for the operation of the Modules included in Rules.
      Specified by:
      getHandler in interface ModuleHandlerFactory
      Parameters:
      module - the Module for which a ModuleHandler instance must be created.
      ruleUID - the identifier of the Rule that the given module belongs to.
      Returns:
      a new ModuleHandler instance, or null if the type of the module parameter is not supported by this factory.
    • internalCreate

      protected abstract @Nullable ModuleHandler internalCreate(Module module, String ruleUID)
      Creates a new ModuleHandler for a given module and ruleUID.
      Parameters:
      module - the Module for which a handler should be created.
      ruleUID - the identifier of the Rule that the given module belongs to.
      Returns:
      a ModuleHandler instance or null if this module type is not supported.
    • ungetHandler

      public void ungetHandler(Module module, String ruleUID, ModuleHandler handler)
      Description copied from interface: ModuleHandlerFactory
      Releases the ModuleHandler instance when it is not needed anymore for handling the specified module in the Rule with the specified ruleUID. If no other Rules and Modules use this handler instance, it should be disposed.
      Specified by:
      ungetHandler in interface ModuleHandlerFactory
      Parameters:
      module - the Module for which the handler was created.
      ruleUID - the identifier of the Rule that the given module belongs to.
      handler - the ModuleHandler instance that is no longer needed.
    • getModuleIdentifier

      protected String getModuleIdentifier(String ruleUid, String moduleId)