Interface ContextPool
public interface ContextPool
Context pool manages contexts of all plugins.
A plugin registers its contexts in its constructor and obtains contexts of other (connected) plugins in
Plugin.initialize().
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T extends Context>
TGet first accessible registered context.<T extends Context>
TGet registered context of a plugin connected to the requesting plugin.default <D> DeviceContext<D> Get first accessible device context with given data type.default <C> MemoryContext<C> Get first accessible memory context with given cell type.voidRegister plugin context.booleanunregister(long pluginID, Class<? extends Context> contextInterface) Unregisters all contexts of the plugin registered under given context interface.
-
Method Details
-
register
Register plugin context.Context interface is the "key" under which the context object is registered. Lookup is by exact interface, so memory and device contexts should be registered also under
MemoryContextorDeviceContext. Contexts registered under the same interface (by any plugin) are indexed from 0 in registration order.- Parameters:
pluginID- owner plugin IDcontext- the context objectcontextInterface- context interface implemented by the context object- Throws:
IllegalArgumentException- if contextInterface is not an interface or context does not implement itIllegalStateException- if the context is already registered
-
unregister
Unregisters all contexts of the plugin registered under given context interface.- Parameters:
pluginID- owner plugin IDcontextInterface- context interface- Returns:
- true if contexts were unregistered, false if there was nothing to unregister
-
get
<T extends Context> T get(long pluginID, Class<T> contextInterface, int index) throws ContextNotFoundException Get registered context of a plugin connected to the requesting plugin.- Type Parameters:
T- context type- Parameters:
pluginID- requesting plugin IDcontextInterface- context interfaceindex- 0-based index of the context object, or -1 for the first accessible one- Returns:
- plugin context
- Throws:
ContextNotFoundException- if the context does not exist or the plugin is not allowed to get it
-
get
default <T extends Context> T get(long pluginID, Class<T> contextInterface) throws ContextNotFoundException Get first accessible registered context. Same asget(pluginID, contextInterface, -1).- Type Parameters:
T- context type- Parameters:
pluginID- requesting plugin IDcontextInterface- context interface- Returns:
- plugin context
- Throws:
ContextNotFoundException- if the context does not exist or the plugin is not allowed to get it
-
getMemory
default <C> MemoryContext<C> getMemory(long pluginID, Class<C> cellType) throws ContextNotFoundException Get first accessible memory context with given cell type.- Type Parameters:
C- memory cell type- Parameters:
pluginID- requesting plugin IDcellType- expected memory cell type- Returns:
- memory context
- Throws:
ContextNotFoundException- if the memory does not exist, is not accessible or has different cell type
-
getDevice
default <D> DeviceContext<D> getDevice(long pluginID, Class<D> dataType) throws ContextNotFoundException Get first accessible device context with given data type.- Type Parameters:
D- device data type- Parameters:
pluginID- requesting plugin IDdataType- expected device data type- Returns:
- device context
- Throws:
ContextNotFoundException- if the device does not exist, is not accessible or has different data type
-