org.opennms.netmgt.config
Class CollectdConfigFactory

java.lang.Object
  extended by org.opennms.netmgt.config.CollectdConfigFactory

public class CollectdConfigFactory
extends Object

This is the singleton class used to load the configuration for the OpenNMS Collection Daemon from the collectd-configuration xml file. A mapping of the configured URLs to the iplist they contain is built at init() time so as to avoid numerous file reads. Note: Users of this class should make sure the init() is called before calling any other method to ensure the config is loaded before accessing other convenience methods.

Version:
$Id: $
Author:
ranger

Constructor Summary
CollectdConfigFactory(InputStream stream, String localServer, boolean verifyServer)
          Constructor for CollectdConfigFactory.
CollectdConfigFactory(Reader rdr, String localServer, boolean verifyServer)
          Public constructor
 
Method Summary
 boolean domainExists(String name)
          Returns true if collection domain exists
 CollectdConfig getCollectdConfig()
          getCollectdConfig
static CollectdConfigFactory getInstance()
          Return the singleton instance of this factory.
 CollectdPackage getPackage(String name)
          getPackage
static void init()
          Load the config from the default config file and create the singleton instance of this factory.
 boolean isServiceCollectionEnabled(String ipAddr, String svcName)
          Returns true if the specified interface is included by at least one package which has the specified service and that service is enabled (set to "on").
 boolean packageExists(String name)
          Returns true if collection package exists
 void rebuildPackageIpListMap()
          This method is used to rebuild the package agaist iplist mapping when needed.
static void reload()
          Reload the config from the default config file
 void saveCurrent()
          Saves the current in-memory configuration to disk and reloads
static void setInstance(CollectdConfigFactory instance)
          setInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectdConfigFactory

public CollectdConfigFactory(Reader rdr,
                             String localServer,
                             boolean verifyServer)
                      throws IOException,
                             org.exolab.castor.xml.MarshalException,
                             org.exolab.castor.xml.ValidationException
Public constructor

Parameters:
rdr - a Reader object.
localServer - a String object.
verifyServer - a boolean.
Throws:
IOException - Thrown if the specified config file cannot be read
org.exolab.castor.xml.MarshalException - Thrown if the file does not conform to the schema.
org.exolab.castor.xml.ValidationException - Thrown if the contents do not match the required schema.
IOException - if any.
org.exolab.castor.xml.MarshalException - if any.
org.exolab.castor.xml.ValidationException - if any.

CollectdConfigFactory

public CollectdConfigFactory(InputStream stream,
                             String localServer,
                             boolean verifyServer)
                      throws org.exolab.castor.xml.MarshalException,
                             org.exolab.castor.xml.ValidationException

Constructor for CollectdConfigFactory.

Parameters:
stream - a InputStream object.
localServer - a String object.
verifyServer - a boolean.
Throws:
org.exolab.castor.xml.MarshalException - if any.
org.exolab.castor.xml.ValidationException - if any.
Method Detail

rebuildPackageIpListMap

public void rebuildPackageIpListMap()
This method is used to rebuild the package agaist iplist mapping when needed. When a node gained service event occurs, collectd has to determine which package the ip/service combination is in, but if the interface is a newly added one, the package iplist should be rebuilt so that collectd could know which package this ip/service pair is in.


init

public static void init()
                 throws IOException,
                        org.exolab.castor.xml.MarshalException,
                        org.exolab.castor.xml.ValidationException
Load the config from the default config file and create the singleton instance of this factory.

Throws:
IOException - Thrown if the specified config file cannot be read
org.exolab.castor.xml.MarshalException - Thrown if the file does not conform to the schema.
org.exolab.castor.xml.ValidationException - Thrown if the contents do not match the required schema.
IOException - if any.
org.exolab.castor.xml.MarshalException - if any.
org.exolab.castor.xml.ValidationException - if any.

reload

public static void reload()
                   throws IOException,
                          org.exolab.castor.xml.MarshalException,
                          org.exolab.castor.xml.ValidationException
Reload the config from the default config file

Throws:
IOException - Thrown if the specified config file cannot be read/loaded
org.exolab.castor.xml.MarshalException - Thrown if the file does not conform to the schema.
org.exolab.castor.xml.ValidationException - Thrown if the contents do not match the required schema.
IOException - if any.
org.exolab.castor.xml.MarshalException - if any.
org.exolab.castor.xml.ValidationException - if any.

saveCurrent

public void saveCurrent()
                 throws org.exolab.castor.xml.MarshalException,
                        IOException,
                        org.exolab.castor.xml.ValidationException
Saves the current in-memory configuration to disk and reloads

Throws:
org.exolab.castor.xml.MarshalException - if any.
IOException - if any.
org.exolab.castor.xml.ValidationException - if any.

getInstance

public static CollectdConfigFactory getInstance()
Return the singleton instance of this factory.

Returns:
The current factory instance.
Throws:
IllegalStateException - Thrown if the factory has not yet been initialized.

setInstance

public static void setInstance(CollectdConfigFactory instance)

setInstance

Parameters:
instance - a CollectdConfigFactory object.

getCollectdConfig

public CollectdConfig getCollectdConfig()

getCollectdConfig

Returns:
a CollectdConfig object.

getPackage

public CollectdPackage getPackage(String name)

getPackage

Parameters:
name - a String object.
Returns:
a CollectdPackage object.

packageExists

public boolean packageExists(String name)
Returns true if collection package exists

Parameters:
name - The package name to check
Returns:
True if the package exists

domainExists

public boolean domainExists(String name)
Returns true if collection domain exists

Parameters:
name - The domain name to check
Returns:
True if the domain exists

isServiceCollectionEnabled

public boolean isServiceCollectionEnabled(String ipAddr,
                                          String svcName)
Returns true if the specified interface is included by at least one package which has the specified service and that service is enabled (set to "on").

Parameters:
ipAddr - IP address of the interface to lookup
svcName - The service name to lookup
Returns:
true if Collectd config contains a package which includes the specified interface and has the specified service enabled.


Copyright © 2011. All Rights Reserved.