org.apache.stanbol.enhancer.servicesapi.helper
Class NameBasedServiceTrackingState

java.lang.Object
  extended by org.osgi.util.tracker.ServiceTracker
      extended by org.apache.stanbol.enhancer.servicesapi.helper.NameBasedServiceTrackingState
All Implemented Interfaces:
org.osgi.util.tracker.ServiceTrackerCustomizer

public class NameBasedServiceTrackingState
extends org.osgi.util.tracker.ServiceTracker
implements org.osgi.util.tracker.ServiceTrackerCustomizer

Used to manage the state of ServiceReferences for services that are accessed based on the value of a specific property.

This can be used to track both EnhancementEngines as well as Chains.

This implementation supports the use of #readLock() on returned values. Also the null as value for the parsed name property.

Author:
Rupert Westenthaler

Field Summary
 
Fields inherited from class org.osgi.util.tracker.ServiceTracker
context, filter
 
Constructor Summary
NameBasedServiceTrackingState(org.osgi.framework.BundleContext context, org.osgi.framework.Filter filter, java.lang.String nameProperty, org.osgi.util.tracker.ServiceTrackerCustomizer customizer)
          Creates a trackingState with an optional customiser
NameBasedServiceTrackingState(org.osgi.framework.BundleContext context, java.lang.String clazz, java.lang.String nameProperty, org.osgi.util.tracker.ServiceTrackerCustomizer customizer)
          Creates a trackingState with an optional customiser
 
Method Summary
 java.lang.Object addingService(org.osgi.framework.ServiceReference reference)
           
 java.util.Map<java.lang.String,org.osgi.framework.ServiceReference> getActive()
          Getter for the read only names -> ServiceReference of the currently active and tracked engines.
 java.util.Set<java.lang.String> getNames()
          Getter for the read only set of names of all currently active and tracked engines
 org.osgi.framework.ServiceReference getReference(java.lang.String name)
           
 java.util.List<org.osgi.framework.ServiceReference> getReferences(java.lang.String name)
           
 void modifiedService(org.osgi.framework.ServiceReference reference, java.lang.Object service)
           
 void removedService(org.osgi.framework.ServiceReference reference, java.lang.Object service)
           
 
Methods inherited from class org.osgi.util.tracker.ServiceTracker
close, getService, getService, getServiceReference, getServiceReferences, getServices, getTrackingCount, open, open, remove, size, waitForService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NameBasedServiceTrackingState

public NameBasedServiceTrackingState(org.osgi.framework.BundleContext context,
                                     org.osgi.framework.Filter filter,
                                     java.lang.String nameProperty,
                                     org.osgi.util.tracker.ServiceTrackerCustomizer customizer)
Creates a trackingState with an optional customiser

Parameters:
context - the BundleContext used for tracking. MUST NOT be null.
filter - The filter used for the ServiceTracker
nameProperty - the property used to lookup the name of the tracked services. This MUST NOT be null nor empty.
customizer - optionally a customiser used with this tracker
Throws:
java.lang.IllegalArgumentException - it the parsed nameProperty is null or an empty string.

NameBasedServiceTrackingState

public NameBasedServiceTrackingState(org.osgi.framework.BundleContext context,
                                     java.lang.String clazz,
                                     java.lang.String nameProperty,
                                     org.osgi.util.tracker.ServiceTrackerCustomizer customizer)
Creates a trackingState with an optional customiser

Parameters:
context - the BundleContext used for tracking. MUST NOT be null.
clazz - The type of the tracked services
nameProperty - the property used to lookup the name of the tracked services. This MUST NOT be null nor empty.
customizer - optionally a customiser used with this tracker
Throws:
java.lang.IllegalArgumentException - it the parsed nameProperty is null or an empty string.
Method Detail

getNames

public java.util.Set<java.lang.String> getNames()
Getter for the read only set of names of all currently active and tracked engines

Returns:
the names of all currently active and tracked engines

getActive

public java.util.Map<java.lang.String,org.osgi.framework.ServiceReference> getActive()
Getter for the read only names -> ServiceReference of the currently active and tracked engines.

Returns:
the name -> ServiceReference mapping of all active engines.

addingService

public java.lang.Object addingService(org.osgi.framework.ServiceReference reference)
Specified by:
addingService in interface org.osgi.util.tracker.ServiceTrackerCustomizer
Overrides:
addingService in class org.osgi.util.tracker.ServiceTracker

modifiedService

public void modifiedService(org.osgi.framework.ServiceReference reference,
                            java.lang.Object service)
Specified by:
modifiedService in interface org.osgi.util.tracker.ServiceTrackerCustomizer
Overrides:
modifiedService in class org.osgi.util.tracker.ServiceTracker

removedService

public void removedService(org.osgi.framework.ServiceReference reference,
                           java.lang.Object service)
Specified by:
removedService in interface org.osgi.util.tracker.ServiceTrackerCustomizer
Overrides:
removedService in class org.osgi.util.tracker.ServiceTracker

getReferences

public java.util.List<org.osgi.framework.ServiceReference> getReferences(java.lang.String name)

getReference

public org.osgi.framework.ServiceReference getReference(java.lang.String name)


Copyright © 2010-2012 The Apache Software Foundation. All Rights Reserved.