public class ConcurrentServiceReferenceSetMap<K,V>
extends java.lang.Object
ServiceReference.compareTo(java.lang.Object)
: 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 and Description |
---|
ConcurrentServiceReferenceSetMap(java.lang.String name)
Create a new ConcurrentServiceReferenceMap for the named service.
|
Modifier and Type | Method and Description |
---|---|
void |
activate(org.osgi.service.component.ComponentContext context) |
void |
deactivate(org.osgi.service.component.ComponentContext context)
Deactivates the map.
|
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. |
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. |
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.
|
boolean |
putReference(K key,
org.osgi.framework.ServiceReference<V> reference)
Associates the reference with the key.
|
boolean |
removeReference(K key,
org.osgi.framework.ServiceReference<V> reference)
Removes the reference associated with the key.
|
java.lang.String |
toString() |
public ConcurrentServiceReferenceSetMap(java.lang.String name)
name
- Name of DS referencepublic void activate(org.osgi.service.component.ComponentContext context)
public void deactivate(org.osgi.service.component.ComponentContext context)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean putReference(K key, org.osgi.framework.ServiceReference<V> reference)
key
- Key associated with this referencereference
- ServiceReference for the target servicepublic boolean removeReference(K key, org.osgi.framework.ServiceReference<V> reference)
key
- Key associated with this referencereference
- ServiceReference for the target servicepublic boolean isEmpty()
public java.util.Iterator<V> getServices(K key)
key
- The key associated with the requested servicepublic java.util.Iterator<ServiceAndServiceReferencePair<V>> getServicesWithReferences(K key)
key
- The key associated with the requested service