com.ibm.wsspi.kernel.service.utils

Class ConcurrentServiceReferenceSetMap<K,V>

  1. java.lang.Object
  2. extended bycom.ibm.wsspi.kernel.service.utils.ConcurrentServiceReferenceSetMap<K,V>

  1. public class ConcurrentServiceReferenceSetMap<K,V>
  2. extends java.lang.Object
This provides a map implementation for lazy-resolution of multiple services. Use this class when you have frequent iteration with infrequent add/removal. Entries are not stored in any particular order, but services with the same key 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 ConcurrentServiceReferenceSetMap<K,V> 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<V> ref) {
  K key;
  serviceMap.putReference(key, ref);
 }
 
 protected void unsetReferenceName(ServiceReference<V> ref) {
  K key;
  serviceMap.removeReference(key, ref);
 }
 
 public Iterator<T> getServices() {
  return serviceSet.getServices();
 }
 

Constructor Summary

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

Method Summary

Modifier and Type Method and Description
  1. void
activate(ComponentContext context)
  1. void
deactivate(ComponentContext context)
Deactivates the map.
  1. java.util.Iterator<V>
getServices(K key)
Retrieve an iterator for the services associated with the given key.
Services are returned in service rank order.
  1. java.util.Iterator<ServiceAndServiceReferencePair<V>>
getServicesWithReferences(K key)
Retrieve an iterator for service & service reference pairs for a given key
Services are returned in service rank order.
Service References are available to query properties etc.
  1. boolean
isEmpty()
Check if there are any registered/added service references: this will return true if all the known sets for all known keys report as empty.
  1. boolean
putReference(K key, reference)
Associates the reference with the key.
  1. boolean
removeReference(K key, reference)
Removes the reference associated with the key.
  1. java.lang.String
toString()
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail

ConcurrentServiceReferenceSetMap

  1. public ConcurrentServiceReferenceSetMap( java.lang.String name)
Create a new ConcurrentServiceReferenceMap 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)
Deactivates the map. Will trigger a release of all held services.

toString

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

putReference

  1. public boolean putReference(K key,
  2. reference)
Associates the reference with the key.
Parameters:
key - Key associated with this reference
reference - ServiceReference for the target service
Returns:
true if this is replacing a previous (non-null) service reference

removeReference

  1. public boolean removeReference( K key,
  2. reference)
Removes the reference associated with the key.
Parameters:
key - Key associated with this reference
reference - ServiceReference for the target service
Returns:
true if reference was unset (not previously replaced)

isEmpty

  1. public boolean isEmpty()
Check if there are any registered/added service references: this will return true if all the known sets for all known keys report as empty.
Returns:
true if the known sets of registered service references are empty.

getServices

  1. public java.util.Iterator<V> getServices( K key)
Retrieve an iterator for the services associated with the given key.
Services are returned in service rank order.
Parameters:
key - The key associated with the requested service
Returns:
Iterator for services if any available, null otherwise.

getServicesWithReferences

  1. public java.util.Iterator<ServiceAndServiceReferencePair<V>> getServicesWithReferences( K key)
Retrieve an iterator for service & service reference pairs for a given key
Services are returned in service rank order.
Service References are available to query properties etc.
Parameters:
key - The key associated with the requested service
Returns:
Iterator supplying pairs of service & service reference if any services are available, null otherwise.