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<Object>, InitializingBean, SmartFactoryBean<Object>, 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).
 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.
 void setBlueprintCompliant(boolean compliant)
          Indicates whether the importer should use (strict) blueprint spec compliance or not.
 void setSticky(boolean sticky)
          Sets the stickiness of this proxy.
 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.
 void setUseBlueprintExceptions(boolean useBlueprintExceptions)
          Indicates whether Blueprint exceptions are preferred over Spring DM ones.
 
Methods inherited from class org.springframework.osgi.service.importer.support.AbstractOsgiServiceImportFactoryBean
getAvailability, getBeanClassLoader, getBeanName, getBundleContext, getCardinality, getContextClassLoader, getFilter, getImportContextClassLoader, getInterfaces, getListeners, getUnifiedFilter, setAvailability, setBeanName, setBundleContext, setCardinality, setContextClassLoader, setFilter, setImportContextClassLoader, 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

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<Object>
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

setSticky

public void setSticky(boolean sticky)
Sets the stickiness of this proxy. If 'true' (default), the proxy will rebind only if the backing service is no longer available. If 'false', the rebind will occur every time a 'better' candidate appears. A better service is defined by having either a higher ranking or the same ranking and a lower service id.

Parameters:
sticky - sticky flag

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

getObjectType

public Class<?> getObjectType()
Returns the managed proxy type. Note that calling this method will cause the creation of the proxy but not its initialization.

Specified by:
getObjectType in interface FactoryBean<Object>

isSingleton

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

Specified by:
isSingleton in interface FactoryBean<Object>
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<Object>
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<Object>
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

setUseBlueprintExceptions

public void setUseBlueprintExceptions(boolean useBlueprintExceptions)
Indicates whether Blueprint exceptions are preferred over Spring DM ones.

Parameters:
useBlueprintExceptions -

setBlueprintCompliant

public void setBlueprintCompliant(boolean compliant)
Indicates whether the importer should use (strict) blueprint spec compliance or not. Strict compliance means that only interfaces are supported and that Blueprint exceptions are thrown by default.

Parameters:
compliant -


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