Class RowCount

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

public class RowCount extends Object implements 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

    Constructors
    Constructor
    Description
    Creates a RowCount which returns zero always.
    RowCount(MOTable<?,?,?> moTable)
    Creates a row counting Gauge32 variable for the specified MOTable.
  • Method Summary

    Modifier and Type
    Method
    Description
    Clones this variable.
    int
    compareTo(org.snmp4j.smi.Variable o)
     
    void
    decodeBER(org.snmp4j.asn1.BERInputStream inputStream)
    Decodes a Variable from an InputStream.
    void
    encodeBER(OutputStream outputStream)
    Encodes a Variable to an OutputStream.
    void
    fromSubIndex(org.snmp4j.smi.OID subIndex, boolean impliedLength)
    Sets the value of this Variable from the supplied (sub-)index.
    int
    Returns the length of this BERSerializable object in bytes when encoded according to the Basic Encoding Rules (BER).
    int
    Returns the length of the payload of this BERSerializable 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
    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
    Returns an integer representation of this variable if such a representation exists.
    long
    Returns a long representation of this variable if such a representation exists.
    org.snmp4j.smi.OID
    toSubIndex(boolean impliedLength)
    Converts the value of this Variable 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

    • RowCount

      public RowCount()
      Creates a RowCount which returns zero always.
    • RowCount

      public RowCount(MOTable<?,?,?> moTable)
      Creates a row counting Gauge32 variable for the specified MOTable.
      Parameters:
      moTable - a table instance whose rows should be counted by this variable.
  • 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 interface Comparable<org.snmp4j.smi.Variable>
      Specified by:
      compareTo in interface org.snmp4j.smi.Variable
    • clone

      public 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.
      Specified by:
      clone in interface org.snmp4j.smi.Variable
      Overrides:
      clone in class Object
      Returns:
      a new instance of this Variable with the same value.
    • getSyntax

      public int getSyntax()
      Gets the ASN.1 syntax identifier value of this SNMP variable.
      Specified by:
      getSyntax in interface org.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 interface org.snmp4j.smi.Variable
      Returns:
      true if the syntax of this variable is an instance of Null 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 interface org.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 interface org.snmp4j.smi.Variable
      Returns:
      a long value.
      Throws:
      UnsupportedOperationException - if a long representation does not exists for this Variable.
    • getSyntaxString

      public String getSyntaxString()
      Gets a textual description of this Variable.
      Specified by:
      getSyntaxString in interface org.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 this Variable to a (sub-)index value.
      Specified by:
      toSubIndex in interface org.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 and OID). 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 this Variable from the supplied (sub-)index.
      Specified by:
      fromSubIndex in interface org.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 and OID). 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 with getBERLength() for encoding enclosing SEQUENCES and the actual encoding of the Variable itself with encodeBER(java.io.OutputStream) changes to the value need to be blocked by synchronization. In order to ensure proper synchronization if a Variable is dynamic, modifications of the variables content need to synchronize on the Variable instance. This can be achieved for the standard SMI Variable implementations for example by
          public static modifyVariable(Integer32 variable, int value)
            synchronize(variable) {
              variable.setValue(value);
            }
          }
       
      Specified by:
      isDynamic in interface org.snmp4j.smi.Variable
      Returns:
      true because the variable might change its value between two calls to getBERLength() and encodeBER(java.io.OutputStream).
    • getBERLength

      public int getBERLength()
      Returns the length of this BERSerializable object in bytes when encoded according to the Basic Encoding Rules (BER).
      Specified by:
      getBERLength in interface org.snmp4j.asn1.BERSerializable
      Returns:
      the BER encoded length of this variable.
    • getBERPayloadLength

      public int getBERPayloadLength()
      Returns the length of the payload of this BERSerializable object in bytes when encoded according to the Basic Encoding Rules (BER).
      Specified by:
      getBERPayloadLength in interface org.snmp4j.asn1.BERSerializable
      Returns:
      the BER encoded length of this variable.
    • decodeBER

      public void decodeBER(org.snmp4j.asn1.BERInputStream inputStream) throws IOException
      Decodes a Variable from an InputStream.
      Specified by:
      decodeBER in interface org.snmp4j.asn1.BERSerializable
      Parameters:
      inputStream - an InputStream containing a BER encoded byte stream.
      Throws:
      IOException - if the stream could not be decoded by using BER rules.
    • encodeBER

      public void encodeBER(OutputStream outputStream) throws IOException
      Encodes a Variable to an OutputStream.
      Specified by:
      encodeBER in interface org.snmp4j.asn1.BERSerializable
      Parameters:
      outputStream - an OutputStream.
      Throws:
      IOException - if an error occurs while writing to the stream.