Class Feature

  • All Implemented Interfaces:, java.lang.AutoCloseable

    public final class Feature
    extends java.lang.Object
    A feature toggle to control new functionality. The default state of a feature is false and can be controlled by third party code discovering FeatureToggles on the Whiteboard. Every feature is linked to a feature toggle and allows to control the state of the feature toggle via FeatureToggle.setEnabled(boolean). Creating a new feature involves registering a feature toggle on the Whiteboard and potentially comes with some overhead (e.g. when the whiteboard is based on OSGi). Therefore, client code should not create a new feature, check the state and then immediately release/close it again. Instead a feature should be acquired initially, checked at runtime whenever needed and finally released when the client component is destroyed.
    • Method Detail

      • newFeature

        public static Feature newFeature​(java.lang.String name,
                                         Whiteboard whiteboard)
        Creates a new Feature with the given name and registers the corresponding FeatureToggle on the Whiteboard. Client code must call close() when the toggle is not used anymore.
        name - the name of the feature toggle.
        whiteboard - the whiteboard where to register the feature toggle.
        the feature toggle.
      • isEnabled

        public boolean isEnabled()
        the current state of this feature.
      • close

        public void close()
        Releases resources for this feature toggle.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface