Interface OperationalModesService

All Known Implementing Classes:
DefaultOperationalModesService

public interface OperationalModesService
API for operational mode management.
Since:
1.62
Version:
2.1
Author:
matt
  • Field Details

    • TOPIC_ENABLE_OPERATIONAL_MODES

      static final String TOPIC_ENABLE_OPERATIONAL_MODES
      The instruction topic for activating a set of operational modes.

      The instruction is expected to provide one or more INSTRUCTION_PARAM_OPERATIONAL_MODE parameters with the modes to be enabled.

      See Also:
    • TOPIC_DISABLE_OPERATIONAL_MODES

      static final String TOPIC_DISABLE_OPERATIONAL_MODES
      The instruction topic for deactivating a set of operational modes.

      The instruction is expected to provide one or more INSTRUCTION_PARAM_OPERATIONAL_MODE parameters with the modes to be disabled.

      See Also:
    • INSTRUCTION_PARAM_OPERATIONAL_MODE

      static final String INSTRUCTION_PARAM_OPERATIONAL_MODE
      Instruction parameter for an operational mode name.
      See Also:
    • INSTRUCTION_PARAM_EXPIRATION

      static final String INSTRUCTION_PARAM_EXPIRATION
      Instruction parameter for an expiration time.
      Since:
      1.1
      See Also:
    • EVENT_TOPIC_OPERATIONAL_MODES_CHANGED

      static final String EVENT_TOPIC_OPERATIONAL_MODES_CHANGED
      An Event topic for when a the active operational modes have changed.

      This event must be sent after the a change to the operational modes has been persisted. The event is expected to provide a EVENT_PARAM_ACTIVE_OPERATIONAL_MODES parameter with the modes that are effectively active after the change.

      See Also:
    • EVENT_PARAM_ACTIVE_OPERATIONAL_MODES

      static final String EVENT_PARAM_ACTIVE_OPERATIONAL_MODES
      Event parameter with a Set of active operational modes.

      If no user-defined modes are active, a default mode is assumed and an empty Set must be provided.

      See Also:
  • Method Details

    • isOperationalModeActive

      boolean isOperationalModeActive(String mode)
      Test if a specific mode is active.

      Note that a null or empty mode argument will be treated as testing if the default mode is active, which is always true.

      Parameters:
      mode - the mode to test; the mode can be prefixed with ! to test if the given mode is not active
      Returns:
      true if mode is active, or if mode starts with ! then true if mode is not active
    • activeOperationalModes

      Set<String> activeOperationalModes()
      Get the set of active operational modes.
      Returns:
      the active operational modes, never null
    • activeOperationalModesWithExpirations

      Map<String,Long> activeOperationalModesWithExpirations()
      Get the set of active operational modes with expirations.

      This method returns only the operational modes that are both active and have an expiration configured (that is still in the future).

      Returns:
      the active operational modes that have expiration dates, never null
      Since:
      2.1
    • enableOperationalModes

      Set<String> enableOperationalModes(Set<String> modes)
      Enable a set of operational modes.
      Parameters:
      modes - the modes to enable
      Returns:
      the active operational modes, after activating modes, never null
    • enableOperationalModes

      Set<String> enableOperationalModes(Set<String> modes, Instant expire)
      Enable a set of operational modes.
      Parameters:
      modes - the modes to enable
      expire - a date after which modes should be automatically disabled, or null for no expiration
      Returns:
      the active operational modes, after activating modes, never null
      Since:
      2.0
    • disableOperationalModes

      Set<String> disableOperationalModes(Set<String> modes)
      Disable a set of operational modes.
      Parameters:
      modes - the modes to disable
      Returns:
      the active operational modes, after deactivating modes, never null
    • hasActiveOperationalMode

      static boolean hasActiveOperationalMode(org.osgi.service.event.Event event, String mode)
      Test if an event has an active mode parameter value.

      This method will look for a EVENT_PARAM_ACTIVE_OPERATIONAL_MODES event parameter in the provided event. If the parameter is a Set, and it contains mode or mode is null or empty, then true will be returned.

      Parameters:
      event - the event to inspect
      mode - the mode to test for
      Returns:
      true if mode is included in the active modes included in the event
    • expirationDate

      static Instant expirationDate(Instruction instruction)
      Parse an expiration value from an instruction parameter.

      The INSTRUCTION_PARAM_EXPIRATION parameter is inspected for an epoch String value, which will be parsed and returned as a date instance if available.

      Parameters:
      instruction - the instruction to parse the expiration parameter from
      Returns:
      the expiration date, or null if none available
      Since:
      2.0
    • registerOperationalModeInfo

      UUID registerOperationalModeInfo(OperationalModesService.OperationalModeInfo info)
      Register operational mode information for "well known" modes.
      Parameters:
      info - the information to register
      Returns:
      a unique registration ID
      Since:
      2.1
    • registeredOperationalModes

      Get all registered operational mode information.
      Returns:
      all registered operational mode information
      Since:
      2.1
    • unregisterOperationalModeInfo

      boolean unregisterOperationalModeInfo(UUID registrationId)
      Unregister previously registered operational mode information.
      Parameters:
      registrationId - the registration ID, previously returned from registerOperationalModeInfo(OperationalModeInfo)
      Returns:
      true if the registration ID was found, false otherwise
      Since:
      2.1
    • withPrefix

      An operational mode information predicate to match on a name prefix.
      Parameters:
      prefix - the prefix to match
      Returns:
      the predicate
      Since:
      2.1
    • withTag

      An operational mode information predicate to match on a tag.
      Parameters:
      tag - the tag to match
      Returns:
      the predicate
      Since:
      2.1
    • withPrefixAndTag

      static Predicate<OperationalModesService.OperationalModeInfo> withPrefixAndTag(String prefix, String tag)
      An operational mode information predicate to match on a tag.
      Parameters:
      prefix - the prefix to match
      tag - the tag to match
      Returns:
      the predicate
      Since:
      2.1