org.springframework.osgi.service.importer.support
Class OsgiServiceProxyFactoryBean

java.lang.Object
  extended by org.springframework.osgi.service.importer.support.AbstractOsgiServiceImportFactoryBean
      extended by org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean
All Implemented Interfaces:
BeanClassLoaderAware, BeanNameAware, DisposableBean, FactoryBean, InitializingBean, SmartFactoryBean, ApplicationEventPublisherAware, BundleContextAware

public final class OsgiServiceProxyFactoryBean
extends AbstractOsgiServiceImportFactoryBean
implements ApplicationEventPublisherAware

OSGi (single) service importer. This implementation creates a managed OSGi service proxy that handles the OSGi service dynamics. The returned proxy will select only the best matching OSGi service for the configuration criteria. If the select service goes away (at any point in time), the proxy will automatically search for a replacement without the user intervention.

Note that the proxy instance remains the same and only the backing OSGi service changes. Due to the dynamic nature of OSGi, the backing object can change during method invocations.

Author:
Costin Leau, Adrian Colyer, Hal Hildebrand

Constructor Summary
OsgiServiceProxyFactoryBean()
           
 
Method Summary
 void afterPropertiesSet()
           
 void destroy()
           
 Object getObject()
          Returns a managed object for accessing OSGi service(s). Returns a managed proxy to the best matching OSGi service.
 Class getObjectType()
           Returns the managed proxy type.
 long getTimeout()
          Returns the timeout (in milliseconds) this importer waits while trying to find a backing service.
 boolean isEagerInit()
           The object created by this factory bean is eagerly initialized.
 boolean isPrototype()
           The object returned by this FactoryBean is a not a prototype.
 boolean isSingleton()
           The object managed by this factory is a singleton.
 void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
           
 void setBeanClassLoader(ClassLoader classLoader)
           This method is called automatically by the container. The class will automatically chain this classloader with the AOP infrastructure classes (even if these are not visible to the user) so that the proxy creation can be completed successfully.
 void setCardinality(Cardinality cardinality)
          Sets the importer cardinality (0..1, 1..1, 0..N, or 1..N).

Since this implementation creates a managed proxy, only single cardinalities are accepted.

 void setTimeout(long timeoutInMillis)
          Sets how long (in milliseconds) should this importer wait between failed attempts at rebinding to a service that has been unregistered.
 
Methods inherited from class org.springframework.osgi.service.importer.support.AbstractOsgiServiceImportFactoryBean
getBeanClassLoader, getBeanName, getBundleContext, getCardinality, getContextClassLoader, getFilter, getInterfaces, getListeners, getUnifiedFilter, setBeanName, setBundleContext, setContextClassLoader, setFilter, setInterfaces, setListeners, setServiceBeanName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OsgiServiceProxyFactoryBean

public OsgiServiceProxyFactoryBean()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface InitializingBean

getObjectType

public Class getObjectType()
Returns the managed proxy type. If the proxy is not created when this method is invoked, the method will try to create a composite interface (if only interfaces are specified) or null otherwise.

Specified by:
getObjectType in interface FactoryBean

getObject

public Object getObject()
Returns a managed object for accessing OSGi service(s). Returns a managed proxy to the best matching OSGi service.

Specified by:
getObject in interface FactoryBean
Returns:
managed OSGi service(s)

setTimeout

public void setTimeout(long timeoutInMillis)
Sets how long (in milliseconds) should this importer wait between failed attempts at rebinding to a service that has been unregistered.

It is possible to change this value after initialization (while the proxy is in place). The new values will be used immediately by the proxy. Any in-flight waiting will be restarted using the new values. Note that if both values are the same, no restart will be applied.

Parameters:
timeoutInMillis - Timeout to set, in milliseconds

getTimeout

public long getTimeout()
Returns the timeout (in milliseconds) this importer waits while trying to find a backing service.

Returns:
timeout in milliseconds

setCardinality

public void setCardinality(Cardinality cardinality)
Sets the importer cardinality (0..1, 1..1, 0..N, or 1..N). Default is 1..X.

Since this implementation creates a managed proxy, only single cardinalities are accepted.

Overrides:
setCardinality in class AbstractOsgiServiceImportFactoryBean
Parameters:
cardinality - importer cardinality.

setApplicationEventPublisher

public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
Specified by:
setApplicationEventPublisher in interface ApplicationEventPublisherAware

destroy

public void destroy()
             throws Exception
Specified by:
destroy in interface DisposableBean
Throws:
Exception

isSingleton

public boolean isSingleton()
The object managed by this factory is a singleton.

Specified by:
isSingleton in interface FactoryBean
Returns:
true (i.e. the FactoryBean returns singletons)

isEagerInit

public boolean isEagerInit()
The object created by this factory bean is eagerly initialized.

Specified by:
isEagerInit in interface SmartFactoryBean
Returns:
true (this factory bean should be eagerly initialized)

isPrototype

public boolean isPrototype()
The object returned by this FactoryBean is a not a prototype.

Specified by:
isPrototype in interface SmartFactoryBean
Returns:
false (the managed object is not a prototype)

setBeanClassLoader

public void setBeanClassLoader(ClassLoader classLoader)
This method is called automatically by the container. The class will automatically chain this classloader with the AOP infrastructure classes (even if these are not visible to the user) so that the proxy creation can be completed successfully.

Specified by:
setBeanClassLoader in interface BeanClassLoaderAware
Overrides:
setBeanClassLoader in class AbstractOsgiServiceImportFactoryBean


Copyright © 2006-2009 Spring Framework. All Rights Reserved.