001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018/*
019 * Copyright (c) OSGi Alliance (2007, 2008). All Rights Reserved.
020 * 
021 * Licensed under the Apache License, Version 2.0 (the "License");
022 * you may not use this file except in compliance with the License.
023 * You may obtain a copy of the License at
024 *
025 *      http://www.apache.org/licenses/LICENSE-2.0
026 *
027 * Unless required by applicable law or agreed to in writing, software
028 * distributed under the License is distributed on an "AS IS" BASIS,
029 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
030 * See the License for the specific language governing permissions and
031 * limitations under the License.
032 */
033
034package org.apache.camel.impl.osgi.tracker;
035
036import org.osgi.framework.Bundle;
037import org.osgi.framework.BundleEvent;
038
039/**
040 * The <code>BundleTrackerCustomizer</code> interface allows a
041 * <code>BundleTracker</code> to customize the <code>Bundle</code>s that are
042 * tracked. A <code>BundleTrackerCustomizer</code> is called when a bundle is
043 * being added to a <code>BundleTracker</code>. The
044 * <code>BundleTrackerCustomizer</code> can then return an object for the
045 * tracked bundle. A <code>BundleTrackerCustomizer</code> is also called when a
046 * tracked bundle is modified or has been removed from a
047 * <code>BundleTracker</code>.
048 * 
049 * <p>
050 * The methods in this interface may be called as the result of a
051 * <code>BundleEvent</code> being received by a <code>BundleTracker</code>.
052 * Since <code>BundleEvent</code>s are received synchronously by the
053 * <code>BundleTracker</code>, it is highly recommended that implementations of
054 * these methods do not alter bundle states while being synchronized on any
055 * object.
056 * 
057 * <p>
058 * The <code>BundleTracker</code> class is thread-safe. It does not call a
059 * <code>BundleTrackerCustomizer</code> while holding any locks.
060 * <code>BundleTrackerCustomizer</code> implementations must also be
061 * thread-safe.
062 * 
063 * @ThreadSafe
064 * @version 
065 * @since 1.4
066 */
067public interface BundleTrackerCustomizer {
068    /**
069     * A bundle is being added to the <code>BundleTracker</code>.
070     * <p>
071     * This method is called before a bundle which matched the search parameters
072     * of the <code>BundleTracker</code> is added to the
073     * <code>BundleTracker</code>. This method should return the object to be
074     * tracked for the specified <code>Bundle</code>. The returned object is
075     * stored in the <code>BundleTracker</code> and is available from the
076     * {@link BundleTracker#getObject(Bundle) getObject} method.
077     * 
078     * @param bundle The <code>Bundle</code> being added to the
079     *            <code>BundleTracker</code>.
080     * @param event The bundle event which caused this customizer method to be
081     *            called or <code>null</code> if there is no bundle event
082     *            associated with the call to this method.
083     * @return The object to be tracked for the specified <code>Bundle</code>
084     *         object or <code>null</code> if the specified <code>Bundle</code>
085     *         object should not be tracked.
086     */
087    Object addingBundle(Bundle bundle, BundleEvent event);
088
089    /**
090     * A bundle tracked by the <code>BundleTracker</code> has been modified.
091     * <p>
092     * This method is called when a bundle being tracked by the
093     * <code>BundleTracker</code> has had its state modified.
094     * 
095     * @param bundle The <code>Bundle</code> whose state has been modified.
096     * @param event The bundle event which caused this customizer method to be
097     *            called or <code>null</code> if there is no bundle event
098     *            associated with the call to this method.
099     * @param object The tracked object for the specified bundle.
100     */
101    void modifiedBundle(Bundle bundle, BundleEvent event, Object object);
102
103    /**
104     * A bundle tracked by the <code>BundleTracker</code> has been removed.
105     * <p>
106     * This method is called after a bundle is no longer being tracked by the
107     * <code>BundleTracker</code>.
108     * 
109     * @param bundle The <code>Bundle</code> that has been removed.
110     * @param event The bundle event which caused this customizer method to be
111     *            called or <code>null</code> if there is no bundle event
112     *            associated with the call to this method.
113     * @param object The tracked object for the specified bundle.
114     */
115    void removedBundle(Bundle bundle, BundleEvent event, Object object);
116}