-
- All Superinterfaces:
BERSerializable
,java.lang.Cloneable
,java.lang.Comparable<Variable>
- All Known Implementing Classes:
AbstractVariable
,BitString
,Counter32
,Counter64
,DtlsAddress
,Gauge32
,GenericAddress
,Integer32
,IpAddress
,Null
,OctetString
,OID
,Opaque
,SMIAddress
,TcpAddress
,TimeTicks
,TlsAddress
,TransportIpAddress
,TsmSecurityParameters
,UdpAddress
,UnsignedInteger32
,VariantVariable
public interface Variable extends java.lang.Cloneable, java.lang.Comparable<Variable>, BERSerializable
TheVariable
interface defines common attributes of all SNMP variables.Before version 1.8, Variable has been an abstract class which has been renamed to
AbstractVariable
.- Since:
- 1.8
- Version:
- 1.8
- Author:
- Frank Fock
-
-
Field Summary
Fields Modifier and Type Field Description static long
serialVersionUID
This definition of a serialVersionUID for the Variable interface has been made for backward compatibility with SNMP4J 1.7.x or earlier serialized Variable instances.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Object
clone()
Clones this variable.int
compareTo(Variable o)
boolean
equals(java.lang.Object o)
void
fromSubIndex(OID subIndex, boolean impliedLength)
Sets the value of thisVariable
from the supplied (sub-)index.int
getSyntax()
Gets the ASN.1 syntax identifier value of this SNMP variable.java.lang.String
getSyntaxString()
Gets a textual description of this Variable.int
hashCode()
boolean
isDynamic()
Indicates whether this variable is dynamic.boolean
isException()
Checks whether this variable represents an exception like noSuchObject, noSuchInstance, and endOfMibView.int
toInt()
Returns an integer representation of this variable if such a representation exists.long
toLong()
Returns a long representation of this variable if such a representation exists.java.lang.String
toString()
Gets a string representation of the variable.OID
toSubIndex(boolean impliedLength)
Converts the value of thisVariable
to a (sub-)index value.-
Methods inherited from interface org.snmp4j.asn1.BERSerializable
decodeBER, encodeBER, getBERLength, getBERPayloadLength
-
-
-
-
Field Detail
-
serialVersionUID
static final long serialVersionUID
This definition of a serialVersionUID for the Variable interface has been made for backward compatibility with SNMP4J 1.7.x or earlier serialized Variable instances.- See Also:
- Constant Field Values
-
-
Method Detail
-
equals
boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
compareTo
int compareTo(Variable o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<Variable>
-
hashCode
int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
clone
java.lang.Object clone()
Clones this variable. Cloning can be used by the SNMP4J API to better support concurrency by creating a clone for internal processing. The content of this object is independent to the content of the clone. Thus, changes to the clone will have no effect to this object.- Returns:
- a new instance of this
Variable
with the same value.
-
getSyntax
int getSyntax()
Gets the ASN.1 syntax identifier value of this SNMP variable.- Returns:
- an integer value < 128 for regular SMI objects and a value >= 128 for exception values like noSuchObject, noSuchInstance, and endOfMibView.
-
isException
boolean isException()
Checks whether this variable represents an exception like noSuchObject, noSuchInstance, and endOfMibView.- Returns:
true
if the syntax of this variable is an instance ofNull
and its syntax equals one of the following:
-
toString
java.lang.String toString()
Gets a string representation of the variable.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of the variable's value.
-
toInt
int toInt()
Returns an integer representation of this variable if such a representation exists.- Returns:
- an integer value (if the native representation of this variable would be a long, then the long value will be casted to int).
- Throws:
java.lang.UnsupportedOperationException
- if an integer representation does not exists for this Variable.
-
toLong
long toLong()
Returns a long representation of this variable if such a representation exists.- Returns:
- a long value.
- Throws:
java.lang.UnsupportedOperationException
- if a long representation does not exists for this Variable.
-
getSyntaxString
java.lang.String getSyntaxString()
Gets a textual description of this Variable.- Returns:
- a textual description like 'Integer32' as used in the Structure of Management Information (SMI) modules. '?' is returned if the syntax is unknown.
-
toSubIndex
OID toSubIndex(boolean impliedLength)
Converts the value of thisVariable
to a (sub-)index value.- Parameters:
impliedLength
- specifies if the sub-index has an implied length. This parameter applies to variable length variables only (e.g.OctetString
andOID
). For other variables it has no effect.- Returns:
- an OID that represents this value as an (sub-)index.
- Throws:
java.lang.UnsupportedOperationException
- if this variable cannot be used in an index.
-
fromSubIndex
void fromSubIndex(OID subIndex, boolean impliedLength)
Sets the value of thisVariable
from the supplied (sub-)index.- Parameters:
subIndex
- the sub-index OID.impliedLength
- specifies if the sub-index has an implied length. This parameter applies to variable length variables only (e.g.OctetString
andOID
). For other variables it has no effect.- Throws:
java.lang.UnsupportedOperationException
- if this variable cannot be used in an index.
-
isDynamic
boolean isDynamic()
Indicates whether this variable is dynamic. If a variable is dynamic, precautions have to be taken when a Variable is serialized using BER encoding, because between determining the length withBERSerializable.getBERLength()
for encoding enclosing SEQUENCES and the actual encoding of the Variable itself withBERSerializable.encodeBER(java.io.OutputStream)
changes to the value need to be blocked by synchronization. In order to ensure proper synchronization if aVariable
is dynamic, modifications of the variables content need to synchronize on theVariable
instance. This can be achieved for the standard SMI Variable implementations for example bypublic static modifyVariable(Integer32 variable, int value) synchronize(variable) { variable.setValue(value); } }
- Returns:
true
if the variable might change its value between two calls toBERSerializable.getBERLength()
andBERSerializable.encodeBER(java.io.OutputStream)
andfalse
if the value is immutable or if its value does not change while serialization because of measures taken by the implementor (i.e. variable cloning).
-
-