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 charCOMMENT_CHARstatic StringCOMMENT_STRstatic intDEFAULT_CHUNK_SIZEstatic intDEFAULT_INITIAL_SLEEP_TIMEstatic doubleDEFAULT_PACKETS_PER_SECONDstatic intDEFAULT_RESTART_SLEEP_TIMEstatic intDEFAULT_RETRIESstatic longDEFAULT_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.DiscoveryConfigurationgetConfiguration()Return the discovery configuration object.Iterable<IPPollAddress>getConfiguredAddresses()getConfiguredAddressesIterator<IPPollAddress>getExcludingIterator(Iterator<IPPollAddress> it)getExcludingInteratorStringgetForeignSource(InetAddress address)getForeignSourcelonggetInitialSleepTime()getInitialSleepTimestatic DiscoveryConfigFactorygetInstance()Deprecated.Inject this value instead of using singleton access.longgetIntraPacketDelay()getIntraPacketDelayList<Detector>getListOfDetectors(InetAddress inetAddress, String location)doublegetPacketsPerSecond()getPacketsPerSecondList<IPPollRange>getRanges()getRangesLockgetReadLock()longgetRestartSleepTime()getRestartSleepTimeList<IPPollAddress>getSpecifics()getSpecificsList<IPPollAddress>getURLSpecifics()getURLSpecificsLockgetWriteLock()booleanisExcluded(InetAddress address, String location)isExcludedvoidreload()Reload the config from the default config file.voidsaveConfiguration(DiscoveryConfiguration configuration)saveConfigurationprotected voidsaveXml(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 IOExceptionReload the config from the default config file.- Throws:
IOExceptionIOException- Thrown if the specified config file cannot be read/loadedIOException- if any.
-
getConfiguration
public DiscoveryConfiguration getConfiguration()
Return the discovery configuration object.- Specified by:
getConfigurationin interfaceDiscoveryConfigurationFactory- Returns:
- a
DiscoveryConfigurationobject.
-
saveXml
protected void saveXml(String xml) throws IOException
saveXml
- Parameters:
xml- aStringobject.- Throws:
IOException- if any.
-
saveConfiguration
public void saveConfiguration(DiscoveryConfiguration configuration) throws IOException
saveConfiguration
- Parameters:
configuration- aDiscoveryConfigurationobject.- 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- aListobject.is- aInputStreamobject.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:
getURLSpecificsin interfaceDiscoveryConfigurationFactory- Returns:
- a
Listobject.
-
getRanges
public List<IPPollRange> getRanges()
getRanges
- Specified by:
getRangesin interfaceDiscoveryConfigurationFactory- Returns:
- a
Listobject.
-
getSpecifics
public List<IPPollAddress> getSpecifics()
getSpecifics
- Specified by:
getSpecificsin interfaceDiscoveryConfigurationFactory- Returns:
- a
Listobject.
-
isExcluded
public boolean isExcluded(InetAddress address, String location)
isExcluded
- Specified by:
isExcludedin interfaceDiscoveryConfigurationFactory- Parameters:
address- aInetAddressobject.location-- Returns:
- a boolean.
-
getForeignSource
public String getForeignSource(InetAddress address)
Description copied from interface:DiscoveryConfigurationFactorygetForeignSource
- Specified by:
getForeignSourcein interfaceDiscoveryConfigurationFactory- Parameters:
address- InetAddress- Returns:
- a String
-
getListOfDetectors
public List<Detector> getListOfDetectors(InetAddress inetAddress, String location)
- Specified by:
getListOfDetectorsin interfaceDiscoveryConfigurationFactory
-
getPacketsPerSecond
public double getPacketsPerSecond()
getPacketsPerSecond
- Specified by:
getPacketsPerSecondin interfaceDiscoveryConfigurationFactory- Returns:
- a int.
-
getIntraPacketDelay
public long getIntraPacketDelay()
getIntraPacketDelay
- Specified by:
getIntraPacketDelayin interfaceDiscoveryConfigurationFactory- Returns:
- a long.
-
getExcludingIterator
public Iterator<IPPollAddress> getExcludingIterator(Iterator<IPPollAddress> it)
getExcludingInterator
- Specified by:
getExcludingIteratorin interfaceDiscoveryConfigurationFactory- Parameters:
it- aIteratorobject.- Returns:
- a
Iteratorobject.
-
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:
getConfiguredAddressesin interfaceDiscoveryConfigurationFactory- Returns:
- a
Iterableobject.
-
getRestartSleepTime
public long getRestartSleepTime()
getRestartSleepTime
- Specified by:
getRestartSleepTimein interfaceDiscoveryConfigurationFactory- Returns:
- a long.
-
getInitialSleepTime
public long getInitialSleepTime()
getInitialSleepTime
- Specified by:
getInitialSleepTimein interfaceDiscoveryConfigurationFactory- Returns:
- a long.
-
-