Class Feature

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public final class Feature
    extends java.lang.Object
    implements java.io.Closeable
    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.
        Parameters:
        name - the name of the feature toggle.
        whiteboard - the whiteboard where to register the feature toggle.
        Returns:
        the feature toggle.
      • isEnabled

        public boolean isEnabled()
        Returns:
        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 java.io.Closeable