org.altlinux.jabbix
Class ResponseQueue

java.lang.Object
  extended by org.altlinux.jabbix.ZabbixClient
      extended by org.altlinux.jabbix.ResponseQueue
All Implemented Interfaces:
Runnable, MetricTable<JabbixActiveMetric<?>>

public class ResponseQueue
extends ZabbixClient
implements MetricTable<JabbixActiveMetric<?>>, Runnable

A Zabbix server client that send metric values to the server when some value expires its refresh period. Holding an updatable queue of JabbixActiveMetric entries to be sent to the server and a link to an other queue to return sent values to.

When an active metric value is added to the queue its expiration counter is reset. Because of that a value is sent to the server when its whole expiration period is passed or when that is the case for some other value.

Author:
Paul Wolneykien

Constructor Summary
ResponseQueue(InetSocketAddress addr, MetricTable<JabbixActiveMetric<?>> returnTable)
          Create a response queue object with the specified parameters.
 
Method Summary
 MetricTable<JabbixActiveMetric<?>> getReturnTable()
          Returns the queue object used to return sent metric objects to.
 boolean isTerminated()
          Indicates whether the wait-and-send loop is terminated.
 void run()
          Starts the queue wait-and-send loop.
 void terminate()
          Terminates this queue wait-and-send loop.
 void updateMetric(JabbixActiveMetric<?> freshMetric)
          Adds the given metric to the queue.
 
Methods inherited from class org.altlinux.jabbix.ZabbixClient
getAddress, getHostName, setAddress, setAddress, setAddress, setAddress, setHostName
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResponseQueue

public ResponseQueue(InetSocketAddress addr,
                     MetricTable<JabbixActiveMetric<?>> returnTable)
Create a response queue object with the specified parameters. A separate return table is used to hold sent values. The two-table (internal queue table and a return table) mechanism is used to prevent metrics the server no longer interested in to resist in the queue for the whole process lifetime.

Parameters:
addr - remote server socket address
returnTable - a table to return sent active metrics to
Method Detail

run

public void run()
Starts the queue wait-and-send loop. While the loop is not terminated by the terminate() method the process waits for any active metric value in the queue to expire and then send the whole queue contents in the "agent data" request. Then the collection of sent metric objects is offered back to a return table.

Specified by:
run in interface Runnable
See Also:
JabbixJSONProtocol.sendMetricList(JabbixWriter, String, Collection), getReturnTable()

updateMetric

public void updateMetric(JabbixActiveMetric<?> freshMetric)
Adds the given metric to the queue. The active status of a metric (see JabbixActiveMetric.setActive(boolean)) is toggled. That action should reset the expiration counter of a metric.

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

getReturnTable

public MetricTable<JabbixActiveMetric<?>> getReturnTable()
Returns the queue object used to return sent metric objects to.

Returns:
the queue to add sent metric objects to

isTerminated

public boolean isTerminated()
Indicates whether the wait-and-send loop is terminated.

Returns:
true if this queue process is terminated
See Also:
run()

terminate

public void terminate()
Terminates this queue wait-and-send loop.

See Also:
run()