- java.lang.Object
-
- org.snmp4j.util.DefaultPDUFactory
-
- All Implemented Interfaces:
PDUFactory
public class DefaultPDUFactory extends java.lang.Object implements PDUFactory
TheDefaultPDUFactory
is a default implementation of thePDUFactory
interface. It creates PDUs depending on the target's message processing model. That is, aPDUv1
instance is created for a SNMPv1 target whereas aScopedPDU
is created for a SNMPv3 target. In all other cases aPDU
instance is created.- Since:
- 1.0.4
- Version:
- 2.5.1
-
-
Field Summary
Fields Modifier and Type Field Description private OctetString
contextEngineID
private OctetString
contextName
static int
GETBULK_DEFAULT_MAX_REPETITIONS
static int
GETBULK_DEFAULT_NON_REPEATERS
private int
maxRepetitions
private int
nonRepeaters
private int
pduType
-
Constructor Summary
Constructors Constructor Description DefaultPDUFactory()
Creates a PDU factory for thePDU.GET
PDU type.DefaultPDUFactory(int pduType)
Creates a PDU factory for the specified PDU type.DefaultPDUFactory(int pduType, OctetString contextEngineID, OctetString contextName)
Creates aPDUFactory
with type and context information.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
applyContextInfoToScopedPDU(PDU pdu)
Sets context engine ID and context name members on the given PDU if that PDU is aScopedPDU
.static PDU
createPDU(int targetVersion)
Creates aPDU
instance for the specified SNMP version.PDU
createPDU(MessageProcessingModel messageProcessingModel)
Creates aPDU
instance for the specifiedMessageProcessingModel
.static PDU
createPDU(MessageProcessingModel messageProcessingModel, int pduType)
Creates aPDU
instance for the specifiedMessageProcessingModel
and PDU type.PDU
createPDU(Target<?> target)
Create aPDU
instance for the supplied target.static PDU
createPDU(Target<?> target, int pduType)
Create aPDU
instance for the supplied target.static PDU
createPDU(Target<?> target, int pduType, int maxRepetitions, int nonRepeaters)
Create aPDU
instance for the supplied target.private static PDU
createPduByMP(MessageProcessingModel messageProcessingModel)
OctetString
getContextEngineID()
Gets the context engine ID forScopedPDU
instances created by this factory.OctetString
getContextName()
Gets the context name forScopedPDU
instances created by this factory.int
getMaxRepetitions()
Gets the maximum number of repetitions for the repetitions variable bindings forPDU.GETBULK
PDUs.int
getNonRepeaters()
Gets the number of non repeater variable bindings forPDU.GETBULK
PDUs.int
getPduType()
void
setContextEngineID(OctetString contextEngineID)
Sets the context engine ID forScopedPDU
instances created by this factory.void
setContextName(OctetString contextName)
Sets the context name forScopedPDU
instances created by this factory.void
setMaxRepetitions(int maxRepetitions)
Sets the max repetitions parameter value for GETBULK PDUs created by this factory.void
setNonRepeaters(int nonRepeaters)
Sets the non repeaters parameter value for GETBULK PDUs created by this factory.void
setPduType(int pduType)
-
-
-
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
-
pduType
private int pduType
-
maxRepetitions
private int maxRepetitions
-
nonRepeaters
private int nonRepeaters
-
contextEngineID
private OctetString contextEngineID
-
contextName
private OctetString contextName
-
-
Constructor Detail
-
DefaultPDUFactory
public DefaultPDUFactory()
Creates a PDU factory for thePDU.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 emptyOctetString
instances.- Parameters:
pduType
- a PDU type as specified byPDU
.
-
DefaultPDUFactory
public DefaultPDUFactory(int pduType, OctetString contextEngineID, OctetString contextName)
Creates aPDUFactory
with type and context information.
-
-
Method Detail
-
setPduType
public void setPduType(int pduType)
-
getPduType
public int getPduType()
-
createPDU
public PDU createPDU(Target<?> target)
Create aPDU
instance for the supplied target.- Specified by:
createPDU
in interfacePDUFactory
- Parameters:
target
- theTarget
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 aScopedPDU
.
-
createPDU
public static PDU createPDU(Target<?> target, int pduType)
Create aPDU
instance for the supplied target. For GETBULK PDUs, the default max repetitions and non repeaters are used. SeeGETBULK_DEFAULT_MAX_REPETITIONS
andGETBULK_DEFAULT_NON_REPEATERS
.- Parameters:
target
- theTarget
where the PDU to be created will be sent.pduType
- a PDU type as specified byPDU
.- 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 aPDU
instance for the supplied target.- Parameters:
target
- theTarget
where the PDU to be created will be sent.pduType
- a PDU type as specified byPDU
.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 aPDU
instance for the specified SNMP version.- Parameters:
targetVersion
- a SNMP version as defined bySnmpConstants
.- Returns:
- a PDU instance that is compatible with the supplied target SNMP version.
- Since:
- 1.7.3
-
createPDU
public PDU createPDU(MessageProcessingModel messageProcessingModel)
Creates aPDU
instance for the specifiedMessageProcessingModel
.- Specified by:
createPDU
in interfacePDUFactory
- 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 aPDU
instance for the specifiedMessageProcessingModel
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
-
createPduByMP
private static PDU createPduByMP(MessageProcessingModel messageProcessingModel)
-
getMaxRepetitions
public int getMaxRepetitions()
Gets the maximum number of repetitions for the repetitions variable bindings forPDU.GETBULK
PDUs. Default isGETBULK_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 forPDU.GETBULK
PDUs. Default isGETBULK_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 forScopedPDU
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 forScopedPDU
instances created by this factory.- Parameters:
contextEngineID
- the context engine ID ornull
if context engine ID is the same as authoritative engine ID.- Since:
- 2.2
-
getContextName
public OctetString getContextName()
Gets the context name forScopedPDU
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 forScopedPDU
instances created by this factory.- Parameters:
contextName
- the context name ornull
for the default context.- Since:
- 2.2
-
-