Class AbstractComponentManager<S>

    • Field Detail

      • REASONS

        static final java.lang.String[] REASONS
      • m_factoryInstance

        protected final boolean m_factoryInstance
      • m_componentId

        private volatile long m_componentId
      • m_dependencyManagers

        private final java.util.List<DependencyManager<S,​?>> m_dependencyManagers
      • m_dependencyManagersInitialized

        private volatile boolean m_dependencyManagersInitialized
      • m_trackingCount

        private final java.util.concurrent.atomic.AtomicInteger m_trackingCount
      • m_stateLock

        private final java.util.concurrent.locks.ReentrantLock m_stateLock
      • m_enabledLatchRef

        private final java.util.concurrent.atomic.AtomicReference<org.osgi.util.promise.Deferred<java.lang.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.
      • m_floor

        private volatile int m_floor
      • m_ceiling

        private volatile int m_ceiling
      • m_missingLock

        private final java.util.concurrent.locks.Lock m_missingLock
      • m_missingCondition

        private final java.util.concurrent.locks.Condition m_missingCondition
      • m_missing

        private final java.util.Set<java.lang.Integer> m_missing
      • m_activationLock

        protected final java.util.concurrent.locks.ReentrantReadWriteLock m_activationLock
      • failureReason

        private volatile java.lang.String failureReason
      • taskCounter

        private static final java.util.concurrent.atomic.AtomicLong taskCounter
      • registrationManager

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

      • 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 Detail

      • getLockTimeout

        final long getLockTimeout()
      • obtainLock

        private void obtainLock​(java.util.concurrent.locks.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 java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • registerComponentId

        void registerComponentId()
      • unregisterComponentId

        void unregisterComponentId()
      • enable

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

        org.osgi.util.promise.Deferred<java.lang.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:
        java.lang.InterruptedException
      • disable

        public final org.osgi.util.promise.Promise<java.lang.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)
      • 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 java.lang.Object getService()
        All ComponentManagers are ServiceFactory instances
        Returns:
        this as a ServiceFactory.
      • getProvidedServices

        protected java.lang.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

        java.util.concurrent.atomic.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()
      • clear

        void clear()
      • toString

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

        private boolean hasServiceRegistrationPermissions()
      • updateTargets

        final void updateTargets​(java.util.Map<java.lang.String,​java.lang.Object> properties)
      • verifyDependencyManagers

        protected boolean verifyDependencyManagers()
      • getDependencyManagers

        java.util.List<DependencyManager<S,​?>> getDependencyManagers()
        Returns an iterator over the DependencyManager objects representing the declared references in declaration order
      • getReversedDependencyManagers

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

        DependencyManager<S,​?> getDependencyManager​(java.lang.String name)
      • deactivateDependencyManagers

        private void deactivateDependencyManagers()
      • disableDependencyManagers

        private void disableDependencyManagers()
      • getProperties

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

        public abstract void setServiceProperties​(java.util.Dictionary<java.lang.String,​?> serviceProperties)
      • getServiceProperties

        public java.util.Dictionary<java.lang.String,​java.lang.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 java.util.Dictionary<java.lang.String,​java.lang.Object> copyTo​(java.util.Dictionary<java.lang.String,​java.lang.Object> target,
                                                                                              java.util.Map<java.lang.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 java.util.Map<java.lang.String,​java.lang.Object> copyToMap​(java.util.Dictionary<java.lang.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 java.util.Dictionary<java.lang.String,​java.lang.Object> copyToDictionary​(java.util.Dictionary<java.lang.String,​?> source,
                                                                                                        boolean allProps)
      • setFailureReason

        public void setFailureReason​(java.lang.Throwable e)
        Set the activation failure reason
        Parameters:
        e - The exception which caused the activation to fail
      • hasInstance

        abstract boolean hasInstance()
      • setServiceProperties

        public void setServiceProperties​(MethodResult methodResult,
                                         java.lang.Integer trackingCount)
      • postRegister

        abstract void postRegister()
      • preDeregister

        abstract void preDeregister()
      • reconfigure

        public abstract void reconfigure​(java.util.Map<java.lang.String,​java.lang.Object> configuration,
                                         boolean configurationDeleted,
                                         TargetedPID factoryPid)