|
||||||||||
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
Constructor Summary | |
---|---|
OsgiServiceCollectionProxyFactoryBean()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
|
void |
destroy()
|
Object |
getObject()
Returns a managed object for accessing OSGi service(s). Returns a managed collection that automatically handles the dynamics of matching OSGi services. |
Class |
getObjectType()
Returns the managed collection 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 |
setCardinality(Cardinality cardinality)
Sets the importer cardinality (0..1, 1..1, 0..N, or 1..N). Since this implementation creates a managed collection, only multiple cardinalities are accepted. |
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). |
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 |
---|
public OsgiServiceCollectionProxyFactoryBean()
Method Detail |
---|
public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
public Class getObjectType()
public Object getObject()
getObject
in interface FactoryBean
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 setCardinality(Cardinality cardinality)
setCardinality
in class AbstractOsgiServiceImportFactoryBean
cardinality
- importer cardinality.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 void destroy() throws Exception
destroy
in interface DisposableBean
Exception
public boolean isSingleton()
isSingleton
in interface FactoryBean
public boolean isEagerInit()
isEagerInit
in interface SmartFactoryBean
public boolean isPrototype()
isPrototype
in interface SmartFactoryBean
public void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader
in interface BeanClassLoaderAware
setBeanClassLoader
in class AbstractOsgiServiceImportFactoryBean
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |