T - The type of the tracked object.public class ModuleTracker<T> extends Object implements ModuleTrackerCustomizer<T>
ModuleTracker class simplifies tracking modules much like the
ServiceTracker simplifies tracking services.
A ModuleTracker is constructed with state criteria and a
ModuleTrackerCustomizer object. A ModuleTracker can use the
ModuleTrackerCustomizer to select which modules are tracked and to
create a customized object to be tracked with the module. The
ModuleTracker can then be opened to begin tracking all modules whose
state matches the specified state criteria.
The getModules method can be called to get the Module objects
of the modules being tracked. The getObject method can be called to
get the customized object for a tracked module.
The ModuleTracker class is thread-safe. It does not call a
ModuleTrackerCustomizer while holding any locks.
ModuleTrackerCustomizer implementations must also be thread-safe.
| Modifier and Type | Field and Description |
|---|---|
protected ModuleContext |
context
The Module Context used by this
ModuleTracker. |
| Constructor and Description |
|---|
ModuleTracker(ModuleContext context,
ModuleTrackerCustomizer<T> customizer,
Module.State... states)
Create a
ModuleTracker for modules whose state is present in the
specified state mask. |
| Modifier and Type | Method and Description |
|---|---|
T |
addingModule(Module module,
ModuleEvent event)
Default implementation of the
ModuleTrackerCustomizer.addingModule method. |
void |
close()
Close this
ModuleTracker. |
Module[] |
getModules()
Return an array of
Modules for all modules being tracked by this
ModuleTracker. |
T |
getObject(Module module)
Returns the customized object for the specified
Module if the
specified module is being tracked by this ModuleTracker. |
Map<Module,T> |
getTracked()
Return a
Map with the Modules and customized objects for
all modules being tracked by this ModuleTracker. |
int |
getTrackingCount()
Returns the tracking count for this
ModuleTracker. |
boolean |
isEmpty()
Return if this
ModuleTracker is empty. |
void |
modifiedModule(Module module,
ModuleEvent event,
T object)
Default implementation of the
ModuleTrackerCustomizer.modifiedModule method. |
void |
open()
Open this
ModuleTracker and begin tracking modules. |
void |
remove(Module module)
Remove a module from this
ModuleTracker. |
void |
removedModule(Module module,
ModuleEvent event,
T object)
Default implementation of the
ModuleTrackerCustomizer.removedModule method. |
int |
size()
Return the number of modules being tracked by this
ModuleTracker. |
protected final ModuleContext context
ModuleTracker.public ModuleTracker(ModuleContext context, ModuleTrackerCustomizer<T> customizer, Module.State... states)
ModuleTracker for modules whose state is present in the
specified state mask.
Modules whose state is present on the specified state mask will be
tracked by this ModuleTracker.
context - The ModuleContext against which the tracking is
done.states - The list of the module states to be tracked.customizer - The customizer object to call when modules are added,
modified, or removed in this ModuleTracker. If customizer
is null, then this ModuleTracker will be used as
the ModuleTrackerCustomizer and this ModuleTracker
will call the ModuleTrackerCustomizer methods on itself.Module.getState()public void open()
ModuleTracker and begin tracking modules.
Module which match the state criteria specified when this
ModuleTracker was created are now tracked by this
ModuleTracker.
IllegalStateException - If the ModuleContext with
which this ModuleTracker was created is no longer valid.SecurityException - If the caller and this class do not
have the appropriate
AdminPermission[context module,LISTENER], and the Java
Runtime Environment supports permissions.public void close()
ModuleTracker.
This method should be called when this ModuleTracker should end
the tracking of modules.
This implementation calls getModules() to get the list of
tracked modules to remove.
public T addingModule(Module module, ModuleEvent event)
ModuleTrackerCustomizer.addingModule method.
This method is only called when this ModuleTracker has been
constructed with a null ModuleTrackerCustomizer argument.
This implementation simply returns the specified Module.
This method can be overridden in a subclass to customize the object to be tracked for the module being added.
addingModule in interface ModuleTrackerCustomizer<T>module - The Module being added to this
ModuleTracker object.event - The module event which caused this customizer method to be
called or null if there is no module event associated with
the call to this method.ModuleTrackerCustomizer.addingModule(Module, ModuleEvent)public void modifiedModule(Module module, ModuleEvent event, T object)
ModuleTrackerCustomizer.modifiedModule method.
This method is only called when this ModuleTracker has been
constructed with a null ModuleTrackerCustomizer argument.
This implementation does nothing.
modifiedModule in interface ModuleTrackerCustomizer<T>module - The Module whose state has been modified.event - The module event which caused this customizer method to be
called or null if there is no module event associated with
the call to this method.object - The customized object for the specified Module.ModuleTrackerCustomizer.modifiedModule(Module, ModuleEvent, Object)public void removedModule(Module module, ModuleEvent event, T object)
ModuleTrackerCustomizer.removedModule method.
This method is only called when this ModuleTracker has been
constructed with a null ModuleTrackerCustomizer argument.
This implementation does nothing.
removedModule in interface ModuleTrackerCustomizer<T>module - The Module being removed.event - The module event which caused this customizer method to be
called or null if there is no module event associated with
the call to this method.object - The customized object for the specified module.ModuleTrackerCustomizer.removedModule(Module, ModuleEvent, Object)public Module[] getModules()
Modules for all modules being tracked by this
ModuleTracker.Modules or null if no modules are
being tracked.public T getObject(Module module)
Module if the
specified module is being tracked by this ModuleTracker.module - The Module being tracked.Module or
null if the specified Module is not being
tracked.public void remove(Module module)
ModuleTracker.
The specified module will be removed from this ModuleTracker . If
the specified module was being tracked then the
ModuleTrackerCustomizer.removedModule method will be called for
that module.module - The Module to be removed.public int size()
ModuleTracker.public int getTrackingCount()
ModuleTracker.
The tracking count is initialized to 0 when this ModuleTracker is
opened. Every time a module is added, modified or removed from this
ModuleTracker the tracking count is incremented.
The tracking count can be used to determine if this ModuleTracker
has added, modified or removed a module by comparing a tracking count
value previously collected with the current tracking count value. If the
value has not changed, then no module has been added, modified or removed
from this ModuleTracker since the previous tracking count was
collected.
ModuleTracker or -1 if this
ModuleTracker is not open.public Map<Module,T> getTracked()
Map with the Modules and customized objects for
all modules being tracked by this ModuleTracker.Map with the Modules and customized objects for
all services being tracked by this ModuleTracker. If no
modules are being tracked, then the returned map is empty.public boolean isEmpty()
ModuleTracker is empty.true if this ModuleTracker is not tracking any
modules.Copyright © 2015 JBoss by Red Hat. All rights reserved.