org.altlinux.jabbix
Class ActiveMetricTable

java.lang.Object
  extended by org.altlinux.jabbix.ActiveMetricTable
All Implemented Interfaces:
Comparable<Delayed>, Delayed, MetricTable<JabbixActiveMetric<?>>

public class ActiveMetricTable
extends Object
implements MetricTable<JabbixActiveMetric<?>>, Delayed

An updatable queue of JabbixActiveMetric entries with an expiration period for the whole queue. The refreshPeriod property and the getDelay(TimeUnit) method of the Delayed interface can be used to set and track the expiration date of the queue. As the information for the active checks is server-originated it is provident to make periodical updates for the set of active metric objects not to run out of date.

Author:
Paul Wolneykien

Constructor Summary
ActiveMetricTable(long refreshPeriod)
          Creates the table with the specified expiration period.
 
Method Summary
 int compareTo(ActiveMetricTable a)
          Indicates if the current table is less than, equal to or greater than the given one.
 int compareTo(Delayed o)
          Indicates if the current table is less than, equal to or greater than the given Delayed object.
 long getDelay(TimeUnit unit)
          Returns the remaining time for the queue data assumed to be fresh.
 Date getNextRefresh()
          Returns the queue expiration date and time.
 DelayQueue<JabbixActiveMetric<?>> getQueue()
          Returns the queue with the active metric objects placed in accordance with their expiration dates.
 long getRefreshPeriod()
          Returns the refresh period of the queue.
 boolean isExpired()
          Indicates whether the queue data is expired.
 void setRefreshPeriod(long refreshPeriod)
          Sets the refresh period for the whole queue to the specified value.
 void updateMetric(JabbixActiveMetric<?> freshMetric)
          Adds the given metric to the queue.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActiveMetricTable

public ActiveMetricTable(long refreshPeriod)
Creates the table with the specified expiration period.

Parameters:
refreshPeriod - the queue expiration period
Method Detail

updateMetric

public void updateMetric(JabbixActiveMetric<?> freshMetric)
Adds the given metric to the queue.

Specified by:
updateMetric in interface MetricTable<JabbixActiveMetric<?>>
Parameters:
freshMetric - a metric to add
See Also:
JabbixMetric.equals(Object)

setRefreshPeriod

public void setRefreshPeriod(long refreshPeriod)
Sets the refresh period for the whole queue to the specified value. Each time the refresh period value is updated the nextRefresh value is set in accordance with the old value or the current system time.

If the given value is 0 then the nextRefresh value is set to null and no periodical refreshes of the table are provided.

Parameters:
refreshPeriod - the refresh period in milliseconds

getRefreshPeriod

public long getRefreshPeriod()
Returns the refresh period of the queue.

Returns:
the refresh period of the queue in milliseconds

getNextRefresh

public Date getNextRefresh()
Returns the queue expiration date and time.

Returns:
the queue expiration date and time

isExpired

public boolean isExpired()
Indicates whether the queue data is expired.

Returns:
true if the queue is expired, false otherwise

getDelay

public long getDelay(TimeUnit unit)
Returns the remaining time for the queue data assumed to be fresh.

Specified by:
getDelay in interface Delayed
Returns:
the remaining time for the queue to expire in the given time units

compareTo

public int compareTo(Delayed o)
Indicates if the current table is less than, equal to or greater than the given Delayed object. Tables are compared using the compareTo(ActiveMetricTable) method. If the given object is not a table then the table is supposed to be less (sooner) than the given object.

Specified by:
compareTo in interface Comparable<Delayed>
Parameters:
o - the object to compare to
Returns:
below zero number if this table expires sooner than the given object, zero if both objects are expired in the same time and above zero number if this table is expired later than the given object

compareTo

public int compareTo(ActiveMetricTable a)
Indicates if the current table is less than, equal to or greater than the given one. One table is less that the other if its refresh is expected sooner. Return value is obtained by the comparison of the nextCheck properties of the tables.

Parameters:
a - another table to compare with
Returns:
below zero number if this table is expired sooner than the given one, zero if both tables are expired in the same time and above zero number if this table is expired later than the given one

getQueue

public DelayQueue<JabbixActiveMetric<?>> getQueue()
Returns the queue with the active metric objects placed in accordance with their expiration dates.

Returns:
the queue with the active metric objects