Package org.opennms.netmgt.config
Class DiscoveryConfigFactory
- java.lang.Object
-
- org.opennms.netmgt.config.DiscoveryConfigFactory
-
- All Implemented Interfaces:
DiscoveryConfigurationFactory
public class DiscoveryConfigFactory extends java.lang.Object implements DiscoveryConfigurationFactory
This class is used to load the configuration for the OpenNMS Discovery service from the discovery-configuration.xml file.- Author:
- Mike Davidson
-
-
Field Summary
Fields Modifier and Type Field Description static char
COMMENT_CHAR
static java.lang.String
COMMENT_STR
static int
DEFAULT_CHUNK_SIZE
static int
DEFAULT_INITIAL_SLEEP_TIME
static double
DEFAULT_PACKETS_PER_SECOND
static int
DEFAULT_RESTART_SLEEP_TIME
static int
DEFAULT_RETRIES
static long
DEFAULT_TIMEOUT
-
Constructor Summary
Constructors Constructor Description DiscoveryConfigFactory()
DiscoveryConfigFactory(DiscoveryConfiguration config)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.util.List<java.lang.String>
addToSpecificsFromURL(java.util.List<IPPollAddress> specifics, java.io.InputStream is, java.lang.String foreignSource, java.lang.String location, long timeout, int retries, java.lang.String url)
addToSpecificsFromURLstatic java.util.List<java.lang.String>
addToSpecificsFromURL(java.util.List<IPPollAddress> specifics, java.lang.String url, java.lang.String foreignSource, java.lang.String location, long timeout, int retries)
The file URL is read and a 'specific IP' is added for each entry in this file.DiscoveryConfiguration
getConfiguration()
Return the discovery configuration object.java.lang.Iterable<IPPollAddress>
getConfiguredAddresses()
getConfiguredAddressesjava.util.Iterator<IPPollAddress>
getExcludingIterator(java.util.Iterator<IPPollAddress> it)
getExcludingInteratorjava.lang.String
getForeignSource(java.net.InetAddress address)
getForeignSourcelong
getInitialSleepTime()
getInitialSleepTimestatic DiscoveryConfigFactory
getInstance()
Deprecated.Inject this value instead of using singleton access.long
getIntraPacketDelay()
getIntraPacketDelayjava.util.List<Detector>
getListOfDetectors(java.net.InetAddress inetAddress, java.lang.String location)
double
getPacketsPerSecond()
getPacketsPerSecondjava.util.List<IPPollRange>
getRanges()
getRangesjava.util.concurrent.locks.Lock
getReadLock()
long
getRestartSleepTime()
getRestartSleepTimejava.util.List<IPPollAddress>
getSpecifics()
getSpecificsjava.util.List<IPPollAddress>
getURLSpecifics()
getURLSpecificsjava.util.concurrent.locks.Lock
getWriteLock()
boolean
isExcluded(java.net.InetAddress address, java.lang.String location)
isExcludedvoid
reload()
Reload the config from the default config file.void
saveConfiguration(DiscoveryConfiguration configuration)
saveConfigurationprotected void
saveXml(java.lang.String xml)
saveXml
-
-
-
Field Detail
-
COMMENT_STR
public static final java.lang.String COMMENT_STR
- See Also:
- Constant Field Values
-
COMMENT_CHAR
public static final char COMMENT_CHAR
- See Also:
- Constant Field Values
-
DEFAULT_PACKETS_PER_SECOND
public static final double DEFAULT_PACKETS_PER_SECOND
- See Also:
- Constant Field Values
-
DEFAULT_INITIAL_SLEEP_TIME
public static final int DEFAULT_INITIAL_SLEEP_TIME
- See Also:
- Constant Field Values
-
DEFAULT_RESTART_SLEEP_TIME
public static final int DEFAULT_RESTART_SLEEP_TIME
- See Also:
- Constant Field Values
-
DEFAULT_RETRIES
public static final int DEFAULT_RETRIES
- See Also:
- Constant Field Values
-
DEFAULT_TIMEOUT
public static final long DEFAULT_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT_CHUNK_SIZE
public static final int DEFAULT_CHUNK_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DiscoveryConfigFactory
public DiscoveryConfigFactory() throws java.io.IOException
- Throws:
java.io.IOException
-
DiscoveryConfigFactory
public DiscoveryConfigFactory(DiscoveryConfiguration config)
-
-
Method Detail
-
getInstance
public static DiscoveryConfigFactory getInstance()
Deprecated.Inject this value instead of using singleton access.
-
getReadLock
public java.util.concurrent.locks.Lock getReadLock()
-
getWriteLock
public java.util.concurrent.locks.Lock getWriteLock()
-
reload
public void reload() throws java.io.IOException
Reload the config from the default config file.- Throws:
java.io.IOException
java.io.IOException
- Thrown if the specified config file cannot be read/loadedjava.io.IOException
- if any.
-
getConfiguration
public DiscoveryConfiguration getConfiguration()
Return the discovery configuration object.- Specified by:
getConfiguration
in interfaceDiscoveryConfigurationFactory
- Returns:
- a
DiscoveryConfiguration
object.
-
saveXml
protected void saveXml(java.lang.String xml) throws java.io.IOException
saveXml
- Parameters:
xml
- aString
object.- Throws:
java.io.IOException
- if any.
-
saveConfiguration
public void saveConfiguration(DiscoveryConfiguration configuration) throws java.io.IOException
saveConfiguration
- Parameters:
configuration
- aDiscoveryConfiguration
object.- Throws:
java.io.IOException
- if any.
-
addToSpecificsFromURL
public static java.util.List<java.lang.String> addToSpecificsFromURL(java.util.List<IPPollAddress> specifics, java.lang.String url, java.lang.String foreignSource, java.lang.String location, long timeout, int retries)
The file URL is read and a 'specific IP' is added for each entry in this file. Each line in the URL file can be one of - <IP><space>#<comments> or <IP> or #<comments> Lines starting with a '#' are ignored and so are characters after a '<space>#' in a line.
- Parameters:
specifics
- the list to add tourl
- the URL filetimeout
- the timeout for all entries in this URLretries
- the retries for all entries in this URL- Returns:
- a list of IP Addresses retrieved from the URL.
-
addToSpecificsFromURL
public static java.util.List<java.lang.String> addToSpecificsFromURL(java.util.List<IPPollAddress> specifics, java.io.InputStream is, java.lang.String foreignSource, java.lang.String location, long timeout, int retries, java.lang.String url) throws java.io.IOException
addToSpecificsFromURL
- Parameters:
specifics
- aList
object.is
- aInputStream
object.timeout
- a long.retries
- a int.url
-- Returns:
- a List of IP Addresses retrieved from URL.
- Throws:
java.io.IOException
- if any.
-
getURLSpecifics
public java.util.List<IPPollAddress> getURLSpecifics()
getURLSpecifics
- Specified by:
getURLSpecifics
in interfaceDiscoveryConfigurationFactory
- Returns:
- a
List
object.
-
getRanges
public java.util.List<IPPollRange> getRanges()
getRanges
- Specified by:
getRanges
in interfaceDiscoveryConfigurationFactory
- Returns:
- a
List
object.
-
getSpecifics
public java.util.List<IPPollAddress> getSpecifics()
getSpecifics
- Specified by:
getSpecifics
in interfaceDiscoveryConfigurationFactory
- Returns:
- a
List
object.
-
isExcluded
public boolean isExcluded(java.net.InetAddress address, java.lang.String location)
isExcluded
- Specified by:
isExcluded
in interfaceDiscoveryConfigurationFactory
- Parameters:
address
- aInetAddress
object.location
-- Returns:
- a boolean.
-
getForeignSource
public java.lang.String getForeignSource(java.net.InetAddress address)
Description copied from interface:DiscoveryConfigurationFactory
getForeignSource
- Specified by:
getForeignSource
in interfaceDiscoveryConfigurationFactory
- Parameters:
address
- InetAddress- Returns:
- a String
-
getListOfDetectors
public java.util.List<Detector> getListOfDetectors(java.net.InetAddress inetAddress, java.lang.String location)
- Specified by:
getListOfDetectors
in interfaceDiscoveryConfigurationFactory
-
getPacketsPerSecond
public double getPacketsPerSecond()
getPacketsPerSecond
- Specified by:
getPacketsPerSecond
in interfaceDiscoveryConfigurationFactory
- Returns:
- a int.
-
getIntraPacketDelay
public long getIntraPacketDelay()
getIntraPacketDelay
- Specified by:
getIntraPacketDelay
in interfaceDiscoveryConfigurationFactory
- Returns:
- a long.
-
getExcludingIterator
public java.util.Iterator<IPPollAddress> getExcludingIterator(java.util.Iterator<IPPollAddress> it)
getExcludingInterator
- Specified by:
getExcludingIterator
in interfaceDiscoveryConfigurationFactory
- Parameters:
it
- aIterator
object.- Returns:
- a
Iterator
object.
-
getConfiguredAddresses
public java.lang.Iterable<IPPollAddress> getConfiguredAddresses()
getConfiguredAddresses
TODO: This function is inefficient. It has O(n^2) complexity based on the product of the include ranges and exclude ranges. This might cause problems if users are using a large number of excluded ranges.- Specified by:
getConfiguredAddresses
in interfaceDiscoveryConfigurationFactory
- Returns:
- a
Iterable
object.
-
getRestartSleepTime
public long getRestartSleepTime()
getRestartSleepTime
- Specified by:
getRestartSleepTime
in interfaceDiscoveryConfigurationFactory
- Returns:
- a long.
-
getInitialSleepTime
public long getInitialSleepTime()
getInitialSleepTime
- Specified by:
getInitialSleepTime
in interfaceDiscoveryConfigurationFactory
- Returns:
- a long.
-
-