Package org.opennms.netmgt.config
Class DiscoveryConfigFactory
- java.lang.Object
-
- org.opennms.netmgt.config.DiscoveryConfigFactory
-
- All Implemented Interfaces:
DiscoveryConfigurationFactory
public class DiscoveryConfigFactory extends 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 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 List<String>
addToSpecificsFromURL(List<IPPollAddress> specifics, InputStream is, String foreignSource, String location, long timeout, int retries, String url)
addToSpecificsFromURLstatic List<String>
addToSpecificsFromURL(List<IPPollAddress> specifics, String url, String foreignSource, 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.Iterable<IPPollAddress>
getConfiguredAddresses()
getConfiguredAddressesIterator<IPPollAddress>
getExcludingIterator(Iterator<IPPollAddress> it)
getExcludingInteratorString
getForeignSource(InetAddress address)
getForeignSourcelong
getInitialSleepTime()
getInitialSleepTimestatic DiscoveryConfigFactory
getInstance()
Deprecated.Inject this value instead of using singleton access.long
getIntraPacketDelay()
getIntraPacketDelayList<Detector>
getListOfDetectors(InetAddress inetAddress, String location)
double
getPacketsPerSecond()
getPacketsPerSecondList<IPPollRange>
getRanges()
getRangesLock
getReadLock()
long
getRestartSleepTime()
getRestartSleepTimeList<IPPollAddress>
getSpecifics()
getSpecificsList<IPPollAddress>
getURLSpecifics()
getURLSpecificsLock
getWriteLock()
boolean
isExcluded(InetAddress address, String location)
isExcludedvoid
reload()
Reload the config from the default config file.void
saveConfiguration(DiscoveryConfiguration configuration)
saveConfigurationprotected void
saveXml(String xml)
saveXml
-
-
-
Field Detail
-
COMMENT_STR
public static final 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 IOException
- Throws:
IOException
-
DiscoveryConfigFactory
public DiscoveryConfigFactory(DiscoveryConfiguration config)
-
-
Method Detail
-
getInstance
public static DiscoveryConfigFactory getInstance()
Deprecated.Inject this value instead of using singleton access.
-
getReadLock
public Lock getReadLock()
-
getWriteLock
public Lock getWriteLock()
-
reload
public void reload() throws IOException
Reload the config from the default config file.- Throws:
IOException
IOException
- Thrown if the specified config file cannot be read/loadedIOException
- if any.
-
getConfiguration
public DiscoveryConfiguration getConfiguration()
Return the discovery configuration object.- Specified by:
getConfiguration
in interfaceDiscoveryConfigurationFactory
- Returns:
- a
DiscoveryConfiguration
object.
-
saveXml
protected void saveXml(String xml) throws IOException
saveXml
- Parameters:
xml
- aString
object.- Throws:
IOException
- if any.
-
saveConfiguration
public void saveConfiguration(DiscoveryConfiguration configuration) throws IOException
saveConfiguration
- Parameters:
configuration
- aDiscoveryConfiguration
object.- Throws:
IOException
- if any.
-
addToSpecificsFromURL
public static List<String> addToSpecificsFromURL(List<IPPollAddress> specifics, String url, String foreignSource, 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 List<String> addToSpecificsFromURL(List<IPPollAddress> specifics, InputStream is, String foreignSource, String location, long timeout, int retries, String url) throws 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:
IOException
- if any.
-
getURLSpecifics
public List<IPPollAddress> getURLSpecifics()
getURLSpecifics
- Specified by:
getURLSpecifics
in interfaceDiscoveryConfigurationFactory
- Returns:
- a
List
object.
-
getRanges
public List<IPPollRange> getRanges()
getRanges
- Specified by:
getRanges
in interfaceDiscoveryConfigurationFactory
- Returns:
- a
List
object.
-
getSpecifics
public List<IPPollAddress> getSpecifics()
getSpecifics
- Specified by:
getSpecifics
in interfaceDiscoveryConfigurationFactory
- Returns:
- a
List
object.
-
isExcluded
public boolean isExcluded(InetAddress address, String location)
isExcluded
- Specified by:
isExcluded
in interfaceDiscoveryConfigurationFactory
- Parameters:
address
- aInetAddress
object.location
-- Returns:
- a boolean.
-
getForeignSource
public String getForeignSource(InetAddress address)
Description copied from interface:DiscoveryConfigurationFactory
getForeignSource
- Specified by:
getForeignSource
in interfaceDiscoveryConfigurationFactory
- Parameters:
address
- InetAddress- Returns:
- a String
-
getListOfDetectors
public List<Detector> getListOfDetectors(InetAddress inetAddress, 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 Iterator<IPPollAddress> getExcludingIterator(Iterator<IPPollAddress> it)
getExcludingInterator
- Specified by:
getExcludingIterator
in interfaceDiscoveryConfigurationFactory
- Parameters:
it
- aIterator
object.- Returns:
- a
Iterator
object.
-
getConfiguredAddresses
public 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.
-
-