Class TrapdConfigFactory

  • All Implemented Interfaces:
    TrapdConfig

    public final class TrapdConfigFactory
    extends java.lang.Object
    implements TrapdConfig
    This is the singleton class used to load the configuration for the OpenNMS Trapd from the trapd-configuration.xml. 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:
    Sowmya Nataraj , Tarus Balog , OpenNMS
    • Constructor Detail

      • TrapdConfigFactory

        public TrapdConfigFactory​(java.io.InputStream stream)
                           throws java.io.IOException

        Constructor for TrapdConfigFactory.

        Parameters:
        stream - a InputStream object.
        Throws:
        java.io.IOException
    • Method Detail

      • init

        public static void init()
                         throws java.io.IOException
        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
        java.io.IOException - if any.
      • reload

        public static void reload()
                           throws java.io.IOException
        Reload the config from the default config file
        Throws:
        java.io.IOException - Thrown if the specified config file cannot be read/loaded
        java.io.IOException - if any.
      • getInstance

        public static TrapdConfig 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.
      • setInstance

        public static void setInstance​(TrapdConfig config)

        setInstance

        Parameters:
        config - a TrapdConfig object.
      • getSnmpTrapPort

        public int getSnmpTrapPort()
        Return the port on which SNMP traps should be received.
        Specified by:
        getSnmpTrapPort in interface TrapdConfig
        Returns:
        the port on which SNMP traps should be received
      • getNewSuspectOnTrap

        public boolean getNewSuspectOnTrap()
        Return whether or not a newSuspect event should be sent when a trap is received from an unknown IP address.
        Specified by:
        getNewSuspectOnTrap in interface TrapdConfig
        Returns:
        whether to generate newSuspect events on traps.
      • getNumThreads

        public int getNumThreads()
        Description copied from interface: TrapdConfig
        Number of threads used for consuming/dispatching messages.
        Specified by:
        getNumThreads in interface TrapdConfig
        Returns:
        number of threads
      • getQueueSize

        public int getQueueSize()
        Description copied from interface: TrapdConfig
        Maximum number of messages to keep in memory while waiting to be dispatched.
        Specified by:
        getQueueSize in interface TrapdConfig
        Returns:
        queue size
      • getBatchSize

        public int getBatchSize()
        Description copied from interface: TrapdConfig
        Messages are aggregated in batches before being dispatched. When the batch reaches this size, it will be dispatched.
        Specified by:
        getBatchSize in interface TrapdConfig
        Returns:
        batch size
      • getBatchIntervalMs

        public int getBatchIntervalMs()
        Description copied from interface: TrapdConfig
        Messages are aggregated in batches before being dispatched. When the batch has been created for longer than this interval it will be dispatched, regardless of the size.
        Specified by:
        getBatchIntervalMs in interface TrapdConfig
        Returns:
        interval in ms