Interface ResourceMonitor<T>

Type Parameters:
T - The type for the Resource.
All Known Subinterfaces:
CPUMonitor, DiskStorageMonitor, MemoryMonitor, SocketMonitor, ThreadMonitor

public interface ResourceMonitor<T>
Representation of the state of a resource for a resource context.

ResourceMonitor objects are returned by the ResourceContext.getMonitor(String) method.

The ResourceMonitor object may be used to:

  • Enable/Disable the monitoring of the corresponding resource type for the corresponding resource context
  • View the current usage of the resource by this resource context

A resource monitor can have a sampling period, a monitored period, or both. For example, for CPU monitoring, the resource monitor implementation can get the CPU usage of the running threads once per minute, and calculate the CPU usage per context in percentages based on the last ten such measurements. This could make a 60 000 milliseconds sampling period, and a 600 000 milliseconds monitored period.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Disable and delete this instance of Resource Monitor.
    void
    Disable the monitoring of this resource type for the resource context associated with this monitor instance.
    void
    Enable the monitoring of this resource type for the resource context associated with this monitor instance.
    boolean
    equals(Object resourceMonitor)
    Checks if resourceMonitor is equals to the current instance.
    Returns the resource context that this monitor belongs to
    long
    Returns the time period for which the usage of this resource type is monitored.
    The name of the resource type that this monitor represents
    long
    Returns the sampling period for this resource type.
    Returns an object representing the current usage of this resource type by this resource context.
    int
    Retrieves the hashCode value of this ResourceMonitor.
    boolean
    Returns true if the ResourceMonitor instance has been deleted, that is the delete() method has been called previously.
    boolean
    Checks if the monitoring for this resource type is enabled for this resource context
  • Method Details

    • getContext

      ResourceContext getContext()
      Returns the resource context that this monitor belongs to
      Returns:
      The associated ResourceContext
    • getResourceType

      String getResourceType()
      The name of the resource type that this monitor represents
      Returns:
      The name of the monitored resource type
    • delete

      void delete() throws ResourceMonitorException
      Disable and delete this instance of Resource Monitor. This method MUST update the list of ResourceMonitor instances hold by the Resource Context (getContext().removeMonitor(this)).
      Throws:
      ResourceMonitorException - For example, when the monitor can't be removed from the ResourceContext.
    • isEnabled

      boolean isEnabled()
      Checks if the monitoring for this resource type is enabled for this resource context
      Returns:
      true if monitoring for this resource type is enabled for this context, false otherwise
    • isDeleted

      boolean isDeleted()
      Returns true if the ResourceMonitor instance has been deleted, that is the delete() method has been called previously.
      Returns:
      true if deleted.
    • enable

      void enable() throws ResourceMonitorException
      Enable the monitoring of this resource type for the resource context associated with this monitor instance. This method SHOULD also update the current resource consumption value (to take into account all previous resource allocations and releases occurred during the time the monitor was disabled).
      Throws:
      ResourceMonitorException - if the ResourceMonitor instance can not be enabled (for example, some MemoryMonitor implementations evaluate the memory consumption by tracking memory allocation operation at runtime. This kind of Monitor can not get instantaneous memory value. Such Monitor instances need to be enabled at starting time.). if the ResourceMonitor instance has been previously deleted
    • disable

      void disable() throws ResourceMonitorException
      Disable the monitoring of this resource type for the resource context associated with this monitor instance. The resource usage is not available until it is enabled again.
      Throws:
      ResourceMonitorException - if the ResourceMonitor instance has been previously deleted
    • getUsage

      Returns an object representing the current usage of this resource type by this resource context.
      Returns:
      The current usage of this resource type.
      Throws:
      ResourceMonitorException - if the ResourceMonitor instance is not enabled.
    • getSamplingPeriod

      long getSamplingPeriod()
      Returns the sampling period for this resource type.
      Returns:
      The sampling period in milliseconds, or -1 if a sampling period is not relevant for this resource type.
    • getMonitoredPeriod

      long getMonitoredPeriod()
      Returns the time period for which the usage of this resource type is monitored.
      Returns:
      The monitored period in milliseconds, or -1 if a monitored period is not relevant for this resource type.
    • equals

      boolean equals(Object resourceMonitor)
      Checks if resourceMonitor is equals to the current instance. A ResourceMonitor rm1 is equals to a ResourceMonitor rm2 if rm1.getContext().equals(rm2.getContext()) and r1.getType().equals(rm2.getType()).
      Overrides:
      equals in class Object
      Parameters:
      resourceMonitor -
      Returns:
      true if the current instance is equals to the provided resourceMonitor
    • hashCode

      int hashCode()
      Retrieves the hashCode value of this ResourceMonitor. The hashCode value is based on the hashCode value of the associated ResourceContext and the hashCode value of the type.
      Overrides:
      hashCode in class Object
      Returns:
      hashcode