|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.osgi.service.importer.support.AbstractOsgiServiceImportFactoryBean org.springframework.osgi.service.importer.support.OsgiServiceCollectionProxyFactoryBean
public final class OsgiServiceCollectionProxyFactoryBean
OSGi service (collection) importer. This implementation creates a managed (read-only) collection of OSGi services. The returned collection automatically handles the OSGi services dynamics. If a new service that matches the configuration criteria appears, it will be automatically added to the collection. If a service that matches the criteria disappears (is unregistered), it will be automatically removed from the collection.
Due to the dynamic nature of OSGi services, the collection content can change at runtime, even during iteration. This implementation will correctly update all the collectionIterator
s so they reflect the collection
content. This approach (as opposed to the 'snapshot' strategy) prevents dealing with dead services which can
appear when imported services go down while iterating. This means that iterating while the collection is being
changed is safe.
Note that the Iterator
still has to be fulfilled meaning the next()
method always obey
the result of the previous hasNext()
invocation:
hasNext() returned value | next() behaviour |
---|---|
true | Always return a non-null value, even when the collection has shrunk as services when away. This means returning a proxy that will throw an exception on an invocation that requires the backing service to be present. |
false | per Iterator
contract, NoSuchElementException is thrown. This applies even if other services are added to the
collection. |
hasNext()
invocation made on the same Iterator
can
return different values based on the services availability. However, as explained above, next()
will
always obey the result of the last hasNext()
method.
Note: Even though the collection and its iterators communicate in a thread-safe manner,
iterators themselves are not thread-safe. Concurrent access on the iterators should be properly synchronized. Due to
the light nature of the iterators, consider creating a new one rather then reusing or sharing.
Iterator
,
Collection
,
List
,
Set
,
SortedSet
Field Summary | |
---|---|
protected Object |
proxy
|
Constructor Summary | |
---|---|
OsgiServiceCollectionProxyFactoryBean()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
|
void |
destroy()
|
MemberType |
getMemberType()
Sets the member type of this service collection. |
Object |
getObject()
Returns a managed object for accessing OSGi service(s). |
Class<?> |
getObjectType()
Returns the managed proxy type. |
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 |
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 |
setBlueprintCompliant(boolean compliant)
Indicates whether the importer should use (strict) blueprint spec compliance or not. |
void |
setCollectionType(CollectionType collectionType)
Sets the collection type this FactoryBean will produce. |
void |
setComparator(Comparator comparator)
Sets the (optional) comparator for ordering the resulting collection. |
void |
setGreedyProxying(boolean greedyProxying)
Dictates whether greedy proxies are created or not (default). |
void |
setMemberType(MemberType type)
Sets the member type of this service collection. |
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 |
Field Detail |
---|
protected Object proxy
Constructor Detail |
---|
public OsgiServiceCollectionProxyFactoryBean()
Method Detail |
---|
public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
public void setComparator(Comparator comparator)
comparator
- Comparator (can be null) used for ordering the resulting collection.setCollectionType(CollectionType)
public void setCollectionType(CollectionType collectionType)
collectionType
- the collection type as string using one of the values above.setComparator(Comparator)
,
Comparable
,
Comparator
,
CollectionType
public void setGreedyProxying(boolean greedyProxying)
Greedy proxies will proxy all the (visible) classes published by the imported OSGi services. This means that the individual service proxy, might implement/extend additional classes.
By default, greedy proxies are disabled (false) meaning that only the specified classes are used for generating the the imported OSGi service proxies. Note:Greedy proxying will use the proxy mechanism dictated by this factory configuration. This means that if JDK proxies are used, greedy proxing will consider only additional interfaces exposed by the OSGi service and none of the extra classes. When CGLIB is used, all extra published classes (whether interfaces or non-final concrete classes) will be considered.
greedyProxying
- true if greedy proxying should be enabled, false otherwise.public MemberType getMemberType()
public void setMemberType(MemberType type)
MemberType.SERVICE_OBJECT
or service references MemberType.SERVICE_REFERENCE
.
type
- the collection member typepublic void destroy() throws Exception
destroy
in interface DisposableBean
Exception
public Object getObject()
getObject
in interface FactoryBean<Object>
public Class<?> getObjectType()
getObjectType
in interface FactoryBean<Object>
public boolean isSingleton()
isSingleton
in interface FactoryBean<Object>
public boolean isEagerInit()
isEagerInit
in interface SmartFactoryBean<Object>
public boolean isPrototype()
isPrototype
in interface SmartFactoryBean<Object>
public void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader
in interface BeanClassLoaderAware
setBeanClassLoader
in class AbstractOsgiServiceImportFactoryBean
public void setUseBlueprintExceptions(boolean useBlueprintExceptions)
useBlueprintExceptions
- public void setBlueprintCompliant(boolean compliant)
compliant
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |