Interface ResourceListener<T>
- Type Parameters:
T- The type for the Resource.
A ResourceListener is an OSGi service which is notified when a Resource Context violates one of the threshold defined by the listener.
Every ResourceListener is associated to a specific Resource Context and a specific Resource type. It defines two types of thresholds: a lower and a upper. A lower threshold is reached when the resource usage decreases below the threshold. On the contrary, an upper threshold is reached when the resource usage exceeds the threshold.
Both lower or upper threshold are two levels: a warning level and error level. The warning level indicates the resource usage becomes to be critical but are still acceptable. The error level indicates the resource usage is now critical for the overall system and actions should be taken.
A Resource Listener is registered with these two mandatory properties:
RESOURCE_CONTEXTwhich defines the ResourceContext associated to this ListenerRESOURCE_TYPEwhich the type of resource
Resource Listeners are associated to a Resource Context and a Resource
Monitor based on the RESOURCE_CONTEXT property and the
RESOURCE_TYPE property (both of them are mandatory at registration
time).
Once associated, the ResourceMonitor gets the threshold values through the
service properties (i.e UPPER_WARNING_THRESHOLD,
UPPER_ERROR_THRESHOLD, LOWER_WARNING_THRESHOLD and
LOWER_WARNING_THRESHOLD) and store them. Once it detects a new
resource consumption, it compares the new resource usage value with the
thresholds provided by the Resource Listener. If the resource usage violates
one of these thresholds, the Resource Monitor notifies the
ResourceListener through a call to notify(ResourceEvent).
A ResourceMonitor tracks threshold value modification by using a
ServiceListener.
- Version:
- 1.0
- Author:
- $Id: 1c29e2896b94e38e03e8daf5ada29b7441caea96 $
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringOptional property defining the value of the lower error threshold.static final StringOptional property defining the value of the lower warning threshold.static final StringMandatory property specifying the Resource Context associated with the listener.static final StringMandatory property defining the type of Resource (i.e the ResourceMonitor) associated to this Listener.static final StringOptional property defining the value of the upper error threshold.static final StringOptional property defining the value of the upper warning threshold. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the lower error threshold value set by the listener.Retrieves the lower warning threshold value set by the listener.Retrieves the upper error threshold value set by this listener.Retrieves the upper warning threshold value set by this listener.voidnotify(ResourceEvent<T> event) Receives a resource monitoring notification
-
Field Details
-
RESOURCE_CONTEXT
Mandatory property specifying the Resource Context associated with the listener.- See Also:
-
RESOURCE_TYPE
Mandatory property defining the type of Resource (i.e the ResourceMonitor) associated to this Listener.- See Also:
-
UPPER_WARNING_THRESHOLD
Optional property defining the value of the upper warning threshold.- See Also:
-
UPPER_ERROR_THRESHOLD
Optional property defining the value of the upper error threshold.- See Also:
-
LOWER_WARNING_THRESHOLD
Optional property defining the value of the lower warning threshold.- See Also:
-
LOWER_ERROR_THRESHOLD
Optional property defining the value of the lower error threshold.- See Also:
-
-
Method Details
-
notify
Receives a resource monitoring notification- Parameters:
event- TheResourceEventobject
-
getLowerWarningThreshold
Comparable<T> getLowerWarningThreshold()Retrieves the lower warning threshold value set by the listener. If the resource usage decreases under this threshold value, thenotify(ResourceEvent)will be called. The provided ResourceEvent then indicates the WARNING state is reached.- Returns:
- a comparable object or null if no threshold is set.
-
getLowerErrorThreshold
Comparable<T> getLowerErrorThreshold()Retrieves the lower error threshold value set by the listener. If the resource usage decreases under this threshold, thenotify(ResourceEvent)will be called. The providedResourceEventthen indicates the ERROR state is reached.- Returns:
- a comparable object or null if no threshold is set.
-
getUpperWarningThreshold
Comparable<T> getUpperWarningThreshold()Retrieves the upper warning threshold value set by this listener. If the resource usage exceeds this threshold, thenotify(ResourceEvent)method will be called. The providedResourceEventthen indicates the WARNING state is reached.- Returns:
- a comparable object or null if no threshold is reached.
-
getUpperErrorThreshold
Comparable<T> getUpperErrorThreshold()Retrieves the upper error threshold value set by this listener. If the resource usage exceeds this threshold, thenotify(ResourceEvent)will be called. The providedResourceEventthen indicates the ERROR state is reached.- Returns:
- a comparable object or null if no threshold is reached.
-