Class FeatureAvailability


  • public final class FeatureAvailability
    extends Object
    Central registry of available features for fine-grained dependency enforcement in a threaded environment.

    Providers of features can register the availability (initializated and ready-to-use) of a particular feature, upon which other code depends. See registerFeature(java.lang.String, java.lang.Object).

    Code that requires an initialized and ready-to-use feature should call waitForFeature(java.lang.String, java.lang.String)--the calling thread will block until that feature is available.

    Feature names are arbitrary and *should not* be defined as 'public static final String' in this class unless they are of general system interest. Features that are not of general interest can and should still be registered through this mechanism, but the names of those features and the associated data can be defined in a more appropriate place.

    Provider Example

    ...provider runs in its own thread...
    FeatureAvailability.registerFeature( FeatureAvailability.MBEAN_SERVER_FEATURE, mbeanServer );
    

    Client Example
    (arbitrary number of clients, multiple calls OK)

    ...client runs until feature is needed...
    final MBeanServer mbeanServer = (MBeanServer)
    FeatureAvailability.waitForFeature( FeatureAvailability.MBEAN_SERVER_FEATURE );
    

    To see how long client code is blocking, set the DEBUG_ENABLED flag to true.

    • Field Detail

      • AMX_LOADER_FEATURE

        public static final String AMX_LOADER_FEATURE
        feature stating that the AMX MBean Loader is available (but not AMX). Data should not be used
        See Also:
        Constant Field Values
      • AMX_CORE_READY_FEATURE

        public static final String AMX_CORE_READY_FEATURE
        feature stating that the AMX core is ready for use after having been started. Data should not be used. Other AMX subystems might still be in the process of initializing
        See Also:
        Constant Field Values
      • AMX_READY_FEATURE

        public static final String AMX_READY_FEATURE
        feature stating that the AMX and all its subsystems are ready for use. Data is the ObjectName of the DomainRoot
        See Also:
        Constant Field Values
    • Method Detail

      • registerFeature

        public void registerFeature​(String featureName,
                                    Object data)
        Register a named feature as being ready for use. The data value can be a dummy value, or can be something useful to the caller of waitForFeature().

        Do not register a feature until its facilities are ready for use.

        Features should generally be fine-grained, not coarse. For example, the AdminService is a coarsely-defined feature which initializes dozens of things; code that requires the presence of one of those things should arrange for a name feature for that. Examples of this include the MBeanServer, the AdminContext, com.sun.appserv:category=config MBeans, etc.

        Parameters:
        featureName - arbitrary name for the feature, to be used by clients in waitForFeature(java.lang.String, java.lang.String)
        data - arbitrary data of possible interest to clients
      • waitForFeature

        public Object waitForFeature​(String featureName,
                                     String callerInfo)
        Block until the specified feature is available.
        Parameters:
        featureName - the name of the desired feature
        callerInfo - arbitrary caller info for debugging purposes
      • deRegisterFeatures

        public void deRegisterFeatures()