Class BeanConfigurationServiceRegistrationListener
BeanConfiguration objects,
so they can be used to dynamically configure and publish other OSGi services.
This object acts like a dynamic OSGi service factory. You configure the type
of service this factory should create, and when BeanConfiguration are
found new instances of the service will be created and configured from the
discovered BeanConfiguration. This allows the bundle the
configuration came from to be completely isolated and unaware of the
implementation bundle using that configuration.
The BeanConfiguration.getConfiguration() Map will be used to
configure the properties on instantiated service objects. The keys of this
Map should be standard Spring JavaBean property names.
The BeanConfiguration.getAttributes() Map will be used to create OSGi
service properties when the service is registered.
The BeanConfiguration.getOrdering() Integer will be used to assign an
OSGi ranking to the service when it is registered.
When the BeanConfiguration is unregistered and the
onUnbind(BeanConfiguration, Map) method is called, the associated
service created by this factory will be unregistered as well.
For example, this might be configured via Spring DM like this:
<osgi:list id="myConfigurationList"
interface="net.solarnetwork.node.util.BeanConfiguration" cardinality="0..N">
<osgi:listener bind-method="onBind" unbind-method="onUnbind" ref="myServiceBean"/>
</osgi:list>
<bean id="myServiceBean"
class="net.solarnetwork.node.util.BeanConfigurationServiceRegistrationListener">
<property name="serviceClass"
value="net.solarnetwork.node.impl.MyServiceImplementation"/>
<property name="serviceInterfaces"
value="net.solarnetwork.node.MyService"/>
<property name="bundleContext" ref="bundleContext"/>
</bean>
- Version:
- 2.0
- Author:
- matt
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA registered service for bean configurations. -
Field Summary
Fields inherited from class net.solarnetwork.common.osgi.service.BaseServiceListener
log -
Constructor Summary
ConstructorsConstructorDescriptionBeanConfigurationServiceRegistrationListener(org.osgi.framework.BundleContext bundleContext) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionClass<?>Get the type of service to create whenonBind(BeanConfiguration, Map)is called.String[]Get the array of interface names to register the OSGi service as.Get an optional Map of properties to register the OSGi service with.voidonBind(BeanConfiguration config, Map<String, ?> properties) Callback when an object has been registered.voidonUnbind(BeanConfiguration config, Map<String, ?> properties) Callback when a trigger has been un-registered.voidsetServiceClass(Class<?> serviceClass) Set the type of service to create whenonBind(BeanConfiguration, Map)is called.voidsetServiceInterfaces(String[] serviceInterfaces) Set the array of interface names to register the OSGi service as.voidsetServiceProperties(Map<String, Object> serviceProperties) Set an optional Map of properties to register the OSGi service with.Methods inherited from class net.solarnetwork.common.osgi.service.BaseServiceListener
addRegisteredService, addRegisteredService, getBundleContext, getRegisteredServices, removeRegisteredService
-
Constructor Details
-
BeanConfigurationServiceRegistrationListener
public BeanConfigurationServiceRegistrationListener(org.osgi.framework.BundleContext bundleContext) Constructor.- Parameters:
bundleContext- the bundle context- Throws:
IllegalArgumentException- if any argument is null
-
-
Method Details
-
onBind
Callback when an object has been registered.This method will instantiate a new instance of
getServiceClass()and configure its properties via the Map returned byBeanConfiguration.getConfiguration(). Afterwards it will register the instance as a service, using thegetServiceInterfaces()as the service interfaces andgetServiceProperties()as the service properties (if available) combined with theBeanConfiguration.getAttributes()(if available).- Parameters:
config- the configuration objectproperties- the service properties
-
onUnbind
Callback when a trigger has been un-registered.This method will attempt to un-register a previously registered service.
- Parameters:
config- the configuration objectproperties- the service properties
-
getServiceClass
Get the type of service to create whenonBind(BeanConfiguration, Map)is called.- Returns:
- the type of service
-
setServiceClass
Set the type of service to create whenonBind(BeanConfiguration, Map)is called.- Parameters:
serviceClass- the type of service
-
getServiceInterfaces
Get the array of interface names to register the OSGi service as.- Returns:
- the interfaces to adopt
-
setServiceInterfaces
Set the array of interface names to register the OSGi service as.- Parameters:
serviceInterfaces- the interfaces to adopt
-
getServiceProperties
Get an optional Map of properties to register the OSGi service with.- Returns:
- the optional properties
-
setServiceProperties
Set an optional Map of properties to register the OSGi service with.- Parameters:
serviceProperties- the optional properties
-