- 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>
AAbstractTarget
class 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 theTarget
interface can subclassAbstractTarget
to take advantage of the implementation of commonTarget
properties. The default timeout can be set withSNMP4JSettings.setDefaultTimeoutMillis(long)
.- Since:
- 1.2
- Version:
- 2.0
- Author:
- Frank Fock
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected int
securityLevel
protected int
securityModel
protected OctetString
securityName
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractTarget()
Default constructorprotected
AbstractTarget(A address)
Creates a SNMPv3 target with no retries and a timeout of one second.protected
AbstractTarget(A address, OctetString securityName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
boolean
equals(java.lang.Object o)
A
getAddress()
Gets the address of this target.int
getMaxSizeRequestPDU()
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.int
getRetries()
Gets the number of retries.int
getSecurityLevel()
Gets the security level associated with this target.int
getSecurityModel()
Gets the security model associated with this target.OctetString
getSecurityName()
Gets the security name associated with this target.long
getTimeout()
Gets the timeout for a target.int
getVersion()
Gets the SNMP version (NMP messagen processing model) of the target.int
hashCode()
void
setAddress(A address)
Sets the address of the target.void
setMaxSizeRequestPDU(int maxSizeRequestPDU)
Sets the maximum size of request PDUs that this target is able to receive.void
setPreferredTransports(java.util.List<TransportMapping<? super A>> preferredTransports)
Sets the prioritised list of transport mappings to be used for this target.void
setRetries(int retries)
Sets the number of retries to be performed before a request is timed out.void
setSecurityLevel(int securityLevel)
Sets the security level for this target.void
setSecurityModel(int securityModel)
Sets the security model for this target.void
setSecurityName(OctetString securityName)
Sets the security name to be used with this target.void
setTimeout(long timeout)
Sets the timeout for a target.void
setVersion(int version)
Sets the SNMP version (thus the SNMP message processing model) of the target.java.lang.String
toString()
protected java.lang.String
toStringAbstractTarget()
-
-
-
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
- anAddress
instance.
-
AbstractTarget
protected AbstractTarget(A address, OctetString securityName)
-
-
Method Detail
-
getAddress
public A getAddress()
Gets the address of this target.- Specified by:
getAddress
in interfaceTarget<A extends Address>
- Returns:
- an Address instance.
-
setAddress
public void setAddress(A address)
Sets the address of the target.- Specified by:
setAddress
in 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:
setVersion
in 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:
getVersion
in 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:
setRetries
in 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:
getRetries
in interfaceTarget<A extends Address>
- Returns:
- an integer >= 0.
-
setTimeout
public void setTimeout(long timeout)
Sets the timeout for a target.- Specified by:
setTimeout
in 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:
getTimeout
in 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:
getMaxSizeRequestPDU
in 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:
setMaxSizeRequestPDU
in 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:Target
Gets 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:
getPreferredTransports
in interfaceTarget<A extends Address>
- Returns:
- an ordered list of
TransportMapping
instances.
-
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 appropriateTransportMapping
will be chosen by the suppliedaddress
of the target. If an entity supports more than oneTransportMapping
for anAddress
class, 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:
toString
in classjava.lang.Object
-
clone
public java.lang.Object clone()
-
getSecurityModel
public int getSecurityModel()
Description copied from interface:Target
Gets the security model associated with this target.- Specified by:
getSecurityModel
in interfaceTarget<A extends Address>
- Returns:
- an
int
value as defined in theSecurityModel
interface or any third party subclass thereof.
-
getSecurityName
public final OctetString getSecurityName()
Description copied from interface:Target
Gets 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:
getSecurityName
in interfaceTarget<A extends Address>
- Returns:
- an
OctetString
instance (nevernull
).
-
getSecurityLevel
public int getSecurityLevel()
Description copied from interface:Target
Gets the security level associated with this target.- Specified by:
getSecurityLevel
in 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:
setSecurityLevel
in interfaceTarget<A extends Address>
- Parameters:
securityLevel
- one of
-
setSecurityModel
public void setSecurityModel(int securityModel)
Sets the security model for this target.- Specified by:
setSecurityModel
in interfaceTarget<A extends Address>
- Parameters:
securityModel
- anint
value as defined in theSecurityModel
interface 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:
setSecurityName
in interfaceTarget<A extends Address>
- Parameters:
securityName
- anOctetString
instance (must not benull
).- See Also:
getSecurityName()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-