public final class OsgiServiceCollectionProxyFactoryBean extends AbstractServiceImporterProxyFactoryBean
Iterators 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| Modifier and Type | Class and Description |
|---|---|
private class |
OsgiServiceCollectionProxyFactoryBean.Executor
Wrapper around internal commands.
|
| Modifier and Type | Field and Description |
|---|---|
private CollectionType |
collectionType |
private java.util.Comparator |
comparator |
private ImporterInternalActions |
controller |
private CollectionProxy |
exposedProxy
proxy casted to a specific interface to allow specific method calls
|
private boolean |
greedyProxying
greedy-proxying
|
private java.lang.Runnable |
initializationCallback |
private static org.apache.commons.logging.Log |
log |
private MemberType |
memberType |
private ServiceProxyCreator |
proxyCreator
proxy creator
|
private java.lang.Runnable |
proxyDestructionCallback
proxy infrastructure hook exposed to allow clean up
|
private java.util.List<ImporterStateListener> |
stateListeners
internal listeners
|
proxy| Constructor and Description |
|---|
OsgiServiceCollectionProxyFactoryBean() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
(package private) java.lang.Object |
createProxy(boolean lazyProxy)
Create the managed-collection given the existing settings.
|
(package private) Cardinality |
getInternalCardinality() |
MemberType |
getMemberType()
Sets the member type of this service collection.
|
(package private) java.lang.Runnable |
getProxyDestructionCallback()
Returns the destruction callback associated with the proxy created by this object.
|
(package private) java.lang.Runnable |
getProxyInitializer()
Returns a callback to the proxy which gets called when the proxy is called for the first time, if a lazy creation
was used.
|
void |
setCollectionType(CollectionType collectionType)
Sets the collection type this FactoryBean will produce.
|
void |
setComparator(java.util.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.
|
destroy, getAopClassLoader, getObject, getObjectType, isBlueprintCompliant, isEagerInit, isPrototype, isSingleton, isUseBlueprintExceptions, setBeanClassLoader, setBlueprintCompliant, setUseBlueprintExceptionsgetAvailability, getBeanClassLoader, getBeanName, getBundleContext, getCardinality, getContextClassLoader, getFilter, getImportContextClassLoader, getInterfaces, getListeners, getUnifiedFilter, setAvailability, setBeanName, setBundleContext, setCardinality, setContextClassLoader, setFilter, setImportContextClassLoader, setInterfaces, setListeners, setServiceBeanNameprivate static final org.apache.commons.logging.Log log
private CollectionProxy exposedProxy
private java.lang.Runnable proxyDestructionCallback
private java.lang.Runnable initializationCallback
private ServiceProxyCreator proxyCreator
private java.util.Comparator comparator
private CollectionType collectionType
private boolean greedyProxying
private MemberType memberType
private final java.util.List<ImporterStateListener> stateListeners
private final ImporterInternalActions controller
public OsgiServiceCollectionProxyFactoryBean()
public void afterPropertiesSet()
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanafterPropertiesSet in class AbstractServiceImporterProxyFactoryBeanjava.lang.Object createProxy(boolean lazyProxy)
createProxy in class AbstractServiceImporterProxyFactoryBeanlazyProxy - indicates whether the proxy is lazy (no code is executed in the proxy) or notAbstractServiceImporterProxyFactoryBean.getProxyDestructionCallback()java.lang.Runnable getProxyInitializer()
AbstractServiceImporterProxyFactoryBeangetProxyInitializer in class AbstractServiceImporterProxyFactoryBeanjava.lang.Runnable getProxyDestructionCallback()
AbstractServiceImporterProxyFactoryBeanFactoryBean.getProxyDestructionCallback in class AbstractServiceImporterProxyFactoryBean#createProxy()public void setComparator(java.util.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,
CollectionTypepublic 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 typeCardinality getInternalCardinality()
getInternalCardinality in class AbstractOsgiServiceImportFactoryBean