BundleTracker class simplifies tracking bundles much like the
ServiceTracker simplifies tracking services.
A BundleTracker is constructed with state criteria and a
BundleTrackerCustomizer object. A BundleTracker can use the
BundleTrackerCustomizer to select which bundles are tracked and to
create a customized object to be tracked with the bundle. The
BundleTracker can then be opened to begin tracking all bundles whose
state matches the specified state criteria.
The getBundles method can be called to get the Bundle objects
of the bundles being tracked. The getObject method can be called to
get the customized object for a tracked bundle.
The BundleTracker class is thread-safe. It does not call a
BundleTrackerCustomizer while holding any locks.
BundleTrackerCustomizer implementations must also be thread-safe.
| Modifier and Type | Class and Description |
|---|---|
| private class | BundleTracker.
Inner class which subclasses AbstractTracked. |
| Modifier and Type | Field and Description |
|---|---|
| protected final BundleContext | context
The Bundle Context used by this |
| pack-priv final BundleTrackerCustomizer | customizer
The |
| pack-priv static final boolean | |
| pack-priv final int | mask
State mask for bundles being tracked. |
| private volatile BundleTracker | tracked
Tracked bundles: |
| Access | Constructor and Description |
|---|---|
| public | BundleTracker(BundleContext
The context, int BundleContext against which the tracking is
done.The bit mask of the stateMask, BundleTrackerCustomizer<T> ORing of the bundle states
to be tracked.The customizer object to call when bundles are added,
modified, or removed in this customizer)BundleTracker. If customizer
is null, then this BundleTracker will be used as
the BundleTrackerCustomizer and this BundleTracker
will call the BundleTrackerCustomizer methods on itself.Create a |
| Modifier and Type | Method and Description |
|---|---|
| public T | Returns: The specified bundle.The bundle, BundleEvent Bundle being added to this
BundleTracker object.The bundle event which caused this customizer method to be
called or event)null if there is no bundle event associated with
the call to this method.Implements org. Default implementation of the
|
| public void | |
| public Bundle[] | Returns: An array ofBundles or null if no bundles are
being tracked.Return an array of |
| public T | |
| public Map | Returns: AMap with the Bundles and customized objects for
all services being tracked by this BundleTracker. If no
bundles are being tracked, then the returned map is empty.Return a |
| public int | Returns: The tracking count for thisBundleTracker or -1 if this
BundleTracker is not open.Returns the tracking count for this |
| public boolean | Returns: true if this BundleTracker is not tracking any
bundles.Return if this |
| public void | modifiedBundle(Bundle
The bundle, BundleEvent Bundle whose state has been modified.The bundle event which caused this customizer method to be
called or event, T null if there is no bundle event associated with
the call to this method.The customized object for the specified Bundle. object)Implements org. Default implementation of the
|
| public void | |
| public void | |
| public void | removedBundle(Bundle
The bundle, BundleEvent Bundle being removed.The bundle event which caused this customizer method to be
called or event, T null if there is no bundle event associated with
the call to this method.The customized object for the specified bundle. object)Implements org. Default implementation of the
|
| public int | Returns: The number of bundles being tracked.Return the number of bundles being tracked by this |
| private BundleTracker |
| context | back to summary |
|---|---|
| protected final BundleContext context The Bundle Context used by this | |
| customizer | back to summary |
|---|---|
| pack-priv final BundleTrackerCustomizer<T> customizer The | |
| DEBUG | back to summary |
|---|---|
| pack-priv static final boolean DEBUG | |
| mask | back to summary |
|---|---|
| pack-priv final int mask State mask for bundles being tracked. This field contains the ORed values of the bundle states being tracked. | |
| tracked | back to summary |
|---|---|
| private volatile BundleTracker<T>. Tracked bundles: | |
| BundleTracker | back to summary |
|---|---|
| public BundleTracker(BundleContext context, int stateMask, BundleTrackerCustomizer<T> customizer) Create a
Bundles whose state is present on the specified state mask will be
tracked by this
| |
| addingBundle | back to summary |
|---|---|
| public T addingBundle(Bundle bundle, BundleEvent event) Implements org. Default implementation of the
This method is only called when this
This implementation simply returns the specified This method can be overridden in a subclass to customize the object to be tracked for the bundle being added.
| |
| close | back to summary |
|---|---|
| public void close() Close this
This method should be called when this
This implementation calls | |
| getBundles | back to summary |
|---|---|
| public Bundle[] getBundles() Return an array of
| |
| getObject | back to summary |
|---|---|
| public T getObject(Bundle bundle) Returns the customized object for the specified
| |
| getTracked | back to summary |
|---|---|
| public Map Return a | |
| getTrackingCount | back to summary |
|---|---|
| public int getTrackingCount() Returns the tracking count for this
The tracking count can be used to determine if this
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Return if this
| |
| modifiedBundle | back to summary |
|---|---|
| public void modifiedBundle(Bundle bundle, BundleEvent event, T object) Implements org. Default implementation of the
This method is only called when this This implementation does nothing.
| |
| open | back to summary |
|---|---|
| public void open() Open this
Bundle which match the state criteria specified when this
| |
| remove | back to summary |
|---|---|
| public void remove(Bundle bundle) Remove a bundle from this
| |
| removedBundle | back to summary |
|---|---|
| public void removedBundle(Bundle bundle, BundleEvent event, T object) Implements org. Default implementation of the
This method is only called when this This implementation does nothing.
| |
| size | back to summary |
|---|---|
| public int size() Return the number of bundles being tracked by this
| |
| tracked | back to summary |
|---|---|
| private BundleTracker Accessor method for the current Tracked object. This method is only intended to be used by the unsynchronized methods which do not modify the tracked field.
| |
SynchronousBundleListener object for the tracker.
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | bundleChanged(final BundleEvent
BundleEvent object from the framework.Implements org.
|
| pack-priv T | Returns: Customized object for the tracked item ornull if the
item is not to be tracked.Item to be tracked. item, final BundleEvent Action related object. related)Implements abstract org. Call the specific customizer adding method. |
| pack-priv void | customizerModified(final Bundle
Tracked item. item, final BundleEvent Action related object. related, final T Customized object for the tracked item. object)Implements abstract org. Call the specific customizer modified method. |
| pack-priv void | customizerRemoved(final Bundle
Tracked item. item, final BundleEvent Action related object. related, final T Customized object for the tracked item. object)Implements abstract org. Call the specific customizer removed method. |
| Tracked | back to summary |
|---|---|
| pack-priv Tracked() Tracked constructor. | |
| bundleChanged | back to summary |
|---|---|
| public void bundleChanged(final BundleEvent event) Implements org.
| |
| customizerAdding | back to summary |
|---|---|
| pack-priv T customizerAdding(final Bundle item, final BundleEvent related) Implements abstract org. Call the specific customizer adding method. This method must not be called while synchronized on this object.
| |
| customizerModified | back to summary |
|---|---|
| pack-priv void customizerModified(final Bundle item, final BundleEvent related, final T object) Implements abstract org. Call the specific customizer modified method. This method must not be called while synchronized on this object.
| |
| customizerRemoved | back to summary |
|---|---|
| pack-priv void customizerRemoved(final Bundle item, final BundleEvent related, final T object) Implements abstract org. Call the specific customizer removed method. This method must not be called while synchronized on this object.
| |