com.ibm.wsspi.kernel.service.utils

Class ConcurrentServiceReferenceSet<T>

  1. java.lang.Object
  2. extended bycom.ibm.wsspi.kernel.service.utils.ConcurrentServiceReferenceSet<T>

  1. public class ConcurrentServiceReferenceSet<T>
  2. extends java.lang.Object
This 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 of ServiceReference#compareTo: 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 Summary

Constructor and Description
ConcurrentServiceReferenceSet(java.lang.String name)
Create a new ConcurrentServiceReferenceSet for the named service.

Method Summary

Modifier and Type Method and Description
  1. void
activate(ComponentContext context)
  1. boolean
addReference( reference)
Adds the service reference to the set, or notifies the set that the service ranking for the reference might have been updated.
  1. void
deactivate(ComponentContext context)
getHighestRankedReference()
The ConcurrentReferenceSet is ordered by the usual service ranking rules: highest service.ranking then lowest (first) service.id.
  1. T
getHighestRankedService()
The ConcurrentReferenceSet is ordered by the usual service ranking rules: highest service.ranking then lowest (first) service.id.
  1. T
getService( serviceReference)
Find the provided reference in the set, and return the corresponding service.
  1. java.util.Iterator<T>
getServices()
Allocate and return an iterator: The iterator will return the service associated with each ServiceReference as it progresses.
  1. java.util.Iterator<ServiceAndServiceReferencePair<T>>
getServicesWithReferences()
Allocate and return an iterator: The iterator will return the service associated with each ServiceReference as it progresses.
  1. boolean
isActive()
  1. boolean
isEmpty()
Check if there are any registered/added service references: this will return true if the set is empty (none available).
  1. java.lang.Iterable<>
references()
  1. boolean
removeReference( reference)
Removes the service reference from the set
  1. java.lang.Iterable<T>
services()
  1. java.lang.String
toString()
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail

ConcurrentServiceReferenceSet

  1. public ConcurrentServiceReferenceSet( java.lang.String name)
Create a new ConcurrentServiceReferenceSet for the named service. e.g. from bnd.bnd: referenceName=.... or from component.xml:
Parameters:
name - Name of DS reference

Method Detail

activate

  1. public void activate(ComponentContext context)

deactivate

  1. public void deactivate(ComponentContext context)

toString

  1. public java.lang.String toString( )
Overrides:
toString in class java.lang.Object

addReference

  1. public boolean addReference( 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

removeReference

  1. public boolean removeReference( 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

isEmpty

  1. public 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.

isActive

  1. public boolean isActive()

getService

  1. public T getService( 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.

getHighestRankedService

  1. public 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

getHighestRankedReference

  1. public 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

getServices

  1. public 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:

getServicesWithReferences

  1. public 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:

services

  1. public java.lang.Iterable<T> services( )

references

  1. public java.lang.Iterable<> references( )