blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractTracked.java [42:214]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    static final boolean		DEBUG	= false;

    /**
     * Map of tracked items to customized objects.
     *
     * @GuardedBy this
     */
    private final Map<S, T>		tracked;

    /**
     * Modification count. This field is initialized to zero and incremented by
     * modified.
     *
     * @GuardedBy this
     */
    private int					trackingCount;

    /**
     * List of items in the process of being added. This is used to deal with
     * nesting of events. Since events may be synchronously delivered, events
     * can be nested. For example, when processing the adding of a service and
     * the customizer causes the service to be unregistered, notification to the
     * nested call to untrack that the service was unregistered can be made to
     * the track method.
     *
     * Since the ArrayList implementation is not synchronized, all access to
     * this list must be protected by the same synchronized object for
     * thread-safety.
     *
     * @GuardedBy this
     */
    private final List<S>		adding;

    /**
     * true if the tracked object is closed.
     *
     * This field is volatile because it is set by one thread and read by
     * another.
     */
    volatile boolean			closed;

    /**
     * Initial list of items for the tracker. This is used to correctly process
     * the initial items which could be modified before they are tracked. This
     * is necessary since the initial set of tracked items are not "announced"
     * by events and therefore the event which makes the item untracked could be
     * delivered before we track the item.
     *
     * An item must not be in both the initial and adding lists at the same
     * time. An item must be moved from the initial list to the adding list
     * "atomically" before we begin tracking it.
     *
     * Since the LinkedList implementation is not synchronized, all access to
     * this list must be protected by the same synchronized object for
     * thread-safety.
     *
     * @GuardedBy this
     */
    private final LinkedList<S>	initial;

    /**
     * AbstractTracked constructor.
     */
    AbstractTracked() {
        tracked = new HashMap<S, T>();
        trackingCount = 0;
        adding = new ArrayList<S>(6);
        initial = new LinkedList<S>();
        closed = false;
    }

    /**
     * Set initial list of items into tracker before events begin to be
     * received.
     *
     * This method must be called from Tracker's open method while synchronized
     * on this object in the same synchronized block as the add listener call.
     *
     * @param list The initial list of items to be tracked. {@code null} entries
     *        in the list are ignored.
     * @GuardedBy this
     */
    void setInitial(S[] list) {
        if (list == null) {
            return;
        }
        for (S item : list) {
            if (item == null) {
                continue;
            }
            if (DEBUG) {
                System.out.println("AbstractTracked.setInitial: " + item); //$NON-NLS-1$
            }
            initial.add(item);
        }
    }

    /**
     * Track the initial list of items. This is called after events can begin to
     * be received.
     *
     * This method must be called from Tracker's open method while not
     * synchronized on this object after the add listener call.
     *
     */
    void trackInitial() {
        while (true) {
            S item;
            synchronized (this) {
                if (closed || (initial.size() == 0)) {
					/*
					 * if there are no more initial items
					 */
                    return; /* we are done */
                }
				/*
				 * move the first item from the initial list to the adding list
				 * within this synchronized block.
				 */
                item = initial.removeFirst();
                if (tracked.get(item) != null) {
					/* if we are already tracking this item */
                    if (DEBUG) {
                        System.out.println("AbstractTracked.trackInitial[already tracked]: " + item); //$NON-NLS-1$
                    }
                    continue; /* skip this item */
                }
                if (adding.contains(item)) {
					/*
					 * if this item is already in the process of being added.
					 */
                    if (DEBUG) {
                        System.out.println("AbstractTracked.trackInitial[already adding]: " + item); //$NON-NLS-1$
                    }
                    continue; /* skip this item */
                }
                adding.add(item);
            }
            if (DEBUG) {
                System.out.println("AbstractTracked.trackInitial: " + item); //$NON-NLS-1$
            }
            trackAdding(item, null); /*
									 * Begin tracking it. We call trackAdding
									 * since we have already put the item in the
									 * adding list.
									 */
        }
    }

    /**
     * Called by the owning Tracker object when it is closed.
     */
    void close() {
        closed = true;
    }

    /**
     * Begin to track an item.
     *
     * @param item Item to be tracked.
     * @param related Action related object.
     */
    void track(final S item, final R related) {
        final T object;
        synchronized (this) {
            if (closed) {
                return;
            }
            object = tracked.get(item);
            if (object == null) { /* we are not tracking the item */
                if (adding.contains(item)) {
					/* if this item is already in the process of being added. */
                    if (DEBUG) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



util/src/main/java/org/apache/aries/util/tracker/hook/BundleHookBundleTracker.java [535:706]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        static final boolean DEBUG = false;

        /**
         * Map of tracked items to customized objects.
         *
         * @GuardedBy this
         */
        private final Map<S, T> tracked;

        /**
         * Modification count. This field is initialized to zero and incremented by
         * modified.
         *
         * @GuardedBy this
         */
        private int trackingCount;

        /**
         * List of items in the process of being added. This is used to deal with
         * nesting of events. Since events may be synchronously delivered, events
         * can be nested. For example, when processing the adding of a service and
         * the customizer causes the service to be unregistered, notification to the
         * nested call to untrack that the service was unregistered can be made to
         * the track method.
         * <p/>
         * Since the ArrayList implementation is not synchronized, all access to
         * this list must be protected by the same synchronized object for
         * thread-safety.
         *
         * @GuardedBy this
         */
        private final List<S> adding;

        /**
         * true if the tracked object is closed.
         * <p/>
         * This field is volatile because it is set by one thread and read by
         * another.
         */
        volatile boolean closed;

        /**
         * Initial list of items for the tracker. This is used to correctly process
         * the initial items which could be modified before they are tracked. This
         * is necessary since the initial set of tracked items are not "announced"
         * by events and therefore the event which makes the item untracked could be
         * delivered before we track the item.
         * <p/>
         * An item must not be in both the initial and adding lists at the same
         * time. An item must be moved from the initial list to the adding list
         * "atomically" before we begin tracking it.
         * <p/>
         * Since the LinkedList implementation is not synchronized, all access to
         * this list must be protected by the same synchronized object for
         * thread-safety.
         *
         * @GuardedBy this
         */
        private final LinkedList<S> initial;

        /**
         * AbstractTracked constructor.
         */
        AbstractTracked() {
            tracked = new HashMap<S, T>();
            trackingCount = 0;
            adding = new ArrayList<S>(6);
            initial = new LinkedList<S>();
            closed = false;
        }

        /**
         * Set initial list of items into tracker before events begin to be
         * received.
         * <p/>
         * This method must be called from Tracker's open method while synchronized
         * on this object in the same synchronized block as the add listener call.
         *
         * @param list The initial list of items to be tracked. {@code null}
         *             entries in the list are ignored.
         * @GuardedBy this
         */
        void setInitial(S[] list) {
            if (list == null) {
                return;
            }
            for (S item : list) {
                if (item == null) {
                    continue;
                }
                if (DEBUG) {
                    System.out.println("AbstractTracked.setInitial: " + item); //$NON-NLS-1$
                }
                initial.add(item);
            }
        }

        /**
         * Track the initial list of items. This is called after events can begin to
         * be received.
         * <p/>
         * This method must be called from Tracker's open method while not
         * synchronized on this object after the add listener call.
         */
        void trackInitial() {
            while (true) {
                S item;
                synchronized (this) {
                    if (closed || (initial.size() == 0)) {
                        /*
                         * if there are no more initial items
                         */
                        return; /* we are done */
                    }
                    /*
                    * move the first item from the initial list to the adding list
                    * within this synchronized block.
                    */
                    item = initial.removeFirst();
                    if (tracked.get(item) != null) {
                        /* if we are already tracking this item */
                        if (DEBUG) {
                            System.out.println("AbstractTracked.trackInitial[already tracked]: " + item); //$NON-NLS-1$
                        }
                        continue; /* skip this item */
                    }
                    if (adding.contains(item)) {
                        /*
                         * if this item is already in the process of being added.
                         */
                        if (DEBUG) {
                            System.out.println("AbstractTracked.trackInitial[already adding]: " + item); //$NON-NLS-1$
                        }
                        continue; /* skip this item */
                    }
                    adding.add(item);
                }
                if (DEBUG) {
                    System.out.println("AbstractTracked.trackInitial: " + item); //$NON-NLS-1$
                }
                trackAdding(item, null); /*
                                          * Begin tracking it. We call trackAdding
									      * since we have already put the item in the
									      * adding list.
									      */
            }
        }

        /**
         * Called by the owning Tracker object when it is closed.
         */
        void close() {
            closed = true;
        }

        /**
         * Begin to track an item.
         *
         * @param item    Item to be tracked.
         * @param related Action related object.
         */
        void track(final S item, final R related) {
            final T object;
            synchronized (this) {
                if (closed) {
                    return;
                }
                object = tracked.get(item);
                if (object == null) { /* we are not tracking the item */
                    if (adding.contains(item)) {
                        /* if this item is already in the process of being added. */
                        if (DEBUG) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



