Class ConcurrentServiceReferenceSet<T>
- java.lang.Object
- 
- com.ibm.wsspi.kernel.service.utils.ConcurrentServiceReferenceSet<T>
 
- 
 public class ConcurrentServiceReferenceSet<T> extends java.lang.ObjectThis provides a simple set implementation for lazy-resolution of services. Use this class when you have frequent iteration with infrequent add/removal. Services are stored in reverse order ofServiceReference.compareTo(java.lang.Object): highest service.ranking then lowest (first) service.id.Usage (following OSGi DS naming conventions/patterns): private final ConcurrentServiceReferenceSet<T> serviceSet = new ConcurrentServiceReferenceSet<T>("referenceName"); protected void activate(ComponentContext ctx) { serviceSet.activate(ctx); } protected void deactivate(ComponentContext ctx) { serviceSet.deactivate(ctx); } protected void setReferenceName(ServiceReference<T> ref) { serviceSet.addReference(ref); } protected void unsetReferenceName(ServiceReference<T> ref) { serviceSet.removeReference(ref); } public Iterator<T> getReferenceName() { return serviceSet.getServices(); }
- 
- 
Constructor SummaryConstructors Constructor Description ConcurrentServiceReferenceSet(java.lang.String name)Create a new ConcurrentServiceReferenceSet for the named service.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivate(org.osgi.service.component.ComponentContext context)booleanaddReference(org.osgi.framework.ServiceReference<T> reference)Adds the service reference to the set, or notifies the set that the service ranking for the reference might have been updated.voiddeactivate(org.osgi.service.component.ComponentContext context)org.osgi.framework.ServiceReference<T>getHighestRankedReference()The ConcurrentReferenceSet is ordered by the usual service ranking rules: highest service.ranking then lowest (first) service.id.TgetHighestRankedService()The ConcurrentReferenceSet is ordered by the usual service ranking rules: highest service.ranking then lowest (first) service.id.TgetService(org.osgi.framework.ServiceReference<T> serviceReference)Find the provided reference in the set, and return the corresponding service.java.util.Iterator<T>getServices()Allocate and return an iterator: The iterator will return the service associated with each ServiceReference as it progresses.java.util.Iterator<ServiceAndServiceReferencePair<T>>getServicesWithReferences()Allocate and return an iterator: The iterator will return the service associated with each ServiceReference as it progresses.booleanisActive()booleanisEmpty()Check if there are any registered/added service references: this will return true if the set is empty (none available).java.lang.Iterable<org.osgi.framework.ServiceReference<T>>references()booleanremoveReference(org.osgi.framework.ServiceReference<T> reference)Removes the service reference from the setjava.lang.Iterable<T>services()java.lang.StringtoString()
 
- 
- 
- 
Method Detail- 
activatepublic void activate(org.osgi.service.component.ComponentContext context) 
 - 
deactivatepublic void deactivate(org.osgi.service.component.ComponentContext context) 
 - 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 - 
addReferencepublic boolean addReference(org.osgi.framework.ServiceReference<T> reference) Adds the service reference to the set, or notifies the set that the service ranking for the reference might have been updated.- Parameters:
- reference- ServiceReference for the target service
- Returns:
- true if this set already contained the service reference
 
 - 
removeReferencepublic boolean removeReference(org.osgi.framework.ServiceReference<T> reference) Removes the service reference from the set- Parameters:
- reference- ServiceReference associated with service to be unset
- Returns:
- true if this set contained the service reference
 
 - 
isEmptypublic boolean isEmpty() Check if there are any registered/added service references: this will return true if the set is empty (none available). If the set is not empty, the services will only be resolvable if there is a viable component context.- Returns:
- true if the list of registered service references is empty.
 
 - 
isActivepublic boolean isActive() 
 - 
getServicepublic T getService(org.osgi.framework.ServiceReference<T> serviceReference) Find the provided reference in the set, and return the corresponding service. Subject to the same restrictions/behavior as getServices.- Parameters:
- serviceReference- Service reference to find in the set
- Returns:
- service associated with service reference, or null if the service could not be located.
 
 - 
getHighestRankedServicepublic T getHighestRankedService() The ConcurrentReferenceSet is ordered by the usual service ranking rules: highest service.ranking then lowest (first) service.id.- Returns:
- The "first" service according to the ranking
 
 - 
getHighestRankedReferencepublic org.osgi.framework.ServiceReference<T> getHighestRankedReference() The ConcurrentReferenceSet is ordered by the usual service ranking rules: highest service.ranking then lowest (first) service.id.- Returns:
- The "first" service reference according to the ranking
 
 - 
getServicespublic java.util.Iterator<T> getServices() Allocate and return an iterator: The iterator will return the service associated with each ServiceReference as it progresses. Creation of the iterator does not eagerly resolve services: resolution is done only once per service reference, and only when "next" would retrieve that service.- Returns:
 
 - 
getServicesWithReferencespublic java.util.Iterator<ServiceAndServiceReferencePair<T>> getServicesWithReferences() Allocate and return an iterator: The iterator will return the service associated with each ServiceReference as it progresses. Creation of the iterator does not eagerly resolve services: resolution is done only once per service reference, and only when "next" would retrieve that service.- Returns:
 
 - 
servicespublic java.lang.Iterable<T> services() 
 - 
referencespublic java.lang.Iterable<org.osgi.framework.ServiceReference<T>> references() 
 
- 
 
-