Class ServiceRegistryCacheManager

java.lang.Object
org.apache.felix.dm.impl.index.ServiceRegistryCacheManager

public class ServiceRegistryCacheManager extends Object
This class manages the service registry cache creation.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Called by the DependencyManager Activator when its start method has completed (successfully or not): getCache() is no longer re-entrant for the Activator thread.
    getCache(Logger logger)
    Gets the service registry cache, if enabled.
    static void
    init(org.osgi.framework.BundleContext context)
    Initialize the service registry cache.
    static void
    registerFilterIndex(FilterIndex index, org.osgi.framework.BundleContext context)
    Registers a FilterIndex into the service registry cache.
    static void
    Called by the DependencyManager Activator when the DependencyManager bundle is stopped: from now on, getCache() neither restarts the DependencyManager bundle nor returns the cache, until the bundle is started again.
    static void
    Unregister a FilterIndex from the cache, and possibly close the cache in case it becomes empty.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ServiceRegistryCacheManager

      public ServiceRegistryCacheManager()
  • Method Details

    • getCache

      public static ServiceRegistryCache getCache(Logger logger)
      Gets the service registry cache, if enabled. Before returning the cache, we try to make sure the DependencyManager bundle is started, because the cache is initialized by the DependencyManager bundle Activator. The cache is only an optimization: this method never throws. If the DependencyManager bundle can't be started, null is returned, and the error is logged only once. If the DependencyManager bundle has been stopped after having been started, we don't restart it, and we return null: the cache was opened with the DependencyManager bundle context, which is no longer valid, so the cache doesn't receive service events anymore. We read the bundle state before m_stopped, so a stop which is in progress (STOPPING) or complete (m_stopped is set before the state becomes RESOLVED) is detected. Only a stop which happens between our checks and the start of the bundle is not detected: the DependencyManager bundle may then be restarted (transiently). If called back from the DependencyManager Activator thread while the Activator is starting (for example from a service factory called by one of the Activator trackers), null is returned: the cache is not ready yet, and the bundle is already being started by this thread.
      Parameters:
      logger - the logger used to report a failure to start the DependencyManager bundle
      Returns:
      the service registry cache, if enabled, or null
    • registerFilterIndex

      public static void registerFilterIndex(FilterIndex index, org.osgi.framework.BundleContext context)
      Registers a FilterIndex into the service registry cache. The cache is created if necessary.
      Parameters:
      index - a new FilterIndex to be registered in the cache
      context - the bundle context used by the cache
    • unregisterFilterIndex

      public static void unregisterFilterIndex(FilterIndex index)
      Unregister a FilterIndex from the cache, and possibly close the cache in case it becomes empty.
      Parameters:
      index - the FilterIndex to unregister
    • init

      public static void init(org.osgi.framework.BundleContext context)
      Initialize the service registry cache. Called by the DependencyManager Activator, with the DependencyManager bundle context (the framework serializes the Activator start, so we don't need to synchronize). Initialization is only done once, even if the DependencyManager bundle is restarted (except m_stopped, which is reset at each start).
      Parameters:
      context - the DependencyManager bundle context
    • activated

      public static void activated()
      Called by the DependencyManager Activator when its start method has completed (successfully or not): getCache() is no longer re-entrant for the Activator thread.
    • stopped

      public static void stopped()
      Called by the DependencyManager Activator when the DependencyManager bundle is stopped: from now on, getCache() neither restarts the DependencyManager bundle nor returns the cache, until the bundle is started again.