Module org.snmp4j

Class DefaultPDUFactory

  • All Implemented Interfaces:
    PDUFactory

    public class DefaultPDUFactory
    extends java.lang.Object
    implements PDUFactory
    The DefaultPDUFactory is a default implementation of the PDUFactory interface. It creates PDUs depending on the target's message processing model. That is, a PDUv1 instance is created for a SNMPv1 target whereas a ScopedPDU is created for a SNMPv3 target. In all other cases a PDU instance is created.
    Since:
    1.0.4
    Version:
    2.5.1
    Author:
    Frank Fock
    • Field Detail

      • GETBULK_DEFAULT_MAX_REPETITIONS

        public static final int GETBULK_DEFAULT_MAX_REPETITIONS
        See Also:
        Constant Field Values
      • GETBULK_DEFAULT_NON_REPEATERS

        public static final int GETBULK_DEFAULT_NON_REPEATERS
        See Also:
        Constant Field Values
    • Constructor Detail

      • DefaultPDUFactory

        public DefaultPDUFactory()
        Creates a PDU factory for the PDU.GET PDU type.
      • DefaultPDUFactory

        public DefaultPDUFactory​(int pduType)
        Creates a PDU factory for the specified PDU type. Context engine ID and name will be set to empty OctetString instances.
        Parameters:
        pduType - a PDU type as specified by PDU.
      • DefaultPDUFactory

        public DefaultPDUFactory​(int pduType,
                                 OctetString contextEngineID,
                                 OctetString contextName)
        Creates a PDUFactory with type and context information.
        Parameters:
        pduType - a PDU type as specified by PDU.
        contextEngineID - a context engine ID to be used when creating ScopedPDUs.
        contextName - a context name to be used when creating ScopedPDUs.
        Since:
        2.2
    • Method Detail

      • setPduType

        public void setPduType​(int pduType)
      • getPduType

        public int getPduType()
      • createPDU

        public PDU createPDU​(Target<?> target)
        Create a PDU instance for the supplied target.
        Specified by:
        createPDU in interface PDUFactory
        Parameters:
        target - the Target where the PDU to be created will be sent.
        Returns:
        PDU a PDU instance that is compatible with the supplied target.
      • applyContextInfoToScopedPDU

        protected void applyContextInfoToScopedPDU​(PDU pdu)
        Sets context engine ID and context name members on the given PDU if that PDU is a ScopedPDU.
        Parameters:
        pdu - a PDU instance which is modified if it is a ScopedPDU instance.
        Since:
        2.5.0
      • createPDU

        public static PDU createPDU​(Target<?> target,
                                    int pduType)
        Create a PDU instance for the supplied target. For GETBULK PDUs, the default max repetitions and non repeaters are used. See GETBULK_DEFAULT_MAX_REPETITIONS and GETBULK_DEFAULT_NON_REPEATERS.
        Parameters:
        target - the Target where the PDU to be created will be sent.
        pduType - a PDU type as specified by PDU.
        Returns:
        PDU a PDU instance that is compatible with the supplied target.
      • createPDU

        public static PDU createPDU​(Target<?> target,
                                    int pduType,
                                    int maxRepetitions,
                                    int nonRepeaters)
        Create a PDU instance for the supplied target.
        Parameters:
        target - the Target where the PDU to be created will be sent.
        pduType - a PDU type as specified by PDU.
        maxRepetitions - the maximum number of repetitions for GETBULK PDUs created by this factory.
        nonRepeaters - the number of non-repeater variable bindings (processed like GETNEXT) for GETBULK PDUs created by this factory.
        Returns:
        PDU a PDU instance that is compatible with the supplied target.
        Since:
        2.2
      • createPDU

        public static PDU createPDU​(int targetVersion)
        Creates a PDU instance for the specified SNMP version.
        Parameters:
        targetVersion - a SNMP version as defined by SnmpConstants.
        Returns:
        a PDU instance that is compatible with the supplied target SNMP version.
        Since:
        1.7.3
      • createPDU

        public PDU createPDU​(MessageProcessingModel messageProcessingModel)
        Creates a PDU instance for the specified MessageProcessingModel.
        Specified by:
        createPDU in interface PDUFactory
        Parameters:
        messageProcessingModel - a message processing model instance.
        Returns:
        a PDU that is compatible with the specified message processing model.
        Since:
        2.2
      • createPDU

        public static PDU createPDU​(MessageProcessingModel messageProcessingModel,
                                    int pduType)
        Creates a PDU instance for the specified MessageProcessingModel and PDU type.
        Parameters:
        messageProcessingModel - a message processing model instance.
        pduType - the type for the new PDU.
        Returns:
        a PDU that is compatible with the specified message processing model.
        Since:
        2.2
      • getMaxRepetitions

        public int getMaxRepetitions()
        Gets the maximum number of repetitions for the repetitions variable bindings for PDU.GETBULK PDUs. Default is GETBULK_DEFAULT_MAX_REPETITIONS
        Returns:
        the maximum number of repetitions for GETBULK PDUs created by this factory.
        Since:
        2.2
      • setMaxRepetitions

        public void setMaxRepetitions​(int maxRepetitions)
        Sets the max repetitions parameter value for GETBULK PDUs created by this factory.
        Parameters:
        maxRepetitions - the maximum number of repetitions for GETBULK PDUs created by this factory.
        Since:
        2.2
      • getNonRepeaters

        public int getNonRepeaters()
        Gets the number of non repeater variable bindings for PDU.GETBULK PDUs. Default is GETBULK_DEFAULT_NON_REPEATERS.
        Returns:
        the number of non-repeater variable bindings (processed like GETNEXT) for GETBULK PDUs created by this factory.
        Since:
        2.2
      • setNonRepeaters

        public void setNonRepeaters​(int nonRepeaters)
        Sets the non repeaters parameter value for GETBULK PDUs created by this factory.
        Parameters:
        nonRepeaters - the number of non-repeater variable bindings (processed like GETNEXT) for GETBULK PDUs created by this factory.
        Since:
        2.2
      • getContextEngineID

        public OctetString getContextEngineID()
        Gets the context engine ID for ScopedPDU instances created by this factory.
        Returns:
        the context engine ID or null if context engine ID is the same as authoritative engine ID.
        Since:
        2.2
      • setContextEngineID

        public void setContextEngineID​(OctetString contextEngineID)
        Sets the context engine ID for ScopedPDU instances created by this factory.
        Parameters:
        contextEngineID - the context engine ID or null if context engine ID is the same as authoritative engine ID.
        Since:
        2.2
      • getContextName

        public OctetString getContextName()
        Gets the context name for ScopedPDU instances created by this factory.
        Returns:
        the context name or null for the default context.
        Since:
        2.2
      • setContextName

        public void setContextName​(OctetString contextName)
        Sets the context name for ScopedPDU instances created by this factory.
        Parameters:
        contextName - the context name or null for the default context.
        Since:
        2.2