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.

    Version:
    1.0
    Author:
    $Id: 1c29e2896b94e38e03e8daf5ada29b7441caea96 $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String LOWER_ERROR_THRESHOLD
      Optional property defining the value of the lower error threshold.
      static java.lang.String LOWER_WARNING_THRESHOLD
      Optional property defining the value of the lower warning threshold.
      static java.lang.String RESOURCE_CONTEXT
      Mandatory property specifying the Resource Context associated with the listener.
      static java.lang.String RESOURCE_TYPE
      Mandatory property defining the type of Resource (i.e the ResourceMonitor) associated to this Listener.
      static java.lang.String UPPER_ERROR_THRESHOLD
      Optional property defining the value of the upper error threshold.
      static java.lang.String UPPER_WARNING_THRESHOLD
      Optional property defining the value of the upper warning threshold.
    • Field Detail

      • RESOURCE_CONTEXT

        static final java.lang.String RESOURCE_CONTEXT
        Mandatory property specifying the Resource Context associated with the listener.
        See Also:
        Constant Field Values
      • RESOURCE_TYPE

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

        static final java.lang.String UPPER_WARNING_THRESHOLD
        Optional property defining the value of the upper warning threshold.
        See Also:
        Constant Field Values
      • UPPER_ERROR_THRESHOLD

        static final java.lang.String UPPER_ERROR_THRESHOLD
        Optional property defining the value of the upper error threshold.
        See Also:
        Constant Field Values
      • LOWER_WARNING_THRESHOLD

        static final java.lang.String LOWER_WARNING_THRESHOLD
        Optional property defining the value of the lower warning threshold.
        See Also:
        Constant Field Values
      • LOWER_ERROR_THRESHOLD

        static final java.lang.String LOWER_ERROR_THRESHOLD
        Optional property defining the value of the lower error threshold.
        See Also:
        Constant Field Values
    • Method Detail

      • notify

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

        java.lang.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

        java.lang.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

        java.lang.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

        java.lang.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.