public final class FeatureAvailability extends Object
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.
| Modifier and Type | Field and Description |
|---|---|
static String |
AMX_CORE_READY_FEATURE
feature stating that the AMX core is ready for use after having been started.
|
static String |
AMX_LOADER_FEATURE
feature stating that the AMX MBean Loader is available (but not AMX).
|
static String |
AMX_READY_FEATURE
feature stating that the AMX and all its subsystems are ready for use.
|
| Modifier and Type | Method and Description |
|---|---|
void |
deRegisterFeatures() |
static FeatureAvailability |
getInstance() |
void |
registerFeature(String featureName,
Object data)
Register a named feature as being ready for use.
|
Object |
waitForFeature(String featureName,
String callerInfo)
Block until the specified feature is available.
|
public static final String AMX_LOADER_FEATURE
public static final String AMX_CORE_READY_FEATURE
public static final String AMX_READY_FEATURE
public static FeatureAvailability getInstance()
public void registerFeature(String featureName, Object data)
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.
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 clientspublic Object waitForFeature(String featureName, String callerInfo)
featureName - the name of the desired featurecallerInfo - arbitrary caller info for debugging purposespublic void deRegisterFeatures()
Copyright © 2017. All rights reserved.