Interface ComponentContext

All Superinterfaces:
Component

@ProviderType public interface ComponentContext extends Component
This interface is the entry point to the Component implementation context. It is used by all DependencyManager Dependency implementations.
Author:
Felix Project Team
See Also:
  • Method Details

    • getExecutor

      Executor getExecutor()
      Returns the Component Executor gate that can be used to ensure proper component event serialization. When you schedule a task in the component executor, your task is executed safely and you do not need to managed synchronization (other external events, like service dependency events) will be queued until your task has been executed).
    • getLogger

      Logger getLogger()
      Returns the logger which can be used by the DependencyManager Dependencies implementations.
    • getBundleContext

      org.osgi.framework.BundleContext getBundleContext()
      Returns the Component's bundle context
      Returns:
      the Component's bundle context
    • getBundle

      org.osgi.framework.Bundle getBundle()
      Returns the Compoent's bundle.
      Returns:
      the Compoent's bundle.
    • setThreadPool

      void setThreadPool(Executor threadPool)
      Sets a threadpool that the component will use when handling external events
      Parameters:
      threadPool - a threadpool used to handle component events and invoke the component's lifecycle callbacks
    • start

      void start()
      Starts the component. All initial dependencies previously added to the component will be started.
    • stop

      void stop()
      Stops the component.
    • isActive

      boolean isActive()
      Is this component already started ?
      Returns:
      true if this component has been started
    • isAvailable

      boolean isAvailable()
      Is this component available (all required dependencies are available) ?
      Returns:
      true if this component is available (all dependencies are available), or false
    • handleEvent

      void handleEvent(DependencyContext dc, EventType type, Event... event)
      Notifies the Component about a dependency event. An event is for example fired when:

      Parameters:
      dc - the dependency
      type - the dependency event type
      e - the dependency event
      See Also:
    • getDependencies

      List<DependencyContext> getDependencies()
      Returns the list of dependencies that has been registered on this component
      Returns:
      the list of dependencies that has been registered on this component
    • invokeCallbackMethod

      void invokeCallbackMethod(Object[] instances, String methodName, Class<?>[][] signatures, Object[][] parameters)
      Invokes a callback method on a given set of objects. An error is logged if the callback is not found in any of the object instances.
      Parameters:
      instances - the component instances
      methodName - the method name
      signatures - the method signatures (types)
      parameters - the method parameters
    • invokeCallbackMethod

      void invokeCallbackMethod(Object[] instances, String methodName, Class<?>[][] signatures, Object[][] parameters, boolean logIfNotFound)
      Invokes a callback method on a given set of objects.
      Parameters:
      instances - the component instances
      methodName - the method name
      signatures - the method signatures (types)
      parameters - the method parameters
      logIfNotFound - true if a warning message should be logged in case the callback is not found in any of the object instances.
    • invokeCallback

      void invokeCallback(Object[] instances, String methodName, Class<?>[][] signatures, Supplier<?>[][] paramsSupplier, boolean logIfNotFound)
      Invokes a callback method on a given set of objects. An error is logged if the callback is not found in any of the object instances.
      Parameters:
      instances - the component instances
      methodName - the method name
      signatures - the method signatures (types)
      paramsSupplier - the supplier for the method parameters
      logIfNotFound - true if a warning message should be logged in case the callback is not found in any of the object instances.
    • getInstances

      Object[] getInstances()
      Returns the component instances
      Specified by:
      getInstances in interface Component
      Returns:
      the component instances
    • getAutoConfigInstance

      String getAutoConfigInstance(Class<?> clazz)
      Returns the component instance field that is assignable to a given class type
      Parameters:
      clazz - the type of an object that has to be injected in the component instance field
      Returns:
      the name of the component instance field that can be assigned to an object having the same type as the "clazz" parameter
    • getAutoConfig

      boolean getAutoConfig(Class<?> clazz)
      Indicates if an object of the given class can be injected in one field of the component
      Parameters:
      clazz - the class of an object that has to be injected in one of the component fields
      Returns:
      true if the component can be injected with an object having the specified "clazz" type.
    • getDependencyEvent

      Event getDependencyEvent(DependencyContext dc)
      Returns the highest ranked dependency service instance for a given dependency
      Parameters:
      dc - the dependency
      Returns:
      the highest ranked dependency service instance for a given dependency
    • getDependencyEvents

      Set<Event> getDependencyEvents(DependencyContext dc)
      Returns all the available dependency services for a given dependency
      Parameters:
      dc - the dependency
      Returns:
      all the available dependency services for a given dependency
    • createConfigurationType

      <U> U createConfigurationType(Class<U> type, Dictionary<?,?> config)
      Creates a configuration for a given type backed by a given dictionary. This method can be used by any custom Dependency Manager dependency that needs to expose some configuration through a dynamic proxy interface.
      Parameters:
      type - the configuration class, cannot be null;
      config - the configuration to wrap, cannot be null.
      Returns:
      an instance of the given type that wraps the given configuration.
    • instantiateComponent

      ComponentContext instantiateComponent()
      Instantiates the component instances.
      Returns:
      this component context.
    • injectionDisabled

      boolean injectionDisabled()
      Indicates if the component fields and methods injections are disabled.