Package org.apache.felix.dm.context
Interface ComponentContext
- All Superinterfaces:
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.felix.dm.Component
Component.ServiceScope -
Method Summary
Modifier and TypeMethodDescription<U> UcreateConfigurationType(Class<U> type, Dictionary<?, ?> config) Creates a configuration for a given type backed by a given dictionary.booleangetAutoConfig(Class<?> clazz) Indicates if an object of the given class can be injected in one field of the componentgetAutoConfigInstance(Class<?> clazz) Returns the component instance field that is assignable to a given class typeorg.osgi.framework.BundleReturns the Compoent's bundle.org.osgi.framework.BundleContextReturns the Component's bundle contextReturns the list of dependencies that has been registered on this componentReturns the highest ranked dependency service instance for a given dependencyReturns all the available dependency services for a given dependencyReturns the Component Executor gate that can be used to ensure proper component event serialization.Object[]Returns the component instancesReturns the logger which can be used by the DependencyManager Dependencies implementations.voidhandleEvent(DependencyContext dc, EventType type, Event... event) Notifies the Component about a dependency event.booleanIndicates if the component fields and methods injections are disabled.Instantiates the component instances.voidinvokeCallback(Object[] instances, String methodName, Class<?>[][] signatures, Supplier<?>[][] paramsSupplier, boolean logIfNotFound) Invokes a callback method on a given set of objects.voidinvokeCallbackMethod(Object[] instances, String methodName, Class<?>[][] signatures, Object[][] parameters) Invokes a callback method on a given set of objects.voidinvokeCallbackMethod(Object[] instances, String methodName, Class<?>[][] signatures, Object[][] parameters, boolean logIfNotFound) Invokes a callback method on a given set of objects.booleanisActive()Is this component already started ?booleanIs this component available (all required dependencies are available) ?voidsetThreadPool(Executor threadPool) Sets a threadpool that the component will use when handling external eventsvoidstart()Starts the component.voidstop()Stops the component.Methods inherited from interface org.apache.felix.dm.Component
add, add, getComponentDeclaration, getDependencyManager, getInstance, getServiceProperties, getServiceRegistration, remove, remove, setAutoConfig, setAutoConfig, setCallbacks, setCallbacks, setComposition, setComposition, setDebug, setFactory, setFactory, setImplementation, setInterface, setInterface, setInterface, setInterface, setScope, setServiceProperties
-
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
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
Notifies the Component about a dependency event. An event is for example fired when:- a dependency service becomes available
EventType.ADDED) - a dependenc service has changed is changed
EventType.CHANGED) - a dependency service has been lost
EventType.REMOVED) - a dependency service has been swapped by another
EventType.SWAPPED)
- Parameters:
dc- the dependencytype- the dependency event typee- the dependency event- See Also:
- a dependency service becomes available
-
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 instancesmethodName- the method namesignatures- 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 instancesmethodName- the method namesignatures- the method signatures (types)parameters- the method parameterslogIfNotFound- 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 instancesmethodName- the method namesignatures- the method signatures (types)paramsSupplier- the supplier for the method parameterslogIfNotFound- 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:
getInstancesin interfaceComponent- Returns:
- the component instances
-
getAutoConfigInstance
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
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
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
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
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 benull;config- the configuration to wrap, cannot benull.- 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.
-