OpenNMS API 1.2.9

## org.opennms.netmgt.config
Class SnmpPeerFactory

    java.lang.Object
      org.opennms.netmgt.config.SnmpPeerFactory

public final class SnmpPeerFactory
extends java.lang.Object

This class is the main respository for SNMP configuration information used by the capabilities daemon. When this class is loaded it reads the snmp configuration into memory, and uses the configuration to find the `SnmpPeer`objects for specific addresses. If an address cannot be located in the configuration then a default peer instance is returned to the caller. 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.

Author:
  Weave , Gerald Turner , OpenNMS

Nested Class Summary
`class` `SnmpPeerFactory.SnmpEventInfo`

Field Summary
`private static SnmpConfig` `m_config` The config class loaded from the config file
`private static boolean` `m_loaded` This member is set to true if the configuration file has been loaded.
`private static SnmpPeerFactory` `m_singleton` The singleton instance of this factory

Constructor Summary
`private` `SnmpPeerFactory(java.lang.String configFile)` Private constructor

Method Summary
`private SnmpPeer` `create(java.net.InetAddress addr, Definition def)` this method uses the passed address and definition to construct an appropriate SNMP peer object for use by an SnmpSession.
`private SnmpPeer` `create(java.net.InetAddress addr, Definition def, int supportedSnmpVersion)` this method uses the passed address and definition to construct an appropriate SNMP peer object for use by an SnmpSession.
`SnmpPeerFactory.SnmpEventInfo` `createSnmpEventInfo()`
`void` `define(java.net.InetAddress ip, SnmpPeerFactory.SnmpEventInfo info)` Puts a specific IP address with associated read-community string into the currently loaded snmp-config.xml.
`static SnmpPeerFactory` `getInstance()` Return the singleton instance of this factory.
`SnmpPeer` `getPeer(java.net.InetAddress host)` This method is used by the Capabilities poller to lookup the SNMP peer information associated with the passed host.
`SnmpPeer` `getPeer(java.net.InetAddress host, int supportedSnmpVersion)` This method is used by the Capabilities poller to lookup the SNMP peer information associated with the passed host.
`static void` `init()` Load the config from the default config file and create the singleton instance of this factory.
`private static void` `optimize()` Combine specific and range elements so that SnmpPeerFactory has to spend less time iterating all these elements.
`static void` `reload()` Reload the config from the default config file
`static void` `saveCurrent()` Saves the current settings to disk
`private static long` `toLong(java.net.InetAddress addr)` Converts the internet address to a long value so that it can be compared using simple opertions.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### m_singleton

    private static SnmpPeerFactory m_singleton

  The singleton instance of this factory

### m_config

    private static SnmpConfig m_config

  The config class loaded from the config file

### m_loaded

    private static boolean m_loaded

  This member is set to true if the configuration file has been loaded.

Constructor Detail

### SnmpPeerFactory

    private SnmpPeerFactory(java.lang.String configFile)
                     throws java.io.IOException,
                            org.exolab.castor.xml.MarshalException,
                            org.exolab.castor.xml.ValidationException

  Private constructor

Throws:
  `java.io.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.

Method Detail

### init

    public static void init()
                     throws java.io.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:
    `java.io.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.

### reload

    public static void reload()
                       throws java.io.IOException,
                              org.exolab.castor.xml.MarshalException,
                              org.exolab.castor.xml.ValidationException

  Reload the config from the default config file

  Throws:
    `java.io.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.

### saveCurrent

    public static void saveCurrent()
                            throws java.lang.Exception

  Saves the current settings to disk

  Throws:
    `java.lang.Exception`

### optimize

    private static void optimize()
                          throws java.net.UnknownHostException

  Combine specific and range elements so that SnmpPeerFactory has to spend less time iterating all these elements.

  Throws:
    `java.net.UnknownHostException`

### getInstance

    public static SnmpPeerFactory getInstance()

  Return the singleton instance of this factory.

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

### toLong

    private static long toLong(java.net.InetAddress addr)

  Converts the internet address to a long value so that it can be compared using simple opertions. The address is converted in network byte order (big endin) and allows for comparisions like <, >, <=, >=, ==, and !=.

  Parameters:
    `addr` - The address to convert to a long
  Returns:
    The address as a long value.

### define

    public void define(java.net.InetAddress ip,
                       SnmpPeerFactory.SnmpEventInfo info)
                throws java.net.UnknownHostException

  Puts a specific IP address with associated read-community string into the currently loaded snmp-config.xml.

  Throws:
    `java.net.UnknownHostException`

### create

    private SnmpPeer create(java.net.InetAddress addr,
                            Definition def)

  this method uses the passed address and definition to construct an appropriate SNMP peer object for use by an SnmpSession.

  Parameters:
    `addr` - The address to construct the snmp peer instance.
    `def` - The definition containing the appropriate information.
  Returns:
    The SnmpPeer matching for the passed address.

### create

    private SnmpPeer create(java.net.InetAddress addr,
                            Definition def,
                            int supportedSnmpVersion)

  this method uses the passed address and definition to construct an appropriate SNMP peer object for use by an SnmpSession.

  Parameters:
    `addr` - The address to construct the snmp peer instance.
    `def` - The definition containing the appropriate information.
    `supportedSnmpVersion` - SNMP version to associate with the peer object if SNMP version has not been explicitly configured.
  Returns:
    The SnmpPeer matching for the passed address.

### getPeer

    public SnmpPeer getPeer(java.net.InetAddress host)

  This method is used by the Capabilities poller to lookup the SNMP peer information associated with the passed host. If there is no specific information available then a default SnmpPeer instance is returned to the caller.

  Parameters:
    `host` - The host for locating the SnmpPeer information.
  Returns:
    The configured SnmpPeer information.

### getPeer

    public SnmpPeer getPeer(java.net.InetAddress host,
                            int supportedSnmpVersion)

  This method is used by the Capabilities poller to lookup the SNMP peer information associated with the passed host. If there is no specific information available then a default SnmpPeer instance is returned to the caller.

  Parameters:
    `host` - The host for locating the SnmpPeer information.
    `supportedSnmpVersion` - SNMP version to associate with the peer object if SNMP version has not been explicitly configured.
  Returns:
    The configured SnmpPeer information.

### createSnmpEventInfo

    public SnmpPeerFactory.SnmpEventInfo createSnmpEventInfo()

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.