org.altlinux.jabbix
Class AgentServer

java.lang.Object
  extended by org.altlinux.jabbix.AgentServer
All Implemented Interfaces:
Runnable

public class AgentServer
extends Object
implements Runnable

The agent server for Zabbix monitoring system. Holds the mapping between a set of MetricAgent objects and corresponding set of metric keys. A running agent server is a passive component of the monitoring system and is used to serve metric value queries over a network using Zabbix protocol (i.e. JabbixProtocol).

Each metric key is a textual string value that can be used in bijection with a MetricAgent. However, for a projection of multiple metric keys to a single MetricAgent component be also possible, the assumption is made that the '.' (dot) symbol of a key is a component separator. For a given multicomponent key the longest leftmost mapping is selected if any.

The incoming requests are processed using a thread pool (i.e. ThreadPoolExecutor).

Author:
Paul Wolneykien

Constructor Summary
AgentServer(ThreadPoolExecutor pool)
          Creates a new agent server instance with a given thread pool set to process incoming requests.
 
Method Summary
 MetricAgent getMetricAgent(String key)
          Returns a metric agent registered for a given metric key.
 Map<String,MetricAgent> getMetricAgentMap()
          Returns the metric key -> metric agent map.
 ThreadPoolExecutor getPool()
          Returns the thread pool being used to process incoming requests.
 int getPort()
          Returns a port number of a server socket.
 void run()
          Starts a serving cycle.
 void setMetricAgentMap(Map<String,MetricAgent> map)
          Sets the metric key -> metric agent map.
 void setPool(ThreadPoolExecutor pool)
          Sets the thread pool to be used to process incoming requests.
 void setPort(int port)
          Sets a port number for a server socket.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AgentServer

public AgentServer(ThreadPoolExecutor pool)
Creates a new agent server instance with a given thread pool set to process incoming requests.

Parameters:
pool - a thread pool executor object
Method Detail

getPort

public int getPort()
Returns a port number of a server socket.

Returns:
server socket port number

setPort

public void setPort(int port)
Sets a port number for a server socket. If the server is running modification of this value doesn't change the port number of the opened socket.

Parameters:
port - port number to listen at

run

public void run()
Starts a serving cycle. The server waits for an incoming connection, accepts it if current SecurityManager doesn't prevent it, then enqueues a new JabbixRequest task to the thread pool (see getPool()) and starts a new iteration.

If the thread pool is built upon a blocking queue the next iteration may be blocked until some previous tasks are done.

Specified by:
run in interface Runnable

getMetricAgentMap

public Map<String,MetricAgent> getMetricAgentMap()
Returns the metric key -> metric agent map.

Returns:
a map of (metric key, metric agent) pairs

setMetricAgentMap

public void setMetricAgentMap(Map<String,MetricAgent> map)
Sets the metric key -> metric agent map.

Parameters:
map - the map of (metric key, metric agent) pairs

getMetricAgent

public MetricAgent getMetricAgent(String key)
Returns a metric agent registered for a given metric key. Each metric key is a textual string value that can be used in bijection with a MetricAgent. However, for a projection of multiple metric keys to a single MetricAgent component be also possible, the assumption is made that the '.' (dot) symbol of a key is a component separator. For a given multicomponent key the longest leftmost mapping is selected if any.

Parameters:
key - the name of a metric
Returns:
a metric agent that can be used to query the metric value

setPool

public void setPool(ThreadPoolExecutor pool)
Sets the thread pool to be used to process incoming requests.

Parameters:
pool - a thread pool executor object

getPool

public ThreadPoolExecutor getPool()
Returns the thread pool being used to process incoming requests.

Returns:
a thread pool executor object