public class OsgiServiceFactoryBean extends AbstractOsgiServiceExporter implements org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, BundleContextAware, org.springframework.beans.factory.FactoryBean<org.osgi.framework.ServiceRegistration>, org.springframework.beans.factory.InitializingBean, org.springframework.core.Ordered
setContextClassLoader(ExportContextClassLoader), since proxying is required, the target class has to meet
certain criterion described in the Spring AOP documentation. In short, final classes are not supported when class
enhancement is used.| Modifier and Type | Class and Description |
|---|---|
private class |
OsgiServiceFactoryBean.Executor
Wrapper around internal commands.
|
private class |
OsgiServiceFactoryBean.PropertiesMonitor
Callback that propagates the changes in the service properties to the registration object.
|
| Modifier and Type | Field and Description |
|---|---|
private java.util.concurrent.atomic.AtomicBoolean |
activated |
private java.lang.ClassLoader |
aopClassLoader
class loader used by the aop infrastructure
|
private org.springframework.beans.factory.BeanFactory |
beanFactory |
private java.lang.String |
beanName
exporter bean name
|
private org.osgi.framework.BundleContext |
bundleContext |
private boolean |
cacheTarget
should the service be cached or not
|
private java.lang.ClassLoader |
classLoader |
private ExportContextClassLoaderEnum |
contextClassLoader |
private ExporterController |
controller
internal behaviour controller
|
private boolean |
hasNamedBean |
private InterfaceDetector |
interfaceDetector |
private java.lang.Class<?>[] |
interfaces |
private java.lang.Object |
lock
synchronization lock
|
private static org.apache.commons.logging.Log |
log |
private ListenerNotifier |
notifier |
private int |
order
Default value is same as non-ordered
|
private ServicePropertiesChangeListener |
propertiesListener |
private OsgiServicePropertiesResolver |
propertiesResolver |
private int |
ranking |
private boolean |
registerAtStartup
register at startup by default
|
private boolean |
registerService
register the service by default
|
private LazyTargetResolver |
resolver |
private ServiceRegistrationWrapper |
safeServiceRegistration |
private java.util.Map |
serviceProperties |
private boolean |
serviceRegistered
registration sanity flag
|
private ServiceRegistrationDecorator |
serviceRegistration |
private java.lang.Object |
target |
private java.lang.String |
targetBeanName |
private java.lang.Class<?> |
targetClass |
| Constructor and Description |
|---|
OsgiServiceFactoryBean() |
| Modifier and Type | Method and Description |
|---|---|
private void |
addBeanFactoryDependency() |
void |
afterPropertiesSet() |
void |
destroy() |
java.lang.String |
getBeanName()
Returns the bean name of this class when configured inside a Spring container.
|
java.lang.Class<?>[] |
getInterfaces()
Returns the interfaces that will be considered when exporting the target as an OSGi service.
|
org.osgi.framework.ServiceRegistration |
getObject()
Returns a
ServiceRegistration to the OSGi service for the target object. |
java.lang.Class<? extends org.osgi.framework.ServiceRegistration> |
getObjectType() |
int |
getOrder() |
int |
getRanking()
Returns the OSGi ranking used when publishing the service.
|
OsgiServicePropertiesResolver |
getResolver()
Returns the property resolver used for publishing the service.
|
java.util.Map |
getServiceProperties()
Returns the properties used when exporting the target as an OSGi service.
|
java.lang.Object |
getTarget()
Returns the object exported as an OSGi service.
|
java.lang.String |
getTargetBeanName()
Returns the target bean name.
|
private boolean |
isBeanBundleScoped() |
boolean |
isSingleton() |
private java.util.Dictionary |
mergeServiceProperties(java.util.Map serviceProperties,
java.lang.String beanName) |
(package private) void |
registerService()
Publishes the given object as an OSGi service.
|
(package private) org.osgi.framework.ServiceRegistration |
registerService(java.lang.Class<?>[] classes,
java.util.Dictionary serviceProperties)
Registration method.
|
void |
setAutoExport(AutoExport classExporter)
Deprecated.
|
void |
setBeanClassLoader(java.lang.ClassLoader classLoader) |
void |
setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) |
void |
setBeanName(java.lang.String name) |
void |
setBundleContext(org.osgi.framework.BundleContext context)
Set the
BundleContext that this bean runs in. |
void |
setCacheTarget(boolean cacheTarget)
Sets the caching of the exported target object.
|
void |
setContextClassLoader(ExportContextClassLoader ccl)
Deprecated.
As of Spring DM 2.0, replaced by
setExportContextClassLoader(ExportContextClassLoaderEnum) |
void |
setExportContextClassLoader(ExportContextClassLoaderEnum ccl)
Sets the context class loader management strategy to use when invoking operations on the exposed target bean.
|
void |
setInterfaceDetector(InterfaceDetector detector)
Sets the strategy used for automatically publishing classes.
|
void |
setInterfaces(java.lang.Class<?>[] interfaces)
Sets the interfaces advertised by the service.These will be advertised in the OSGi space and are considered when
looking for a service.
|
void |
setOrder(int order)
Set the ordering which will apply to this class's implementation of Ordered, used when applying multiple
BeanPostProcessors.
|
void |
setRanking(int ranking)
Shortcut for setting the ranking property of the published service.
|
void |
setRegisterService(boolean register)
Controls whether the service actually gets published or not.
|
void |
setResolver(OsgiServicePropertiesResolver resolver)
Sets the property resolver used when publishing the bean as an OSGi service.
|
void |
setServiceProperties(java.util.Map serviceProperties)
Sets the properties used when exposing the target as an OSGi service.
|
void |
setTarget(java.lang.Object target)
Sets the given object to be export as an OSGi service.
|
void |
setTargetBeanName(java.lang.String name)
Sets the name of the bean managed by the Spring container, which will be exported as an OSGi service.
|
(package private) void |
unregisterService()
Unregisters/de-exports the OSGi service.
|
(package private) void |
unregisterService(org.osgi.framework.ServiceRegistration registration)
Unregisters (literally stops) a service.
|
getLazyListeners, getNotifier, setLazyListeners, setListenersprivate static final org.apache.commons.logging.Log log
private volatile org.osgi.framework.BundleContext bundleContext
private volatile OsgiServicePropertiesResolver propertiesResolver
private volatile org.springframework.beans.factory.BeanFactory beanFactory
private volatile ServiceRegistrationDecorator serviceRegistration
private final ServiceRegistrationWrapper safeServiceRegistration
private volatile java.util.Map serviceProperties
private volatile ServicePropertiesChangeListener propertiesListener
private volatile int ranking
private volatile java.lang.String targetBeanName
private boolean hasNamedBean
private volatile java.lang.Class<?>[] interfaces
private InterfaceDetector interfaceDetector
private volatile ExportContextClassLoaderEnum contextClassLoader
private volatile java.lang.Object target
private volatile java.lang.Class<?> targetClass
private int order
private java.lang.ClassLoader classLoader
private java.lang.ClassLoader aopClassLoader
private java.lang.String beanName
private boolean serviceRegistered
private boolean registerAtStartup
private boolean registerService
private final java.lang.Object lock
private final ExporterController controller
private volatile LazyTargetResolver resolver
private ListenerNotifier notifier
private final java.util.concurrent.atomic.AtomicBoolean activated
private boolean cacheTarget
public void afterPropertiesSet()
throws java.lang.Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanjava.lang.Exceptionpublic void destroy()
destroy in interface org.springframework.beans.factory.DisposableBeandestroy in class AbstractOsgiServiceExporterprivate void addBeanFactoryDependency()
private java.util.Dictionary mergeServiceProperties(java.util.Map serviceProperties,
java.lang.String beanName)
void registerService()
registerService in class AbstractOsgiServiceExporterorg.osgi.framework.ServiceRegistration registerService(java.lang.Class<?>[] classes,
java.util.Dictionary serviceProperties)
classes - serviceProperties - private boolean isBeanBundleScoped()
public void setBeanClassLoader(java.lang.ClassLoader classLoader)
setBeanClassLoader in interface org.springframework.beans.factory.BeanClassLoaderAwarepublic org.osgi.framework.ServiceRegistration getObject()
throws java.lang.Exception
ServiceRegistration to the OSGi service for the target object.getObject in interface org.springframework.beans.factory.FactoryBean<org.osgi.framework.ServiceRegistration>java.lang.Exceptionpublic java.lang.Class<? extends org.osgi.framework.ServiceRegistration> getObjectType()
getObjectType in interface org.springframework.beans.factory.FactoryBean<org.osgi.framework.ServiceRegistration>public boolean isSingleton()
isSingleton in interface org.springframework.beans.factory.FactoryBean<org.osgi.framework.ServiceRegistration>void unregisterService()
AbstractOsgiServiceExporterunregisterService in class AbstractOsgiServiceExportervoid unregisterService(org.osgi.framework.ServiceRegistration registration)
registration - public void setContextClassLoader(ExportContextClassLoader ccl)
setExportContextClassLoader(ExportContextClassLoaderEnum)ExportContextClassLoader.UNMANAGED is used.
Note: Since proxying is required for context class loader manager, the target class has to
meet certain criteria described in the Spring AOP documentation. In short, final classes are not supported when
class enhancement is used.ccl - context class loader strategy to useExportContextClassLoaderpublic void setExportContextClassLoader(ExportContextClassLoaderEnum ccl)
ExportContextClassLoader.UNMANAGED is used.
Note: Since proxying is required for context class loader manager, the target class has to
meet certain criteria described in the Spring AOP documentation. In short, final classes are not supported when
class enhancement is used.ccl - context class loader strategy to useExportContextClassLoaderpublic java.lang.Object getTarget()
public void setTarget(java.lang.Object target)
setTargetBeanName(String) is used.target - the object to be exported as an OSGi servicepublic java.lang.String getTargetBeanName()
public void setTargetBeanName(java.lang.String name)
setTarget(Object).name - target bean namepublic void setAutoExport(AutoExport classExporter)
AutoExport.DISABLED.classExporter - class exporter used for automatically publishing service classes.AutoExportpublic void setInterfaceDetector(InterfaceDetector detector)
DefaultInterfaceDetector.DISABLED.detector - public java.util.Map getServiceProperties()
public void setServiceProperties(java.util.Map serviceProperties)
ServicePropertiesChangeListener), any updates to the properties will be reflected by the service
registration.serviceProperties - properties used for exporting the target as an OSGi servicepublic int getRanking()
public void setRanking(int ranking)
ranking - service rankingConstants.SERVICE_RANKINGpublic void setRegisterService(boolean register)
register - whether to register the service or not. The default is true.public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
throws org.springframework.beans.BeansException
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAwareorg.springframework.beans.BeansExceptionpublic void setBundleContext(org.osgi.framework.BundleContext context)
BundleContextAwareBundleContext that this bean runs in. Normally this can
be used to initialize an object.setBundleContext in interface BundleContextAwarecontext - the BundleContext object to be used
by this objectpublic OsgiServicePropertiesResolver getResolver()
public void setResolver(OsgiServicePropertiesResolver resolver)
resolver - service property resolverpublic java.lang.Class<?>[] getInterfaces()
public void setInterfaces(java.lang.Class<?>[] interfaces)
interfaces - array of classes to advertisepublic int getOrder()
getOrder in interface org.springframework.core.Orderedpublic void setOrder(int order)
Default value is Integer.MAX_VALUE, meaning that it's non-ordered.
order - ordering valuepublic java.lang.String getBeanName()
public void setBeanName(java.lang.String name)
setBeanName in interface org.springframework.beans.factory.BeanNameAwarepublic void setCacheTarget(boolean cacheTarget)