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 Type
    Method
    Description
    default <T extends Context>
    T
    get(long pluginID, Class<T> contextInterface)
    Get first accessible registered context.
    <T extends Context>
    T
    get(long pluginID, Class<T> contextInterface, int index)
    Get registered context of a plugin connected to the requesting plugin.
    default <D> DeviceContext<D>
    getDevice(long pluginID, Class<D> dataType)
    Get first accessible device context with given data type.
    default <C> MemoryContext<C>
    getMemory(long pluginID, Class<C> cellType)
    Get first accessible memory context with given cell type.
    void
    register(long pluginID, Context context, Class<? extends Context> contextInterface)
    Register plugin context.
    boolean
    unregister(long pluginID, Class<? extends Context> contextInterface)
    Unregisters all contexts of the plugin registered under given context interface.
  • Method Details

    • register

      void register(long pluginID, Context context, Class<? extends Context> contextInterface)
      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 MemoryContext or DeviceContext. Contexts registered under the same interface (by any plugin) are indexed from 0 in registration order.

      Parameters:
      pluginID - owner plugin ID
      context - the context object
      contextInterface - context interface implemented by the context object
      Throws:
      IllegalArgumentException - if contextInterface is not an interface or context does not implement it
      IllegalStateException - if the context is already registered
    • unregister

      boolean unregister(long pluginID, Class<? extends Context> contextInterface)
      Unregisters all contexts of the plugin registered under given context interface.
      Parameters:
      pluginID - owner plugin ID
      contextInterface - 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 ID
      contextInterface - context interface
      index - 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 as get(pluginID, contextInterface, -1).
      Type Parameters:
      T - context type
      Parameters:
      pluginID - requesting plugin ID
      contextInterface - 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 ID
      cellType - 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 ID
      dataType - expected device data type
      Returns:
      device context
      Throws:
      ContextNotFoundException - if the device does not exist, is not accessible or has different data type