Class ScriptServiceUtil

java.lang.Object
org.openhab.core.model.script.ScriptServiceUtil

public class ScriptServiceUtil extends Object
Utility class for providing easy access to script services.
Author:
Davy Vanherbergen - Initial contribution, Kai Kreuzer - renamed and removed interface, Ravi Nadahar - added additional registries for retrieval
  • Field Details

  • Constructor Details

  • Method Details

    • deactivate

      public void deactivate()
    • getItemRegistry

      public static ItemRegistry getItemRegistry()
      Returns:
      The ItemRegistry.
    • getItemRegistryInstance

      public ItemRegistry getItemRegistryInstance()
    • getThingRegistry

      public static ThingRegistry getThingRegistry()
      Returns:
      The ThingRegistry instance.
    • getThingRegistryInstance

      public ThingRegistry getThingRegistryInstance()
    • getEventPublisher

      public static EventPublisher getEventPublisher()
      Returns:
      The EventPublisher instance.
    • getModelRepository

      public static ModelRepository getModelRepository()
      Returns:
      The ModelRepository instance.
    • getModelRepositoryInstance

      public ModelRepository getModelRepositoryInstance()
    • getMetadataRegistry

      public static MetadataRegistry getMetadataRegistry()
      Returns:
      The MetadataRegistry instance.
    • getMetadataRegistryInstance

      public MetadataRegistry getMetadataRegistryInstance()
    • getRuleRegistry

      public static RuleRegistry getRuleRegistry()
      Returns:
      The RuleRegistry instance.
    • getRuleRegistryInstance

      public RuleRegistry getRuleRegistryInstance()
    • getItemChannelLinkRegistry

      public static ItemChannelLinkRegistry getItemChannelLinkRegistry()
      Returns:
      The ItemChannelLinkRegistry instance.
    • getItemChannelLinkRegistryInstance

      public ItemChannelLinkRegistry getItemChannelLinkRegistryInstance()
    • getTimeZone

      public static TimeZone getTimeZone()
      Returns:
      The currently openHAB configured TimeZone.
    • getZoneId

      public static ZoneId getZoneId()
      Returns:
      The currently openHAB configured ZoneId.
    • getTimeZoneProvider

      public static TimeZoneProvider getTimeZoneProvider()
      Returns:
      The TimeZoneProvider instance.
    • getTimeZoneProviderInstance

      public TimeZoneProvider getTimeZoneProviderInstance()
    • getLocale

      public static Locale getLocale()
      Returns:
      The currently openHAB configured Locale.
    • getLocaleProvider

      public static LocaleProvider getLocaleProvider()
      Returns:
      The LocaleProvider instance.
    • getLocaleProviderInstance

      public LocaleProvider getLocaleProviderInstance()
    • getRuleManager

      public static @Nullable RuleManager getRuleManager()
      Returns:
      The RuleManager / rule engine instance or null if it doesn't exist.
    • getRuleManagerInstance

      public @Nullable RuleManager getRuleManagerInstance()
    • getScheduler

      public static Scheduler getScheduler()
      Returns:
      The Scheduler instance.
    • getSchedulerInstance

      public Scheduler getSchedulerInstance()
    • getScriptEngine

      public static ScriptEngine getScriptEngine()
    • getActionServices

      public static List<ActionService> getActionServices()
      Returns:
      A List of currently registered ActionService instances.
    • getThingActions

      public static List<ThingActions> getThingActions()
      Returns:
      A List of currently registered ThingActions instances.
    • getActionServiceInstances

      public List<ActionService> getActionServiceInstances()
    • getThingActionsInstances

      public List<ThingActions> getThingActionsInstances()
    • addActionService

      public void addActionService(ActionService actionService)
    • removeActionService

      public void removeActionService(ActionService actionService)
    • addThingActions

      public void addThingActions(ThingActions thingActions)
    • removeThingActions

      public void removeThingActions(ThingActions thingActions)
    • setScriptEngine

      public void setScriptEngine(ScriptEngine scriptEngine)
    • unsetScriptEngine

      public void unsetScriptEngine(ScriptEngine scriptEngine)
    • getInstance

      public static <T> @Nullable T getInstance(Class<T> clazz)
      Retrieve an OSGi instance of the specified Class, if it exists. The reference to the instance is unreserved, which means that the instance might stop being valid at any time, for example if the service or the containing bundle is stopped.

      Returning an unreserved service isn't kosher in the world of OSGi, but the only alternative is that the scripts that retrieve the instance are responsible for unregistering the reservation after use. That isn't a reasonable thing to expect from user scripts. The chance that a service is stopped while OH is running is quite small, so on balance, returning an unreserved service instance seems like the best way to do it. It isn't much different from returning an instance to a registry that is reserved by ScriptServiceUtil - if the ScriptServiceUtil itself is stopped, the instance might become invalid while the script is using it.

      Type Parameters:
      T - the class type.
      Parameters:
      clazz - the class of the instance to get.
      Returns:
      The instance or null if the instance wasn't found.