blob: 100c6b4eaac0d1e7d74f83439856404d65799691 [file] [log] [blame]
Richard S. Hall8df9ab12009-07-24 17:06:37 +00001/*
2 * Copyright (c) OSGi Alliance (2007, 2008). All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.osgi.util.tracker;
18
19import org.osgi.framework.Bundle;
20import org.osgi.framework.BundleEvent;
21
22/**
23 * The <code>BundleTrackerCustomizer</code> interface allows a
24 * <code>BundleTracker</code> to customize the <code>Bundle</code>s that are
25 * tracked. A <code>BundleTrackerCustomizer</code> is called when a bundle is
26 * being added to a <code>BundleTracker</code>. The
27 * <code>BundleTrackerCustomizer</code> can then return an object for the
28 * tracked bundle. A <code>BundleTrackerCustomizer</code> is also called when a
29 * tracked bundle is modified or has been removed from a
30 * <code>BundleTracker</code>.
31 *
32 * <p>
33 * The methods in this interface may be called as the result of a
34 * <code>BundleEvent</code> being received by a <code>BundleTracker</code>.
35 * Since <code>BundleEvent</code>s are received synchronously by the
36 * <code>BundleTracker</code>, it is highly recommended that implementations of
37 * these methods do not alter bundle states while being synchronized on any
38 * object.
39 *
40 * <p>
41 * The <code>BundleTracker</code> class is thread-safe. It does not call a
42 * <code>BundleTrackerCustomizer</code> while holding any locks.
43 * <code>BundleTrackerCustomizer</code> implementations must also be
44 * thread-safe.
45 *
46 * @ThreadSafe
47 * @version $Revision: 5874 $
48 * @since 1.4
49 */
50public interface BundleTrackerCustomizer {
51 /**
52 * A bundle is being added to the <code>BundleTracker</code>.
53 *
54 * <p>
55 * This method is called before a bundle which matched the search parameters
56 * of the <code>BundleTracker</code> is added to the
57 * <code>BundleTracker</code>. This method should return the object to be
58 * tracked for the specified <code>Bundle</code>. The returned object is
59 * stored in the <code>BundleTracker</code> and is available from the
60 * {@link BundleTracker#getObject(Bundle) getObject} method.
61 *
62 * @param bundle The <code>Bundle</code> being added to the
63 * <code>BundleTracker</code>.
64 * @param event The bundle event which caused this customizer method to be
65 * called or <code>null</code> if there is no bundle event associated
66 * with the call to this method.
67 * @return The object to be tracked for the specified <code>Bundle</code>
68 * object or <code>null</code> if the specified <code>Bundle</code>
69 * object should not be tracked.
70 */
71 public Object addingBundle(Bundle bundle, BundleEvent event);
72
73 /**
74 * A bundle tracked by the <code>BundleTracker</code> has been modified.
75 *
76 * <p>
77 * This method is called when a bundle being tracked by the
78 * <code>BundleTracker</code> has had its state modified.
79 *
80 * @param bundle The <code>Bundle</code> whose state has been modified.
81 * @param event The bundle event which caused this customizer method to be
82 * called or <code>null</code> if there is no bundle event associated
83 * with the call to this method.
84 * @param object The tracked object for the specified bundle.
85 */
86 public void modifiedBundle(Bundle bundle, BundleEvent event,
87 Object object);
88
89 /**
90 * A bundle tracked by the <code>BundleTracker</code> has been removed.
91 *
92 * <p>
93 * This method is called after a bundle is no longer being tracked by the
94 * <code>BundleTracker</code>.
95 *
96 * @param bundle The <code>Bundle</code> that has been removed.
97 * @param event The bundle event which caused this customizer method to be
98 * called or <code>null</code> if there is no bundle event associated
99 * with the call to this method.
100 * @param object The tracked object for the specified bundle.
101 */
102 public void removedBundle(Bundle bundle, BundleEvent event,
103 Object object);
104}