Interface ResourceListener<T>

Type Parameters:
T - The type for the Resource.

public interface ResourceListener<T>

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:

The next optional properties are used to specify threshold values. A ResourceListener must at least provides one of them: These threshold values can also be retrieved through methods.

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.

  • Field Details

    • RESOURCE_CONTEXT

      static final String RESOURCE_CONTEXT
      Mandatory property specifying the Resource Context associated with the listener.
      See Also:
    • RESOURCE_TYPE

      static final String RESOURCE_TYPE
      Mandatory property defining the type of Resource (i.e the ResourceMonitor) associated to this Listener.
      See Also:
    • UPPER_WARNING_THRESHOLD

      static final String UPPER_WARNING_THRESHOLD
      Optional property defining the value of the upper warning threshold.
      See Also:
    • UPPER_ERROR_THRESHOLD

      static final String UPPER_ERROR_THRESHOLD
      Optional property defining the value of the upper error threshold.
      See Also:
    • LOWER_WARNING_THRESHOLD

      static final String LOWER_WARNING_THRESHOLD
      Optional property defining the value of the lower warning threshold.
      See Also:
    • LOWER_ERROR_THRESHOLD

      static final String LOWER_ERROR_THRESHOLD
      Optional property defining the value of the lower error threshold.
      See Also:
  • Method Details

    • notify

      void notify(ResourceEvent<T> event)
      Receives a resource monitoring notification
      Parameters:
      event - The ResourceEvent object
    • getLowerWarningThreshold

      Comparable<T> getLowerWarningThreshold()
      Retrieves the lower warning threshold value set by the listener. If the resource usage decreases under this threshold value, the notify(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, the notify(ResourceEvent) will be called. The provided ResourceEvent then 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, the notify(ResourceEvent) method will be called. The provided ResourceEvent then 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, the notify(ResourceEvent) will be called. The provided ResourceEvent then indicates the ERROR state is reached.
      Returns:
      a comparable object or null if no threshold is reached.