public interface Component
Modifier and Type | Method and Description |
---|---|
Component |
add(ComponentStateListener listener)
Adds a component state listener to this component.
|
Component |
add(Dependency... dependencies)
Adds dependency(ies) to this component, atomically.
|
ComponentDeclaration |
getComponentDeclaration()
Returns the component description (dependencies, service provided, etc ...).
|
DependencyManager |
getDependencyManager()
Returns the dependency manager associated with this component.
|
<T> T |
getInstance()
Returns the instance that make up this component.
|
java.lang.Object[] |
getInstances()
Returns the composition instances that make up this component, or just the
component instance if it does not have a composition, or an empty array if
the component has not even been instantiated.
|
<K,V> java.util.Dictionary<K,V> |
getServiceProperties()
Returns the service properties associated with the component.
|
ServiceRegistration |
getServiceRegistration()
Returns the service registration for this component.
|
Component |
remove(ComponentStateListener listener)
Removes a component state listener from this component.
|
Component |
remove(Dependency d)
Removes a dependency from the component.
|
Component |
setAutoConfig(java.lang.Class<?> clazz,
boolean autoConfig)
Configures auto configuration of injected classes in the component instance.
|
Component |
setAutoConfig(java.lang.Class<?> clazz,
java.lang.String instanceName)
Configures auto configuration of injected classes in the component instance.
|
Component |
setCallbacks(java.lang.Object instance,
java.lang.String init,
java.lang.String start,
java.lang.String stop,
java.lang.String destroy)
Sets the names of the methods used as callbacks.
|
Component |
setCallbacks(java.lang.String init,
java.lang.String start,
java.lang.String stop,
java.lang.String destroy)
Sets the names of the methods used as callbacks.
|
Component |
setComposition(java.lang.Object instance,
java.lang.String getMethod)
Sets the instance and method to invoke to get back all instances that
are part of a composition and need dependencies injected.
|
Component |
setComposition(java.lang.String getMethod)
Sets the method to invoke on the service implementation to get back all
instances that are part of a composition and need dependencies injected.
|
Component |
setDebug(java.lang.String label)
Activate debug for this component.
|
Component |
setFactory(java.lang.Object factory,
java.lang.String createMethod)
Sets the factory to use to create the implementation.
|
Component |
setFactory(java.lang.String createMethod)
Sets the factory to use to create the implementation.
|
Component |
setImplementation(java.lang.Object implementation)
Sets the implementation for this component.
|
Component |
setInterface(java.lang.String[] serviceNames,
java.util.Dictionary<?,?> properties)
Sets the public interfaces under which this component should be registered
in the OSGi service registry.
|
Component |
setInterface(java.lang.String serviceName,
java.util.Dictionary<?,?> properties)
Sets the public interface under which this component should be registered
in the OSGi service registry.
|
Component |
setServiceProperties(java.util.Dictionary<?,?> serviceProperties)
Sets the service properties associated with the component.
|
Component setImplementation(java.lang.Object implementation)
Class
that will be instantiated using its default constructor when the
required dependencies are resolved, effectively giving you a lazy
instantiation mechanism.
There are four special methods that are called when found through
reflection to give you life cycle management options:
init()
is invoked after the instance has been
created and dependencies have been resolved, and can be used to
initialize the internal state of the instance or even to add more
dependencies based on runtime statestart()
is invoked right before the service is
registeredstop()
is invoked right after the service is
unregistereddestroy()
is invoked after all dependencies are
removedimplementation
- the implementationComponentStateListener
Component add(Dependency... dependencies)
dependencies
- the dependencies to add.Component remove(Dependency d)
d
- the dependency to removeComponent add(ComponentStateListener listener)
listener
- the state listenerComponent remove(ComponentStateListener listener)
listener
- the state listenerComponent setInterface(java.lang.String serviceName, java.util.Dictionary<?,?> properties)
serviceName
- the name of the service interfaceproperties
- the properties for this serviceComponent setInterface(java.lang.String[] serviceNames, java.util.Dictionary<?,?> properties)
serviceNames
- the names of the service interfaceproperties
- the properties for these servicesComponent setAutoConfig(java.lang.Class<?> clazz, boolean autoConfig)
clazz
- the class (from the list above)autoConfig
- false
to turn off auto configurationComponent setAutoConfig(java.lang.Class<?> clazz, java.lang.String instanceName)
clazz
- the class (from the list above)instanceName
- the name of the instance to inject the class intosetAutoConfig(Class, boolean)
ServiceRegistration getServiceRegistration()
null
if no service registration is
available, for example if this component is not registered as a
service at all.<T> T getInstance()
java.lang.Object[] getInstances()
<K,V> java.util.Dictionary<K,V> getServiceProperties()
null
if there are noneComponent setServiceProperties(java.util.Dictionary<?,?> serviceProperties)
serviceProperties
- the propertiesComponent setCallbacks(java.lang.String init, java.lang.String start, java.lang.String stop, java.lang.String destroy)
init
- the name of the init methodstart
- the name of the start methodstop
- the name of the stop methoddestroy
- the name of the destroy methodComponent setCallbacks(java.lang.Object instance, java.lang.String init, java.lang.String start, java.lang.String stop, java.lang.String destroy)
See setCallbacks(String init, String start, String stop, String destroy) for more information on the signatures. Specifying an instance means you can create a manager that will be invoked whenever the life cycle of a component changes and this manager can then decide how to expose this life cycle to the actual component, offering an important indirection when developing your own component models.
Component setFactory(java.lang.Object factory, java.lang.String createMethod)
setComposition
to create a
composition of instances that work together to implement a component. The
factory itself can also be instantiated lazily by not specifying an
instance, but a Class
.factory
- the factory instance or classcreateMethod
- the name of the create methodComponent setFactory(java.lang.String createMethod)
setComposition
to create a composition of instances that
work together to implement a component.
Note that currently, there is no default for the factory, so please use
setFactory(factory, createMethod)
instead.
createMethod
- the name of the create methodComponent setComposition(java.lang.Object instance, java.lang.String getMethod)
Object[]
.instance
- the instance that has the methodgetMethod
- the method to invokeComponent setComposition(java.lang.String getMethod)
Object[]
.getMethod
- the method to invokeDependencyManager getDependencyManager()
ComponentDeclaration getComponentDeclaration()
Component setDebug(java.lang.String label)
label
-