java.lang.Object
org.snmp4j.agent.mo.snmp.RowCount
- All Implemented Interfaces:
Cloneable
,Comparable<org.snmp4j.smi.Variable>
,org.snmp4j.asn1.BERSerializable
,org.snmp4j.smi.Variable
The
RowCount
class implements a Variable
that counts the rows of a table and returns the number
of rows as value. This class is a dynamic Variable, which means it needs to be cloned when serialized.
When cloned, a Gauge32
instance with the row count of the source table will be created.- Since:
- 3.2.1
- Author:
- Frank Fock
-
Field Summary
Fields inherited from interface org.snmp4j.smi.Variable
serialVersionUID
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
Clones this variable.int
compareTo
(org.snmp4j.smi.Variable o) void
decodeBER
(org.snmp4j.asn1.BERInputStream inputStream) Decodes aVariable
from anInputStream
.void
encodeBER
(OutputStream outputStream) Encodes aVariable
to anOutputStream
.void
fromSubIndex
(org.snmp4j.smi.OID subIndex, boolean impliedLength) Sets the value of thisVariable
from the supplied (sub-)index.int
Returns the length of thisBERSerializable
object in bytes when encoded according to the Basic Encoding Rules (BER).int
Returns the length of the payload of thisBERSerializable
object in bytes when encoded according to the Basic Encoding Rules (BER).int
Gets the ASN.1 syntax identifier value of this SNMP variable.Gets a textual description of this Variable.long
getValue()
Gets the number of rows in the associated table as unsigned long value.boolean
Indicates whether this variable is dynamic.boolean
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.org.snmp4j.smi.OID
toSubIndex
(boolean impliedLength) Converts the value of thisVariable
to a (sub-)index value.Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.snmp4j.smi.Variable
equals, hashCode, toString
-
Constructor Details
-
Method Details
-
getValue
public long getValue()Gets the number of rows in the associated table as unsigned long value.- Returns:
- the number of rows in the associated table (greater or equal to zero). Zero is returned if a
null
table is associated.
-
compareTo
public int compareTo(org.snmp4j.smi.Variable o) - Specified by:
compareTo
in interfaceComparable<org.snmp4j.smi.Variable>
- Specified by:
compareTo
in interfaceorg.snmp4j.smi.Variable
-
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. -
getSyntax
public int getSyntax()Gets the ASN.1 syntax identifier value of this SNMP variable.- Specified by:
getSyntax
in interfaceorg.snmp4j.smi.Variable
- Returns:
- an integer value < 128 for regular SMI objects and a value >= 128 for exception values like noSuchObject, noSuchInstance, and endOfMibView.
-
isException
public boolean isException()Checks whether this variable represents an exception like noSuchObject, noSuchInstance, and endOfMibView.- Specified by:
isException
in interfaceorg.snmp4j.smi.Variable
- Returns:
true
if the syntax of this variable is an instance ofNull
and its syntax equals one of the following:SMIConstants.EXCEPTION_NO_SUCH_OBJECT
SMIConstants.EXCEPTION_NO_SUCH_INSTANCE
SMIConstants.EXCEPTION_END_OF_MIB_VIEW
-
toInt
public int toInt()Returns an integer representation of this variable if such a representation exists.- Specified by:
toInt
in interfaceorg.snmp4j.smi.Variable
- 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:
UnsupportedOperationException
- if an integer representation does not exists for this Variable.
-
toLong
public long toLong()Returns a long representation of this variable if such a representation exists.- Specified by:
toLong
in interfaceorg.snmp4j.smi.Variable
- Returns:
- a long value.
- Throws:
UnsupportedOperationException
- if a long representation does not exists for this Variable.
-
getSyntaxString
Gets a textual description of this Variable.- Specified by:
getSyntaxString
in interfaceorg.snmp4j.smi.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
public org.snmp4j.smi.OID toSubIndex(boolean impliedLength) Converts the value of thisVariable
to a (sub-)index value.- Specified by:
toSubIndex
in interfaceorg.snmp4j.smi.Variable
- 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:
UnsupportedOperationException
- if this variable cannot be used in an index.
-
fromSubIndex
public void fromSubIndex(org.snmp4j.smi.OID subIndex, boolean impliedLength) Sets the value of thisVariable
from the supplied (sub-)index.- Specified by:
fromSubIndex
in interfaceorg.snmp4j.smi.Variable
- 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:
UnsupportedOperationException
- if this variable cannot be used in an index.
-
isDynamic
public 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 withgetBERLength()
for encoding enclosing SEQUENCES and the actual encoding of the Variable itself withencodeBER(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); } }
- Specified by:
isDynamic
in interfaceorg.snmp4j.smi.Variable
- Returns:
true
because the variable might change its value between two calls togetBERLength()
andencodeBER(java.io.OutputStream)
.
-
getBERLength
public int getBERLength()Returns the length of thisBERSerializable
object in bytes when encoded according to the Basic Encoding Rules (BER).- Specified by:
getBERLength
in interfaceorg.snmp4j.asn1.BERSerializable
- Returns:
- the BER encoded length of this variable.
-
getBERPayloadLength
public int getBERPayloadLength()Returns the length of the payload of thisBERSerializable
object in bytes when encoded according to the Basic Encoding Rules (BER).- Specified by:
getBERPayloadLength
in interfaceorg.snmp4j.asn1.BERSerializable
- Returns:
- the BER encoded length of this variable.
-
decodeBER
Decodes aVariable
from anInputStream
.- Specified by:
decodeBER
in interfaceorg.snmp4j.asn1.BERSerializable
- Parameters:
inputStream
- anInputStream
containing a BER encoded byte stream.- Throws:
IOException
- if the stream could not be decoded by using BER rules.
-
encodeBER
Encodes aVariable
to anOutputStream
.- Specified by:
encodeBER
in interfaceorg.snmp4j.asn1.BERSerializable
- Parameters:
outputStream
- anOutputStream
.- Throws:
IOException
- if an error occurs while writing to the stream.
-