Class AbstractComponentManager<S>

java.lang.Object
org.apache.felix.scr.impl.manager.AbstractComponentManager<S>
All Implemented Interfaces:
ComponentManager<S>
Direct Known Subclasses:
ComponentFactoryImpl, SingleComponentManager

public abstract class AbstractComponentManager<S> extends Object implements ComponentManager<S>
The default ComponentManager. Objects of this class are responsible for managing implementation object's lifecycle.
  • Field Details

    • REASONS

      static final String[] REASONS
    • m_container

      protected final ComponentContainer<S> m_container
    • m_factoryInstance

      protected final boolean m_factoryInstance
    • m_componentId

      private volatile long m_componentId
    • m_componentMethods

      private final ComponentMethods<S> m_componentMethods
    • m_dependencyManagers

      private final List<DependencyManager<S,?>> m_dependencyManagers
    • m_dependencyManagersInitialized

      private volatile boolean m_dependencyManagersInitialized
    • m_trackingCount

      private final AtomicInteger m_trackingCount
    • m_stateLock

      private final ReentrantLock m_stateLock
    • m_enabledLatchRef

      private final AtomicReference<org.osgi.util.promise.Deferred<Void>> m_enabledLatchRef
      This latch prevents concurrent enable, disable, and reconfigure. Since the enable and disable operations may use two threads and the initiating thread does not wait for the operation to complete, we can't use a regular lock.
    • state

    • m_floor

      private volatile int m_floor
    • m_ceiling

      private volatile int m_ceiling
    • m_missingLock

      private final Lock m_missingLock
    • m_missingCondition

      private final Condition m_missingCondition
    • m_missing

      private final Set<Integer> m_missing
    • m_activationLock

      protected final ReentrantReadWriteLock m_activationLock
    • failureReason

      private volatile String failureReason
    • taskCounter

      private static final AtomicLong taskCounter
    • registrationManager

      final RegistrationManager<org.osgi.framework.ServiceRegistration<S>> registrationManager
  • Constructor Details

    • AbstractComponentManager

      protected AbstractComponentManager(ComponentContainer<S> container, ComponentMethods<S> componentMethods)
      The constructor receives both the container and the methods.
      Parameters:
      container - The component container
      componentMethods - The component methods
    • AbstractComponentManager

      protected AbstractComponentManager(ComponentContainer<S> container, ComponentMethods<S> componentMethods, boolean factoryInstance)
      The constructor receives both the container and the methods.
      Parameters:
      container - The component container
      componentMethods - The component methods
      factoryInstance - Flag whether this is a factory instance
  • Method Details

    • getLockTimeout

      final long getLockTimeout()
    • obtainLock

      private void obtainLock(Lock lock)
    • obtainActivationReadLock

      final void obtainActivationReadLock()
    • releaseActivationReadLock

      final void releaseActivationReadLock()
    • obtainActivationWriteLock

      final void obtainActivationWriteLock()
    • releaseActivationWriteeLock

      final void releaseActivationWriteeLock()
    • obtainStateLock

      final void obtainStateLock()
    • releaseStateLock

      final void releaseStateLock()
    • isStateLocked

      final boolean isStateLocked()
    • dumpThreads

      final void dumpThreads()
    • tracked

      void tracked(int trackingCount)
    • waitForTracked

      void waitForTracked(int trackingCount)
      We effectively maintain the set of completely processed service event tracking counts. This method waits for all events prior to the parameter tracking count to complete, then returns. See further documentation in EdgeInfo.
      Parameters:
      trackingCount -
    • doMissingWait

      private boolean doMissingWait() throws InterruptedException
      Throws:
      InterruptedException
    • registerComponentId

      void registerComponentId()
    • unregisterComponentId

      void unregisterComponentId()
    • enable

      public final org.osgi.util.promise.Promise<Void> enable(boolean async)
    • enableLatchWait

      org.osgi.util.promise.Deferred<Void> enableLatchWait()
      Use a CountDownLatch as a non-reentrant "lock" that can be passed between threads. This lock assures that enable, disable, and reconfigure operations do not overlap.
      Returns:
      the latch to count down when the operation is complete (in the calling or another thread)
      Throws:
      InterruptedException
    • disable

      public final org.osgi.util.promise.Promise<Void> disable(boolean async)
    • dispose

      void dispose()
    • dispose

      public void dispose(int reason)
      Disposes off this component deactivating and disabling it first as required. After disposing off the component, it may not be used anymore.

      This method unlike the other state change methods immediately takes action and disposes the component. The reason for this is, that this method has to actually complete before other actions like bundle stopping may continue.

    • registerMissingDependency

      <T> void registerMissingDependency(DependencyManager<S,T> dm, org.osgi.framework.ServiceReference<T> ref, int trackingCount)
    • getId

      public long getId()
      Specified by:
      getId in interface ComponentManager<S>
    • getBundle

      public org.osgi.framework.Bundle getBundle()
      Returns the Bundle providing this component. If the component as already been disposed off, this method returns null.
    • getBundleContext

      org.osgi.framework.BundleContext getBundleContext()
    • isImmediate

      protected boolean isImmediate()
    • isFactory

      public boolean isFactory()
    • enableInternal

      final void enableInternal()
    • activateInternal

      final void activateInternal()
    • deactivateInternal

      final void deactivateInternal(int reason, boolean disable, boolean dispose)
      Handles deactivating, disabling, and disposing a component manager. Deactivating a factory instance always disables and disposes it. Deactivating a factory disposes it.
      Parameters:
      reason - reason for action
      disable - whether to also disable the manager
      dispose - whether to also dispose of the manager
    • doDeactivate

      private void doDeactivate(int reason, boolean disable)
    • disableInternal

      final void disableInternal()
    • deleteComponent

      protected abstract void deleteComponent(int reason)
    • getServiceInternal

      boolean getServiceInternal(org.osgi.framework.ServiceRegistration<S> serviceRegistration)
    • getService

      private Object getService()
      All ComponentManagers are ServiceFactory instances
      Returns:
      this as a ServiceFactory.
    • getComponentMethods

      ComponentMethods<S> getComponentMethods()
    • getProvidedServices

      protected String[] getProvidedServices()
    • registerService

      protected boolean registerService()
      Registers the service on behalf of the component.
    • unregisterService

      protected boolean unregisterService()
    • getServiceRegistration

      protected org.osgi.framework.ServiceRegistration<S> getServiceRegistration()
    • getTrackingCount

      AtomicInteger getTrackingCount()
    • initDependencyManagers

      private void initDependencyManagers(ComponentContextImpl<S> componentContext)
    • collectDependencies

      protected boolean collectDependencies(ComponentContextImpl<S> componentContext)
      Collect and store in m_dependencies_map all the services for dependencies, outside of any locks.
      Parameters:
      componentContext - possible instance key for prototype scope references
      Returns:
      true if all references can be collected, false if some dependency is no longer available.
    • invokeUpdatedMethod

      abstract <T> boolean invokeUpdatedMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> refPair, int trackingCount)
      Invoke updated method
      Returns:
      true if the component needs reactivation, false otherwise.
    • invokeBindMethod

      abstract <T> void invokeBindMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> refPair, int trackingCount)
    • invokeUnbindMethod

      abstract <T> void invokeUnbindMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> oldRefPair, int trackingCount)
    • notifyWaiters

      void notifyWaiters()
    • getActivator

      public ComponentActivator getActivator()
    • clear

      void clear()
    • getLogger

      public ComponentLogger getLogger()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hasServiceRegistrationPermissions

      private boolean hasServiceRegistrationPermissions()
    • loadDependencyManagers

      private List<DependencyManager<S,?>> loadDependencyManagers(ComponentMetadata metadata)
    • updateTargets

      final void updateTargets(Map<String,Object> properties)
    • verifyDependencyManagers

      protected boolean verifyDependencyManagers()
    • getDependencyManagers

      List<DependencyManager<S,?>> getDependencyManagers()
      Returns an iterator over the DependencyManager objects representing the declared references in declaration order
    • getReferenceManagers

      public List<? extends ReferenceManager<S,?>> getReferenceManagers()
      Specified by:
      getReferenceManagers in interface ComponentManager<S>
    • getReversedDependencyManagers

      List<DependencyManager<S,?>> getReversedDependencyManagers()
      Returns an iterator over the DependencyManager objects representing the declared references in reversed declaration order
    • getDependencyManager

      DependencyManager<S,?> getDependencyManager(String name)
    • deactivateDependencyManagers

      private void deactivateDependencyManagers()
    • disableDependencyManagers

      private void disableDependencyManagers()
    • getProperties

      public abstract Map<String,Object> getProperties()
      Specified by:
      getProperties in interface ComponentManager<S>
    • setServiceProperties

      public abstract void setServiceProperties(Dictionary<String,?> serviceProperties)
    • getServiceProperties

      public Dictionary<String,Object> getServiceProperties()
      Returns the subset of component properties to be used as service properties. These properties are all component properties where property name does not start with dot (.), properties which are considered private.
    • copyTo

      protected static Dictionary<String,Object> copyTo(Dictionary<String,Object> target, Map<String,?> source, boolean allProps)
      Copies the properties from the source Dictionary into the target Dictionary except for private properties (whose name has a leading dot) which are only copied if the allProps parameter is true.
      Parameters:
      target - The Dictionary into which to copy the properties. If null a new Hashtable is created.
      source - The Dictionary providing the properties to copy. If null or empty, nothing is copied.
      allProps - Whether all properties (true) or only the public properties (false) are to be copied.
      Returns:
      The target is returned, which may be empty if source is null or empty and target was null or all properties are private and had not to be copied
    • copyToMap

      protected static Map<String,Object> copyToMap(Dictionary<String,?> source, boolean allProps)
      Copies the properties from the source Dictionary into the target Dictionary except for private properties (whose name has a leading dot) which are only copied if the allProps parameter is true.
      Parameters:
      source - The Dictionary providing the properties to copy. If null or empty, nothing is copied.
      allProps - Whether all properties (true) or only the public properties (false) are to be copied.
      Returns:
      The target is returned, which may be empty if source is null or empty and target was null or all properties are private and had not to be copied
    • copyToDictionary

      protected static Dictionary<String,Object> copyToDictionary(Dictionary<String,?> source, boolean allProps)
    • getComponentMetadata

      public ComponentMetadata getComponentMetadata()
    • getSpecState

      public int getSpecState()
      Specified by:
      getSpecState in interface ComponentManager<S>
    • getState

    • getFailureReason

      public String getFailureReason()
      Specified by:
      getFailureReason in interface ComponentManager<S>
    • setFailureReason

      public void setFailureReason(Throwable e)
      Set the activation failure reason
      Parameters:
      e - The exception which caused the activation to fail
    • setState

      void setState(AbstractComponentManager.State previousState, AbstractComponentManager.State newState)
    • setServiceProperties

      public void setServiceProperties(MethodResult methodResult, Integer trackingCount)
    • postRegister

      abstract void postRegister()
    • preDeregister

      abstract void preDeregister()
    • reconfigure

      public abstract void reconfigure(Map<String,Object> configuration, boolean configurationDeleted, TargetedPID factoryPid)
    • getComponentManagers

      public abstract void getComponentManagers(List<AbstractComponentManager<S>> cms)
    • getRegisteredServiceReference

      public final org.osgi.framework.ServiceReference<S> getRegisteredServiceReference()
      Specified by:
      getRegisteredServiceReference in interface ComponentManager<S>