Class CommandBridgeProvider
CommandBridgeAPI singleton
instance.
CommandBridge registers its implementation when the plugin enables.
Third-party plugins
retrieve the instance by calling get() or get(Class) for
platform-specific
subtypes. The provider holds a single volatile reference accessible across
threads.
This class cannot be instantiated. All access is through static methods.
To obtain the API instance:
CommandBridgeAPI api = CommandBridgeProvider.get();
To access a platform-specific subtype, pass the expected class to
get(Class).
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic CommandBridgeAPIget()Returns the registeredCommandBridgeAPIinstance.static <T extends CommandBridgeAPI>
TReturns the registeredCommandBridgeAPIinstance cast to the specified subtype.static voidregister(CommandBridgeAPI impl) Registers theCommandBridgeAPIimplementation.static voidClears the registeredCommandBridgeAPIimplementation.
-
Method Details
-
get
Returns the registeredCommandBridgeAPIinstance.This method is safe to call from any thread after CommandBridge has enabled.
- Returns:
- the registered
CommandBridgeAPIinstance; nevernull - Throws:
IllegalStateException- if CommandBridge is not installed, not yet enabled, or the API has not been registered- See Also:
-
get
Returns the registeredCommandBridgeAPIinstance cast to the specified subtype.Use this method when accessing a platform-specific extension of the API. The cast is validated at runtime; if the registered instance does not implement the requested type, an
IllegalStateExceptionis thrown.- Type Parameters:
T- the expected API subtype; must extendCommandBridgeAPI- Parameters:
type- theClasstoken of the expected subtype; must not benull- Returns:
- the API instance cast to
T; nevernull - Throws:
IllegalStateException- if the API is not registered, or if the registered instance is not an instance oftype- See Also:
-
register
Registers theCommandBridgeAPIimplementation.This method is called internally by the CommandBridge plugin during startup and is not intended for use by third-party plugins.
- Parameters:
impl- the implementation to register; must not benull- Throws:
IllegalStateException- if an implementation is already registeredNullPointerException- ifimplisnull
-
unregister
public static void unregister()Clears the registeredCommandBridgeAPIimplementation.Called internally by the CommandBridge plugin during shutdown. After this method returns, calls to
get()will throwIllegalStateExceptionuntil a new implementation is registered.
-