- java.lang.Object
-
- org.snmp4j.AbstractTarget<A>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,Target<A>
- Direct Known Subclasses:
CommunityTarget,SecureTarget
public abstract class AbstractTarget<A extends Address> extends java.lang.Object implements Target<A>
AAbstractTargetclass is an abstract representation of a remote SNMP entity. It represents a target with an Address object, as well protocol parameters such as retransmission and timeout policy. Implementers of theTargetinterface can subclassAbstractTargetto take advantage of the implementation of commonTargetproperties.- Since:
- 1.2
- Version:
- 2.0
- Author:
- Frank Fock
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected intsecurityLevelprotected intsecurityModelprotected OctetStringsecurityName
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractTarget()Default constructorprotectedAbstractTarget(A address)Creates a SNMPv3 target with no retries and a timeout of one second.protectedAbstractTarget(A address, OctetString securityName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()booleanequals(java.lang.Object o)AgetAddress()Gets the address of this target.intgetMaxSizeRequestPDU()Gets the maximum size of request PDUs that this target is able to respond to.java.util.List<TransportMapping<? super A>>getPreferredTransports()Gets the prioritised list of transport mappings to be used for this target.intgetRetries()Gets the number of retries.intgetSecurityLevel()Gets the security level associated with this target.intgetSecurityModel()Gets the security model associated with this target.OctetStringgetSecurityName()Gets the security name associated with this target.longgetTimeout()Gets the timeout for a target.intgetVersion()Gets the SNMP version (NMP messagen processing model) of the target.inthashCode()voidsetAddress(A address)Sets the address of the target.voidsetMaxSizeRequestPDU(int maxSizeRequestPDU)Sets the maximum size of request PDUs that this target is able to receive.voidsetPreferredTransports(java.util.List<TransportMapping<? super A>> preferredTransports)Sets the prioritised list of transport mappings to be used for this target.voidsetRetries(int retries)Sets the number of retries to be performed before a request is timed out.voidsetSecurityLevel(int securityLevel)Sets the security level for this target.voidsetSecurityModel(int securityModel)Sets the security model for this target.voidsetSecurityName(OctetString securityName)Sets the security name to be used with this target.voidsetTimeout(long timeout)Sets the timeout for a target.voidsetVersion(int version)Sets the SNMP version (thus the SNMP message processing model) of the target.java.lang.StringtoString()protected java.lang.StringtoStringAbstractTarget()
-
-
-
Field Detail
-
securityLevel
protected int securityLevel
-
securityModel
protected int securityModel
-
securityName
protected OctetString securityName
-
-
Constructor Detail
-
AbstractTarget
protected AbstractTarget()
Default constructor
-
AbstractTarget
protected AbstractTarget(A address)
Creates a SNMPv3 target with no retries and a timeout of one second.- Parameters:
address- anAddressinstance.
-
AbstractTarget
protected AbstractTarget(A address, OctetString securityName)
-
-
Method Detail
-
getAddress
public A getAddress()
Gets the address of this target.- Specified by:
getAddressin interfaceTarget<A extends Address>- Returns:
- an Address instance.
-
setAddress
public void setAddress(A address)
Sets the address of the target.- Specified by:
setAddressin interfaceTarget<A extends Address>- Parameters:
address- an Address instance.
-
setVersion
public void setVersion(int version)
Sets the SNMP version (thus the SNMP message processing model) of the target.- Specified by:
setVersionin interfaceTarget<A extends Address>- Parameters:
version- the message processing model ID.- See Also:
SnmpConstants.version1,SnmpConstants.version2c,SnmpConstants.version3
-
getVersion
public int getVersion()
Gets the SNMP version (NMP messagen processing model) of the target.- Specified by:
getVersionin interfaceTarget<A extends Address>- Returns:
- the message processing model ID.
- See Also:
SnmpConstants.version1,SnmpConstants.version2c,SnmpConstants.version3
-
setRetries
public void setRetries(int retries)
Sets the number of retries to be performed before a request is timed out.- Specified by:
setRetriesin interfaceTarget<A extends Address>- Parameters:
retries- the number of retries. Note: If the number of retries is set to 0, then the request will be sent out exactly once.
-
getRetries
public int getRetries()
Gets the number of retries.- Specified by:
getRetriesin interfaceTarget<A extends Address>- Returns:
- an integer >= 0.
-
setTimeout
public void setTimeout(long timeout)
Sets the timeout for a target.- Specified by:
setTimeoutin interfaceTarget<A extends Address>- Parameters:
timeout- timeout in milliseconds before a confirmed request is resent or timed out.
-
getTimeout
public long getTimeout()
Gets the timeout for a target.- Specified by:
getTimeoutin interfaceTarget<A extends Address>- Returns:
- the timeout in milliseconds.
-
getMaxSizeRequestPDU
public int getMaxSizeRequestPDU()
Gets the maximum size of request PDUs that this target is able to respond to. The default is 65535.- Specified by:
getMaxSizeRequestPDUin interfaceTarget<A extends Address>- Returns:
- the maximum PDU size of request PDUs for this target. Which is always greater than 484.
-
setMaxSizeRequestPDU
public void setMaxSizeRequestPDU(int maxSizeRequestPDU)
Sets the maximum size of request PDUs that this target is able to receive.- Specified by:
setMaxSizeRequestPDUin interfaceTarget<A extends Address>- Parameters:
maxSizeRequestPDU- the maximum PDU (SNMP message) size this session will be able to process.
-
getPreferredTransports
public java.util.List<TransportMapping<? super A>> getPreferredTransports()
Description copied from interface:TargetGets the prioritised list of transport mappings to be used for this target. The first mapping in the list that matches the target address is chosen for sending new requests.- Specified by:
getPreferredTransportsin interfaceTarget<A extends Address>- Returns:
- an ordered list of
TransportMappinginstances.
-
setPreferredTransports
public void setPreferredTransports(java.util.List<TransportMapping<? super A>> preferredTransports)
Sets the prioritised list of transport mappings to be used for this target. The first mapping in the list that matches the target address will be chosen for sending new requests. If the value is set tonull(default), the appropriateTransportMappingwill be chosen by the suppliedaddressof the target. If an entity supports more than oneTransportMappingfor anAddressclass, the the results are not defined. This situation can be controlled by setting this preferredTransports list.- Parameters:
preferredTransports- a list of transport mappings that are preferred for this target class.- Since:
- 2.0
-
toStringAbstractTarget
protected java.lang.String toStringAbstractTarget()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
clone
public java.lang.Object clone()
-
getSecurityModel
public int getSecurityModel()
Description copied from interface:TargetGets the security model associated with this target.- Specified by:
getSecurityModelin interfaceTarget<A extends Address>- Returns:
- an
intvalue as defined in theSecurityModelinterface or any third party subclass thereof.
-
getSecurityName
public final OctetString getSecurityName()
Description copied from interface:TargetGets the security name associated with this target. The security name is used by the security model to lookup further parameters like authentication and privacy protocol settings from the security model dependent internal storage.- Specified by:
getSecurityNamein interfaceTarget<A extends Address>- Returns:
- an
OctetStringinstance (nevernull).
-
getSecurityLevel
public int getSecurityLevel()
Description copied from interface:TargetGets the security level associated with this target.- Specified by:
getSecurityLevelin interfaceTarget<A extends Address>- Returns:
- one of
-
setSecurityLevel
public void setSecurityLevel(int securityLevel)
Sets the security level for this target. The supplied security level must be supported by the security model dependent information associated with the security name set for this target.- Specified by:
setSecurityLevelin interfaceTarget<A extends Address>- Parameters:
securityLevel- one of
-
setSecurityModel
public void setSecurityModel(int securityModel)
Sets the security model for this target.- Specified by:
setSecurityModelin interfaceTarget<A extends Address>- Parameters:
securityModel- anintvalue as defined in theSecurityModelinterface or any third party subclass thereof.
-
setSecurityName
public final void setSecurityName(OctetString securityName)
Sets the security name to be used with this target.- Specified by:
setSecurityNamein interfaceTarget<A extends Address>- Parameters:
securityName- anOctetStringinstance (must not benull).- See Also:
getSecurityName()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-