connect/src/main/java/org/apache/felix/connect/felix/framework/HookRegistry.java [71:234]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        for (final String serviceName : classNames)
        {
            if (serviceName.equals(hookClass.getName()))
            {
                // For a service factory, we can only match names.
                if (svcObj instanceof ServiceFactory)
                {
                    return true;
                }
                // For a service object, check if its class matches.
                if (hookClass.isAssignableFrom(svcObj.getClass()))
                {
                    return true;
                }
            }
        }

        return false;
    }

    private boolean isHook(final String serviceName, final Object svcObj)
    {
        final Class<?> hookClass = HOOK_CLASSES.get(serviceName);
        if ( hookClass != null )
        {
            // For a service factory, we can only match names.
            if (svcObj instanceof ServiceFactory)
            {
                return true;
            }
            // For a service object, check if its class matches.
            if (hookClass.isAssignableFrom(svcObj.getClass()))
            {
                return true;
            }
        }

        return false;
    }

    /**
     * Check and add the service to the set of hooks
     * @param classNames The service names
     * @param svcObj The service object
     * @param ref The service reference
     */
    public void addHooks(final String[] classNames, final Object svcObj, final ServiceReference<?> ref)
    {
        for(final String serviceName : classNames)
        {
            if (isHook(serviceName, svcObj))
            {
                synchronized (m_allHooks) // we need to sync as we replace the value
                {
                    SortedSet<ServiceReference<?>> hooks = m_allHooks.get(serviceName);
                    if (hooks == null)
                    {
                        hooks = new TreeSet<ServiceReference<?>>(Collections.reverseOrder());
                    }
                    else
                    {
                        hooks = new TreeSet<ServiceReference<?>>(hooks);
                    }
                    hooks.add(ref);
                    m_allHooks.put(serviceName, hooks);
                }
            }
        }
    }

    /**
     * Update the service ranking for a hook
     * @param ref The service reference
     */
    public void updateHooks(final ServiceReference<?> ref)
    {
        // We maintain the hooks sorted, so if ranking has changed for example,
        // we need to ensure the order remains correct by resorting the hooks.
        final Object svcObj = ((ServiceRegistrationImpl.ServiceReferenceImpl) ref)
                .getRegistration().getService();
        final String [] classNames = (String[]) ref.getProperty(Constants.OBJECTCLASS);

        for(final String serviceName : classNames)
        {
            if (isHook(serviceName, svcObj))
            {
                synchronized (m_allHooks) // we need to sync as we replace the value
                {
                    SortedSet<ServiceReference<?>> hooks = m_allHooks.get(serviceName);
                    if (hooks != null)
                    {
                        TreeSet<ServiceReference<?>> newHooks = new TreeSet<ServiceReference<?>>(Collections.reverseOrder());
                        for (ServiceReference<?> hook : hooks) {
                            newHooks.add(hook); // copy constructor / addAll() does not re-sort
                        }

                        m_allHooks.put(serviceName, newHooks);
                    }
                }
            }
        }
    }

    /**
     * Remove the service hooks
     * @param ref The service reference
     */
    public void removeHooks(final ServiceReference<?> ref)
    {
        final Object svcObj = ((ServiceRegistrationImpl.ServiceReferenceImpl) ref)
            .getRegistration().getService();
        final String [] classNames = (String[]) ref.getProperty(Constants.OBJECTCLASS);

        for(final String serviceName : classNames)
        {
            if (isHook(serviceName, svcObj))
            {
                synchronized (m_allHooks) // we need to sync as we replace the value
                {
                    SortedSet<ServiceReference<?>> hooks = m_allHooks.get(serviceName);
                    if (hooks != null)
                    {
                        hooks = new TreeSet<ServiceReference<?>>(hooks);
                        hooks.remove(ref);
                        m_allHooks.put(serviceName, hooks);
                    }
                }
            }
        }
        synchronized ( m_blackList )
        {
            m_blackList.remove(ref);
        }
    }

    /**
     * Return the sorted set of hooks
     * @param hookClass The hook class
     * @return The sorted set - the set might be empty
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public <S> Set<ServiceReference<S>> getHooks(final Class<S> hookClass)
    {
        final Set<ServiceReference<?>> hooks = m_allHooks.get(hookClass.getName());
        if (hooks != null)
        {
            return (Set)hooks;
        }
        return Collections.emptySet();
    }

    public boolean isHookBlackListed(final ServiceReference<?> sr)
    {
        synchronized ( m_blackList )
        {
            return m_blackList.containsKey(sr);
        }
    }

    public void blackListHook(final ServiceReference<?> sr)
    {
        synchronized ( m_blackList )
        {
            m_blackList.put(sr, sr);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



framework/src/main/java/org/apache/felix/framework/HookRegistry.java [71:234]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        for (final String serviceName : classNames)
        {
            if (serviceName.equals(hookClass.getName()))
            {
                // For a service factory, we can only match names.
                if (svcObj instanceof ServiceFactory)
                {
                    return true;
                }
                // For a service object, check if its class matches.
                if (hookClass.isAssignableFrom(svcObj.getClass()))
                {
                    return true;
                }
            }
        }

        return false;
    }

    private boolean isHook(final String serviceName, final Object svcObj)
    {
        final Class<?> hookClass = HOOK_CLASSES.get(serviceName);
        if ( hookClass != null )
        {
            // For a service factory, we can only match names.
            if (svcObj instanceof ServiceFactory)
            {
                return true;
            }
            // For a service object, check if its class matches.
            if (hookClass.isAssignableFrom(svcObj.getClass()))
            {
                return true;
            }
        }

        return false;
    }

    /**
     * Check and add the service to the set of hooks
     * @param classNames The service names
     * @param svcObj The service object
     * @param ref The service reference
     */
    public void addHooks(final String[] classNames, final Object svcObj, final ServiceReference<?> ref)
    {
        for(final String serviceName : classNames)
        {
            if (isHook(serviceName, svcObj))
            {
                synchronized (m_allHooks) // we need to sync as we replace the value
                {
                    SortedSet<ServiceReference<?>> hooks = m_allHooks.get(serviceName);
                    if (hooks == null)
                    {
                        hooks = new TreeSet<ServiceReference<?>>(Collections.reverseOrder());
                    }
                    else
                    {
                        hooks = new TreeSet<ServiceReference<?>>(hooks);
                    }
                    hooks.add(ref);
                    m_allHooks.put(serviceName, hooks);
                }
            }
        }
    }

    /**
     * Update the service ranking for a hook
     * @param ref The service reference
     */
    public void updateHooks(final ServiceReference<?> ref)
    {
        // We maintain the hooks sorted, so if ranking has changed for example,
        // we need to ensure the order remains correct by resorting the hooks.
        final Object svcObj = ((ServiceRegistrationImpl.ServiceReferenceImpl) ref)
                .getRegistration().getService();
        final String [] classNames = (String[]) ref.getProperty(Constants.OBJECTCLASS);

        for(final String serviceName : classNames)
        {
            if (isHook(serviceName, svcObj))
            {
                synchronized (m_allHooks) // we need to sync as we replace the value
                {
                    SortedSet<ServiceReference<?>> hooks = m_allHooks.get(serviceName);
                    if (hooks != null)
                    {
                        TreeSet<ServiceReference<?>> newHooks = new TreeSet<ServiceReference<?>>(Collections.reverseOrder());
                        for (ServiceReference<?> hook : hooks) {
                            newHooks.add(hook); // copy constructor / addAll() does not re-sort
                        }

                        m_allHooks.put(serviceName, newHooks);
                    }
                }
            }
        }
    }

    /**
     * Remove the service hooks
     * @param ref The service reference
     */
    public void removeHooks(final ServiceReference<?> ref)
    {
        final Object svcObj = ((ServiceRegistrationImpl.ServiceReferenceImpl) ref)
            .getRegistration().getService();
        final String [] classNames = (String[]) ref.getProperty(Constants.OBJECTCLASS);

        for(final String serviceName : classNames)
        {
            if (isHook(serviceName, svcObj))
            {
                synchronized (m_allHooks) // we need to sync as we replace the value
                {
                    SortedSet<ServiceReference<?>> hooks = m_allHooks.get(serviceName);
                    if (hooks != null)
                    {
                        hooks = new TreeSet<ServiceReference<?>>(hooks);
                        hooks.remove(ref);
                        m_allHooks.put(serviceName, hooks);
                    }
                }
            }
        }
        synchronized ( m_blackList )
        {
            m_blackList.remove(ref);
        }
    }

    /**
     * Return the sorted set of hooks
     * @param hookClass The hook class
     * @return The sorted set - the set might be empty
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public <S> Set<ServiceReference<S>> getHooks(final Class<S> hookClass)
    {
        final Set<ServiceReference<?>> hooks = m_allHooks.get(hookClass.getName());
        if (hooks != null)
        {
            return (Set)hooks;
        }
        return Collections.emptySet();
    }

    public boolean isHookBlackListed(final ServiceReference<?> sr)
    {
        synchronized ( m_blackList )
        {
            return m_blackList.containsKey(sr);
        }
    }

    public void blackListHook(final ServiceReference<?> sr)
    {
        synchronized ( m_blackList )
        {
            m_blackList.put(sr, sr);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



