Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.eclipse.gemini.blueprint.service.importer.support
Class OsgiServiceCollectionProxyFactoryBean

    java.lang.Object
      org.eclipse.gemini.blueprint.service.importer.support.AbstractOsgiServiceImportFactoryBean
          org.eclipse.gemini.blueprint.service.importer.support.OsgiServiceCollectionProxyFactoryBean

All Implemented Interfaces:
  BundleContextAware, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.FactoryBean<Object>, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.SmartFactoryBean<Object>

    public final class OsgiServiceCollectionProxyFactoryBean

extends AbstractOsgiServiceImportFactoryBean

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 collection `Iterator`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.

Due to the dynamic nature of OSGi, `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.

Author:
  Costin Leau
See Also:
  `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.
`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.eclipse.gemini.blueprint.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

### proxy

    protected Object proxy

Constructor Detail

### OsgiServiceCollectionProxyFactoryBean

    public OsgiServiceCollectionProxyFactoryBean()

Method Detail

### afterPropertiesSet

    public void afterPropertiesSet()

  Specified by:
    `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`

### setComparator

    public void setComparator(Comparator comparator)

  Sets the (optional) comparator for ordering the resulting collection. The presence of a comparator will force the FactoryBean to use a sorted collection even though, the specified collection type does not imply ordering.

  Thus, instead of list a sorted list will be created and instead of a set, a sorted set.

  Parameters:
    `comparator` - Comparator (can be null) used for ordering the resulting collection.
  See Also:
    `setCollectionType(CollectionType)`

### setCollectionType

    public void setCollectionType(CollectionType collectionType)

  Sets the collection type this FactoryBean will produce. Note that if a comparator is set, a sorted collection will be created even if the specified type is does not imply ordering. If no comparator is set but the collection type implies ordering, the natural order of the elements will be used.

  Parameters:
    `collectionType` - the collection type as string using one of the values above.
  See Also:
    `setComparator(Comparator)`, `Comparable`, `Comparator`, `CollectionType`

### setGreedyProxying

    public void setGreedyProxying(boolean greedyProxying)

  Dictates whether greedy proxies are created or not (default).

  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.

  Parameters:
    `greedyProxying` - true if greedy proxying should be enabled, false otherwise.

### getMemberType

    public MemberType getMemberType()

  Sets the member type of this service collection.

  Returns:
    the collection member type

### setMemberType

    public void setMemberType(MemberType type)

  Sets the member type of this service collection. The collection can hold either service proxies (the default) indicated by `MemberType.SERVICE_OBJECT` or service references `MemberType.SERVICE_REFERENCE`.

  Parameters:
    `type` - the collection member type

### destroy

    public void destroy()
                 throws Exception

  Specified by:
    `destroy` in interface `org.springframework.beans.factory.DisposableBean`
  Throws:
    `Exception`

### getObject

    public Object getObject()

  Returns a managed object for accessing OSGi service(s).

  Specified by:
    `getObject` in interface `org.springframework.beans.factory.FactoryBean<Object>`
  Returns:
    managed OSGi service(s)

### 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 `org.springframework.beans.factory.FactoryBean<Object>`

### isSingleton

    public boolean isSingleton()

  The object managed by this factory is a singleton.

  Specified by:
    `isSingleton` in interface `org.springframework.beans.factory.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 `org.springframework.beans.factory.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 `org.springframework.beans.factory.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 `org.springframework.beans.factory.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` -

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2006-2013. All Rights Reserved.