|
OSGi™ Core Release 5 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.osgi.util.tracker.BundleTracker<T>
T
- The type of the tracked object.public class BundleTracker<T>
The 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.
Field Summary | |
---|---|
protected BundleContext |
context
The Bundle Context used by this BundleTracker . |
Constructor Summary | |
---|---|
BundleTracker(BundleContext context,
int stateMask,
BundleTrackerCustomizer<T> customizer)
Create a BundleTracker for bundles whose state is present in the
specified state mask. |
Method Summary | |
---|---|
T |
addingBundle(Bundle bundle,
BundleEvent event)
Default implementation of the BundleTrackerCustomizer.addingBundle method. |
void |
close()
Close this BundleTracker . |
Bundle[] |
getBundles()
Return an array of Bundle s for all bundles being tracked by this
BundleTracker . |
T |
getObject(Bundle bundle)
Returns the customized object for the specified Bundle if the
specified bundle is being tracked by this BundleTracker . |
java.util.Map<Bundle,T> |
getTracked()
Return a Map with the Bundle s and customized objects for
all bundles being tracked by this BundleTracker . |
int |
getTrackingCount()
Returns the tracking count for this BundleTracker . |
boolean |
isEmpty()
Return if this BundleTracker is empty. |
void |
modifiedBundle(Bundle bundle,
BundleEvent event,
T object)
Default implementation of the BundleTrackerCustomizer.modifiedBundle method. |
void |
open()
Open this BundleTracker and begin tracking bundles. |
void |
remove(Bundle bundle)
Remove a bundle from this BundleTracker . |
void |
removedBundle(Bundle bundle,
BundleEvent event,
T object)
Default implementation of the BundleTrackerCustomizer.removedBundle method. |
int |
size()
Return the number of bundles being tracked by this BundleTracker . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final BundleContext context
BundleTracker
.
Constructor Detail |
---|
public BundleTracker(BundleContext context, int stateMask, BundleTrackerCustomizer<T> customizer)
BundleTracker
for bundles whose state is present in the
specified state mask.
Bundles whose state is present on the specified state mask will be
tracked by this BundleTracker
.
context
- The BundleContext
against which the tracking is
done.stateMask
- The bit mask of the OR
ing of the bundle states
to be tracked.customizer
- The customizer object to call when bundles are added,
modified, or removed in this BundleTracker
. If customizer
is null
, then this BundleTracker
will be used as
the BundleTrackerCustomizer
and this BundleTracker
will call the BundleTrackerCustomizer
methods on itself.Bundle.getState()
Method Detail |
---|
public void open()
BundleTracker
and begin tracking bundles.
Bundle which match the state criteria specified when this
BundleTracker
was created are now tracked by this
BundleTracker
.
java.lang.IllegalStateException
- If the BundleContext
with
which this BundleTracker
was created is no longer valid.
java.lang.SecurityException
- If the caller and this class do not
have the appropriate
AdminPermission[context bundle,LISTENER]
, and the Java
Runtime Environment supports permissions.public void close()
BundleTracker
.
This method should be called when this BundleTracker
should end
the tracking of bundles.
This implementation calls getBundles()
to get the list of
tracked bundles to remove.
public T addingBundle(Bundle bundle, BundleEvent event)
BundleTrackerCustomizer.addingBundle
method.
This method is only called when this BundleTracker
has been
constructed with a null BundleTrackerCustomizer
argument.
This implementation simply returns the specified Bundle
.
This method can be overridden in a subclass to customize the object to be tracked for the bundle being added.
addingBundle
in interface BundleTrackerCustomizer<T>
bundle
- The Bundle
being added to this
BundleTracker
object.event
- The bundle event which caused this customizer method to be
called or null
if there is no bundle event associated with
the call to this method.
BundleTrackerCustomizer.addingBundle(Bundle, BundleEvent)
public void modifiedBundle(Bundle bundle, BundleEvent event, T object)
BundleTrackerCustomizer.modifiedBundle
method.
This method is only called when this BundleTracker
has been
constructed with a null BundleTrackerCustomizer
argument.
This implementation does nothing.
modifiedBundle
in interface BundleTrackerCustomizer<T>
bundle
- The Bundle
whose state has been modified.event
- The bundle event which caused this customizer method to be
called or null
if there is no bundle event associated with
the call to this method.object
- The customized object for the specified Bundle.BundleTrackerCustomizer.modifiedBundle(Bundle, BundleEvent, Object)
public void removedBundle(Bundle bundle, BundleEvent event, T object)
BundleTrackerCustomizer.removedBundle
method.
This method is only called when this BundleTracker
has been
constructed with a null BundleTrackerCustomizer
argument.
This implementation does nothing.
removedBundle
in interface BundleTrackerCustomizer<T>
bundle
- The Bundle
being removed.event
- The bundle event which caused this customizer method to be
called or null
if there is no bundle event associated with
the call to this method.object
- The customized object for the specified bundle.BundleTrackerCustomizer.removedBundle(Bundle, BundleEvent, Object)
public Bundle[] getBundles()
Bundle
s for all bundles being tracked by this
BundleTracker
.
Bundle
s or null
if no bundles are
being tracked.public T getObject(Bundle bundle)
Bundle
if the
specified bundle is being tracked by this BundleTracker
.
bundle
- The Bundle
being tracked.
Bundle
or
null
if the specified Bundle
is not being
tracked.public void remove(Bundle bundle)
BundleTracker
.
The specified bundle will be removed from this BundleTracker
. If
the specified bundle was being tracked then the
BundleTrackerCustomizer.removedBundle
method will be called for
that bundle.
bundle
- The Bundle
to be removed.public int size()
BundleTracker
.
public int getTrackingCount()
BundleTracker
.
The tracking count is initialized to 0 when this BundleTracker
is
opened. Every time a bundle is added, modified or removed from this
BundleTracker
the tracking count is incremented.
The tracking count can be used to determine if this BundleTracker
has added, modified or removed a bundle by comparing a tracking count
value previously collected with the current tracking count value. If the
value has not changed, then no bundle has been added, modified or removed
from this BundleTracker
since the previous tracking count was
collected.
BundleTracker
or -1 if this
BundleTracker
is not open.public java.util.Map<Bundle,T> getTracked()
Map
with the Bundle
s and customized objects for
all bundles being tracked by this BundleTracker
.
Map
with the Bundle
s and customized objects for
all services being tracked by this BundleTracker
. If no
bundles are being tracked, then the returned map is empty.public boolean isEmpty()
BundleTracker
is empty.
true
if this BundleTracker
is not tracking any
bundles.
|
OSGi™ Core Release 5 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |