public interface AspectComponent extends Component
public class Activator extends DependencyActivatorBase { &Override public void init(BundleContext context, DependencyManager dm) throws Exception { AspectComponent aspectComponent = createAspectComponent() .setAspect(Database.class, null, 10) .setImplementation(DatabaseCache.class); dm.add(aspectComponent); } } interface Database { String get(String key); } class DatabaseCache implements Database { volatile Database originalDatabase; // injected String get(String key) { String value = cache.get(key); if (value == null) { value = this.originalDatabase.get(key); store(key, value); } return value; } ... }
For "add", "change", "remove" callbacks, the following method signatures are supported:
(Component comp, ServiceReference ref, Service service)
(Component comp, ServiceReference ref, Object service)
(Component comp, ServiceReference ref)
(Component comp, Service service)
(Component comp, Object service)
(Component comp)
(Component comp, Map properties, Service service)
(ServiceReference ref, Service service)
(ServiceReference ref, Object service)
(ServiceReference ref)
(Service service)
(Service service, Map propeerties)
(Map properties, Service, service)
(Service service, Dictionary properties)
(Dictionary properties, Service service)
(Object service)
For "swap" callbacks, the following method signatures are supported:
(Service old, Service replace)
(Object old, Object replace)
(ServiceReference old, Service old, ServiceReference replace, Service replace)
(ServiceReference old, Object old, ServiceReference replace, Object replace)
(Component comp, Service old, Service replace)
(Component comp, Object old, Object replace)
(Component comp, ServiceReference old, Service old, ServiceReference replace, Service replace)
(Component comp, ServiceReference old, Object old, ServiceReference replace, Object replace)
(ServiceReference old, ServiceReference replace)
(Component comp, ServiceReference old, ServiceReference replace)
Component.ServiceScope
Modifier and Type | Method and Description |
---|---|
AspectComponent |
add(ComponentStateListener listener)
Adds a component state listener to this component.
|
AspectComponent |
add(Dependency... dependencies)
Adds dependency(ies) to this component, atomically.
|
AspectComponent |
remove(ComponentStateListener listener)
Removes a component state listener from this component.
|
AspectComponent |
remove(Dependency d)
Removes a dependency from the component.
|
AspectComponent |
setAspect(java.lang.Class<?> service,
java.lang.String filter,
int ranking)
Sets the service interface to apply the aspect to (required parameter)
|
AspectComponent |
setAspectCallbackInstance(java.lang.Object callbackInstance)
Sets the instance to invoke the callbacks on (optional parameter).
|
AspectComponent |
setAspectCallbacks(java.lang.String add,
java.lang.String change,
java.lang.String remove,
java.lang.String swap)
Sets name of the callbacks method to invoke on add,change,remove, or swap callbacks (optional parameter).
|
AspectComponent |
setAspectField(java.lang.String autoConfig)
Sets the aspect implementation field name where to inject original service (optional parameter).
|
AspectComponent |
setAutoConfig(java.lang.Class<?> clazz,
boolean autoConfig)
Configures auto configuration of injected classes in the component instance.
|
AspectComponent |
setAutoConfig(java.lang.Class<?> clazz,
java.lang.String instanceName)
Configures auto configuration of injected classes in the component instance.
|
AspectComponent |
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.
|
AspectComponent |
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.
|
AspectComponent |
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.
|
AspectComponent |
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.
|
AspectComponent |
setDebug(java.lang.String label)
Activate debug for this component.
|
AspectComponent |
setFactory(java.lang.Object factory,
java.lang.String createMethod)
Sets the factory to use to create the implementation.
|
AspectComponent |
setFactory(java.lang.String createMethod)
Sets the factory to use to create the implementation.
|
AspectComponent |
setImplementation(java.lang.Object implementation)
Sets the implementation for this component.
|
AspectComponent |
setInterface(java.lang.Class<?>[] serviceNames,
java.util.Dictionary<?,?> properties)
Sets the public interfaces under which this component should be registered
in the OSGi service registry.
|
AspectComponent |
setInterface(java.lang.Class<?> serviceName,
java.util.Dictionary<?,?> properties)
Sets the public interface under which this component should be registered
in the OSGi service registry.
|
AspectComponent |
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.
|
AspectComponent |
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.
|
AspectComponent |
setScope(Component.ServiceScope scope)
Sets the component scope.
|
AspectComponent |
setServiceProperties(java.util.Dictionary<?,?> serviceProperties)
Sets the service properties associated with the component.
|
getComponentDeclaration, getDependencyManager, getInstance, getInstances, getServiceProperties, getServiceRegistration
AspectComponent setScope(Component.ServiceScope scope)
AspectComponent 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
removedsetImplementation
in interface Component
implementation
- the implementationComponentStateListener
AspectComponent add(Dependency... dependencies)
AspectComponent remove(Dependency d)
AspectComponent add(ComponentStateListener listener)
AspectComponent remove(ComponentStateListener listener)
AspectComponent setInterface(java.lang.String serviceName, java.util.Dictionary<?,?> properties)
setInterface
in interface Component
serviceName
- the name of the service interfaceproperties
- the properties for this serviceAspectComponent setInterface(java.lang.String[] serviceNames, java.util.Dictionary<?,?> properties)
setInterface
in interface Component
serviceNames
- the names of the service interfaceproperties
- the properties for these servicesAspectComponent setInterface(java.lang.Class<?> serviceName, java.util.Dictionary<?,?> properties)
setInterface
in interface Component
serviceName
- the name of the service interfaceproperties
- the properties for this serviceAspectComponent setInterface(java.lang.Class<?>[] serviceNames, java.util.Dictionary<?,?> properties)
setInterface
in interface Component
serviceNames
- the names of the service interfaceproperties
- the properties for these servicesAspectComponent setAutoConfig(java.lang.Class<?> clazz, boolean autoConfig)
setAutoConfig
in interface Component
clazz
- the class (from the list above)autoConfig
- false
to turn off auto configurationAspectComponent setAutoConfig(java.lang.Class<?> clazz, java.lang.String instanceName)
setAutoConfig
in interface Component
clazz
- the class (from the list above)instanceName
- the name of the instance to inject the class intosetAutoConfig(Class, boolean)
AspectComponent setServiceProperties(java.util.Dictionary<?,?> serviceProperties)
setServiceProperties
in interface Component
serviceProperties
- the propertiesAspectComponent setCallbacks(java.lang.String init, java.lang.String start, java.lang.String stop, java.lang.String destroy)
setCallbacks
in interface Component
init
- the name of the init methodstart
- the name of the start methodstop
- the name of the stop methoddestroy
- the name of the destroy methodAspectComponent 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.
setCallbacks
in interface Component
AspectComponent 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
.setFactory
in interface Component
factory
- the factory instance or classcreateMethod
- the name of the create methodAspectComponent 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.
setFactory
in interface Component
createMethod
- the name of the create methodAspectComponent setComposition(java.lang.Object instance, java.lang.String getMethod)
Object[]
.setComposition
in interface Component
instance
- the instance that has the methodgetMethod
- the method to invokeAspectComponent setComposition(java.lang.String getMethod)
Object[]
.setComposition
in interface Component
getMethod
- the method to invokeAspectComponent setDebug(java.lang.String label)
AspectComponent setAspect(java.lang.Class<?> service, java.lang.String filter, int ranking)
service
- the service interface to apply the aspect tofilter
- the filter condition to use with the service aspect interface (null if no filter)ranking
- the level used to organize the aspect chain orderingAspectComponent setAspectField(java.lang.String autoConfig)
autoConfig
- the aspect implementation field name where to inject original serviceAspectComponent setAspectCallbacks(java.lang.String add, java.lang.String change, java.lang.String remove, java.lang.String swap)
add
- name of the callback method to invoke on addchange
- name of the callback method to invoke on changeremove
- name of the callback method to invoke on removeswap
- name of the callback method to invoke on swapAspectComponent setAspectCallbackInstance(java.lang.Object callbackInstance)
callbackInstance
- the instance to invoke the callbacks on