blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractTracked.java [224:445]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                modified(); /* increment modification count */
            }
        }

        if (object == null) { /* we are not tracking the item */
            trackAdding(item, related);
        } else {
			/* Call customizer outside of synchronized region */
            customizerModified(item, related, object);
			/*
			 * If the customizer throws an unchecked exception, it is safe to
			 * let it propagate
			 */
        }
    }

    /**
     * Common logic to add an item to the tracker used by track and
     * trackInitial. The specified item must have been placed in the adding list
     * before calling this method.
     *
     * @param item Item to be tracked.
     * @param related Action related object.
     */
    private void trackAdding(final S item, final R related) {
        if (DEBUG) {
            System.out.println("AbstractTracked.trackAdding: " + item); //$NON-NLS-1$
        }
        T object = null;
        boolean becameUntracked = false;
		/* Call customizer outside of synchronized region */
        try {
            object = customizerAdding(item, related);
			/*
			 * If the customizer throws an unchecked exception, it will
			 * propagate after the finally
			 */
        } finally {
            synchronized (this) {
                if (adding.remove(item) && !closed) {
					/*
					 * if the item was not untracked during the customizer
					 * callback
					 */
                    if (object != null) {
                        tracked.put(item, object);
                        modified(); /* increment modification count */
                        notifyAll(); /* notify any waiters */
                    }
                } else {
                    becameUntracked = true;
                }
            }
        }
		/*
		 * The item became untracked during the customizer callback.
		 */
        if (becameUntracked && (object != null)) {
            if (DEBUG) {
                System.out.println("AbstractTracked.trackAdding[removed]: " + item); //$NON-NLS-1$
            }
			/* Call customizer outside of synchronized region */
            customizerRemoved(item, related, object);
			/*
			 * If the customizer throws an unchecked exception, it is safe to
			 * let it propagate
			 */
        }
    }

    /**
     * Discontinue tracking the item.
     *
     * @param item Item to be untracked.
     * @param related Action related object.
     */
    void untrack(final S item, final R related) {
        final T object;
        synchronized (this) {
            if (initial.remove(item)) { /*
										 * if this item is already in the list
										 * of initial references to process
										 */
                if (DEBUG) {
                    System.out.println("AbstractTracked.untrack[removed from initial]: " + item); //$NON-NLS-1$
                }
                return; /*
						 * we have removed it from the list and it will not be
						 * processed
						 */
            }

            if (adding.remove(item)) { /*
										 * if the item is in the process of
										 * being added
										 */
                if (DEBUG) {
                    System.out.println("AbstractTracked.untrack[being added]: " + item); //$NON-NLS-1$
                }
                return; /*
						 * in case the item is untracked while in the process of
						 * adding
						 */
            }
            object = tracked.remove(item); /*
											 * must remove from tracker before
											 * calling customizer callback
											 */
            if (object == null) { /* are we actually tracking the item */
                return;
            }
            modified(); /* increment modification count */
        }
        if (DEBUG) {
            System.out.println("AbstractTracked.untrack[removed]: " + item); //$NON-NLS-1$
        }
		/* Call customizer outside of synchronized region */
        customizerRemoved(item, related, object);
		/*
		 * If the customizer throws an unchecked exception, it is safe to let it
		 * propagate
		 */
    }

    /**
     * Returns the number of tracked items.
     *
     * @return The number of tracked items.
     *
     * @GuardedBy this
     */
    int size() {
        return tracked.size();
    }

    /**
     * Returns if the tracker is empty.
     *
     * @return Whether the tracker is empty.
     *
     * @GuardedBy this
     * @since 1.5
     */
    boolean isEmpty() {
        return tracked.isEmpty();
    }

    /**
     * Return the customized object for the specified item
     *
     * @param item The item to lookup in the map
     * @return The customized object for the specified item.
     *
     * @GuardedBy this
     */
    T getCustomizedObject(final S item) {
        return tracked.get(item);
    }

    /**
     * Copy the tracked items into an array.
     *
     * @param list An array to contain the tracked items.
     * @return The specified list if it is large enough to hold the tracked
     *         items or a new array large enough to hold the tracked items.
     * @GuardedBy this
     */
    S[] copyKeys(final S[] list) {
        return tracked.keySet().toArray(list);
    }

    /**
     * Increment the modification count. If this method is overridden, the
     * overriding method MUST call this method to increment the tracking count.
     *
     * @GuardedBy this
     */
    void modified() {
        trackingCount++;
    }

    /**
     * Returns the tracking count for this {@code ServiceTracker} object.
     *
     * The tracking count is initialized to 0 when this object is opened. Every
     * time an item is added, modified or removed from this object the tracking
     * count is incremented.
     *
     * @GuardedBy this
     * @return The tracking count for this object.
     */
    int getTrackingCount() {
        return trackingCount;
    }

    /**
     * Copy the tracked items and associated values into the specified map.
     *
     * @param <M> Type of {@code Map} to hold the tracked items and associated
     *        values.
     * @param map The map into which to copy the tracked items and associated
     *        values. This map must not be a user provided map so that user code
     *        is not executed while synchronized on this.
     * @return The specified map.
     * @GuardedBy this
     * @since 1.5
     */
    <M extends Map<? super S, ? super T>> M copyEntries(final M map) {
        map.putAll(tracked);
        return map;
    }

    /**
     * Call the specific customizer adding method. This method must not be
     * called while synchronized on this object.
     *
     * @param item Item to be tracked.
     * @param related Action related object.
     * @return Customized object for the tracked item or {@code null} if the
     *         item is not to be tracked.
     */
    abstract T customizerAdding(final S item, final R related);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



util/src/main/java/org/apache/aries/util/tracker/hook/BundleHookBundleTracker.java [718:936]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                    modified(); /* increment modification count */
                }
            }

            if (object == null) { /* we are not tracking the item */
                trackAdding(item, related);
            } else {
                /* Call customizer outside of synchronized region */
                customizerModified(item, related, object);
                /*
                 * If the customizer throws an unchecked exception, it is safe to
                 * let it propagate
                 */
            }
        }

        /**
         * Common logic to add an item to the tracker used by track and
         * trackInitial. The specified item must have been placed in the adding list
         * before calling this method.
         *
         * @param item    Item to be tracked.
         * @param related Action related object.
         */
        private void trackAdding(final S item, final R related) {
            if (DEBUG) {
                System.out.println("AbstractTracked.trackAdding: " + item); //$NON-NLS-1$
            }
            T object = null;
            boolean becameUntracked = false;
            /* Call customizer outside of synchronized region */
            try {
                object = customizerAdding(item, related);
                /*
                 * If the customizer throws an unchecked exception, it will
                 * propagate after the finally
                 */
            } finally {
                synchronized (this) {
                    if (adding.remove(item) && !closed) {
                        /*
                         * if the item was not untracked during the customizer
                         * callback
                         */
                        if (object != null) {
                            tracked.put(item, object);
                            modified(); /* increment modification count */
                            notifyAll(); /* notify any waiters */
                        }
                    } else {
                        becameUntracked = true;
                    }
                }
            }
            /*
             * The item became untracked during the customizer callback.
             */
            if (becameUntracked && (object != null)) {
                if (DEBUG) {
                    System.out.println("AbstractTracked.trackAdding[removed]: " + item); //$NON-NLS-1$
                }
                /* Call customizer outside of synchronized region */
                customizerRemoved(item, related, object);
                /*
                 * If the customizer throws an unchecked exception, it is safe to
                 * let it propagate
                 */
            }
        }

        /**
         * Discontinue tracking the item.
         *
         * @param item    Item to be untracked.
         * @param related Action related object.
         */
        void untrack(final S item, final R related) {
            final T object;
            synchronized (this) {
                if (initial.remove(item)) { /*
										     * if this item is already in the list
										     * of initial references to process
										     */
                    if (DEBUG) {
                        System.out.println("AbstractTracked.untrack[removed from initial]: " + item); //$NON-NLS-1$
                    }
                    return; /*
						     * we have removed it from the list and it will not be
						     * processed
						     */
                }

                if (adding.remove(item)) { /*
										    * if the item is in the process of
										    * being added
										    */
                    if (DEBUG) {
                        System.out.println("AbstractTracked.untrack[being added]: " + item); //$NON-NLS-1$
                    }
                    return; /*
						     * in case the item is untracked while in the process of
						     * adding
						     */
                }
                object = tracked.remove(item); /*
											    * must remove from tracker before
											    * calling customizer callback
											    */
                if (object == null) { /* are we actually tracking the item */
                    return;
                }
                modified(); /* increment modification count */
            }
            if (DEBUG) {
                System.out.println("AbstractTracked.untrack[removed]: " + item); //$NON-NLS-1$
            }
            /* Call customizer outside of synchronized region */
            customizerRemoved(item, related, object);
            /*
             * If the customizer throws an unchecked exception, it is safe to let it
             * propagate
             */
        }

        /**
         * Returns the number of tracked items.
         *
         * @return The number of tracked items.
         * @GuardedBy this
         */
        int size() {
            return tracked.size();
        }

        /**
         * Returns if the tracker is empty.
         *
         * @return Whether the tracker is empty.
         * @GuardedBy this
         * @since 1.5
         */
        boolean isEmpty() {
            return tracked.isEmpty();
        }

        /**
         * Return the customized object for the specified item
         *
         * @param item The item to lookup in the map
         * @return The customized object for the specified item.
         * @GuardedBy this
         */
        T getCustomizedObject(final S item) {
            return tracked.get(item);
        }

        /**
         * Copy the tracked items into an array.
         *
         * @param list An array to contain the tracked items.
         * @return The specified list if it is large enough to hold the tracked
         *         items or a new array large enough to hold the tracked items.
         * @GuardedBy this
         */
        S[] copyKeys(final S[] list) {
            return tracked.keySet().toArray(list);
        }

        /**
         * Increment the modification count. If this method is overridden, the
         * overriding method MUST call this method to increment the tracking count.
         *
         * @GuardedBy this
         */
        void modified() {
            trackingCount++;
        }

        /**
         * Returns the tracking count for this {@code ServiceTracker} object.
         * <p/>
         * The tracking count is initialized to 0 when this object is opened. Every
         * time an item is added, modified or removed from this object the tracking
         * count is incremented.
         *
         * @return The tracking count for this object.
         * @GuardedBy this
         */
        int getTrackingCount() {
            return trackingCount;
        }

        /**
         * Copy the tracked items and associated values into the specified map.
         *
         * @param <M> Type of {@code Map} to hold the tracked items and
         *            associated values.
         * @param map The map into which to copy the tracked items and associated
         *            values. This map must not be a user provided map so that user code
         *            is not executed while synchronized on this.
         * @return The specified map.
         * @GuardedBy this
         * @since 1.5
         */
        <M extends Map<? super S, ? super T>> M copyEntries(final M map) {
            map.putAll(tracked);
            return map;
        }

        /**
         * Call the specific customizer adding method. This method must not be
         * called while synchronized on this object.
         *
         * @param item    Item to be tracked.
         * @param related Action related object.
         * @return Customized object for the tracked item or {@code null} if
         *         the item is not to be tracked.
         */
        abstract T customizerAdding(final S item, final R related);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



