Class BufferedMOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>

java.lang.Object
org.snmp4j.agent.mox.BufferedMOTableModel<R>
All Implemented Interfaces:
org.snmp4j.agent.mo.MOTableModel<R>
Direct Known Subclasses:
BufferedMOMutableTableModel

public abstract class BufferedMOTableModel<R extends org.snmp4j.agent.mo.MOTableRow> extends Object implements org.snmp4j.agent.mo.MOTableModel<R>
The BufferedMOTableModel is a read-only table model that dynamically loads data from an backend as needed. The internal buffer holds up to getMaxBufferSize() rows fetched from the backend. Rows are removed from the buffer either when they are older than getBufferTimeoutNanoSeconds() or if the maximum number of buffered rows is reached.

The MOTableRowFactory is needed to create table rows from the backend plain row data.

Since:
2.2
Version:
3.0
Author:
Frank Fock
  • Field Details

    • bufferedRows

      protected final SortedMap<org.snmp4j.smi.OID,BufferedMOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>.BufferedMOTableRow<R extends org.snmp4j.agent.mo.MOTableRow>> bufferedRows
    • bufferedChunksList

      protected final List<BufferedMOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>.BufferedMOTableRow<R extends org.snmp4j.agent.mo.MOTableRow>> bufferedChunksList
    • firstRow

      protected BufferedMOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>.BufferedMOTableRow<R extends org.snmp4j.agent.mo.MOTableRow> firstRow
    • lastRow

      protected BufferedMOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>.BufferedMOTableRow<R extends org.snmp4j.agent.mo.MOTableRow> lastRow
    • rowFactory

      protected org.snmp4j.agent.mo.MOTableRowFactory<R extends org.snmp4j.agent.mo.MOTableRow> rowFactory
    • columnCount

      protected int columnCount
      The number of columns in this table model.
    • bufferTimeoutNanoSeconds

      protected long bufferTimeoutNanoSeconds
      The timeout for buffered rows in 10^-9 seconds.
    • chunkSize

      protected int chunkSize
      The number of rows that are fetched with fetchNextRows(org.snmp4j.smi.OID, int) consecutively to minimize the number of backend read operations.
    • maxBufferSize

      protected int maxBufferSize
      The maximum number of rows in the buffer. While requests processing the actual upper bound of the buffer might be the sum of getMaxBufferSize() and getChunkSize().
    • bufferHits

      protected long bufferHits
      The number of rows that were read from the buffer without backend access.
    • bufferMisses

      protected long bufferMisses
      The number of rows that were read from the backend, because they were not found or not valid in the buffer.
  • Constructor Details

    • BufferedMOTableModel

      protected BufferedMOTableModel(org.snmp4j.agent.mo.MOTableRowFactory<R> rowFactory)
      Creates a BufferedMOTableModel with the specified MOTableRowFactory.
      Parameters:
      rowFactory - the row factory to be used to create rows from backend data.
  • Method Details

    • setRowFactory

      public void setRowFactory(org.snmp4j.agent.mo.MOTableRowFactory<R> rowFactory)
      Sets the factory instance to be used for creating rows for this model.
      Parameters:
      rowFactory - a MOTableRowFactory instance or null to disable row creation.
    • getRowFactory

      public org.snmp4j.agent.mo.MOTableRowFactory<R> getRowFactory()
    • getBufferTimeoutNanoSeconds

      public long getBufferTimeoutNanoSeconds()
      Gets the timeout nano-seconds for buffered rows.
      Returns:
      the number of nano-seconds after which an buffered row is invalidated and removed from the buffer.
    • setBufferTimeoutNanoSeconds

      public void setBufferTimeoutNanoSeconds(long bufferTimeoutNanoSeconds)
      Sets the timeout nano-seconds for buffered rows.
      Parameters:
      bufferTimeoutNanoSeconds - the number of nano-seconds after which an buffered row is invalidated and removed from the buffer.
    • getMaxBufferSize

      public int getMaxBufferSize()
      Returns the maximum number of rows in the buffer.
      Returns:
      the size of the row buffer.
    • setMaxBufferSize

      public void setMaxBufferSize(int maxBufferSize)
      Sets the maximum number of rows in the buffer. The default is
      Parameters:
      maxBufferSize - the size of the row buffer.
    • getChunkSize

      public int getChunkSize()
      Returns the chunk size for GETNEXT like buffer fetching with the fetchNextRows(org.snmp4j.smi.OID, int) operation. The default is 10.
      Returns:
      the chunk size for consecutive row fetching from the backend.
    • setChunkSize

      public void setChunkSize(int chunkSize)
      Sets the chunk size for GETNEXT like buffer fetching with the fetchNextRows(org.snmp4j.smi.OID, int) operation. The default is 10.
      Parameters:
      chunkSize - the chunk size for consecutive row fetching from the backend.
    • getColumnCount

      public int getColumnCount()
      Specified by:
      getColumnCount in interface org.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
    • getRowCount

      public abstract int getRowCount()
      Specified by:
      getRowCount in interface org.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
    • containsRow

      public abstract boolean containsRow(org.snmp4j.smi.OID index)
      Specified by:
      containsRow in interface org.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
    • getRow

      public R getRow(org.snmp4j.smi.OID index)
      Specified by:
      getRow in interface org.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
    • getRow

      protected R getRow(org.snmp4j.smi.OID index, boolean putRowIntoBuffer)
      Gets a row from the internal buffer or the backend and puts it into the buffer if specified.
      Parameters:
      index - the index of the target row.
      putRowIntoBuffer - if true then the fetched row (not from the buffer) will be put into the buffer.
      Returns:
      the row with the given index or null if it does not exist.
    • iterator

      public Iterator<R> iterator()
      Specified by:
      iterator in interface org.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
    • tailIterator

      public Iterator<R> tailIterator(org.snmp4j.smi.OID lowerBound)
      Specified by:
      tailIterator in interface org.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
    • lastIndex

      public abstract org.snmp4j.smi.OID lastIndex()
      Specified by:
      lastIndex in interface org.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
    • firstIndex

      public abstract org.snmp4j.smi.OID firstIndex()
      Specified by:
      firstIndex in interface org.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
    • firstRow

      public R firstRow()
      Specified by:
      firstRow in interface org.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
    • getFirstBufferRow

      protected BufferedMOTableModel<R>.BufferedMOTableRow<R> getFirstBufferRow()
      Gets the first row from the buffer or the backend if not available from the buffer.
      Returns:
      the first row as buffered row.
    • lastRow

      public R lastRow()
      Specified by:
      lastRow in interface org.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
    • getLastBufferRow

      protected BufferedMOTableModel<R>.BufferedMOTableRow<R> getLastBufferRow()
      Gets the last row from the buffer or the backend if not available from the buffer.
      Returns:
      the last row as buffered row.
    • isRowValid

      protected boolean isRowValid(long lastRefreshNanoTime)
      Tests if the given timestamp (in nano seconds as retrieved from System.nanoTime()) denotes a valid row.
      Parameters:
      lastRefreshNanoTime - the last refresh timestamp from a buffered row.
      Returns:
      true if (System.nanoTime() - lastRefreshNanoTime &lt; bufferTimeoutNanoSeconds)
    • getRowFromBuffer

      protected BufferedMOTableModel<R>.BufferedMOTableRow<R> getRowFromBuffer(org.snmp4j.smi.OID index)
      Gets a row from the buffer.
      Parameters:
      index - the index of the target row.
      Returns:
      null if a row with the given index is not buffered (or no longer valid) and the buffered row with that index if that row could be found and is still valid.
    • fetchRow

      protected abstract org.snmp4j.smi.Variable[] fetchRow(org.snmp4j.smi.OID index)
      Fetches the specified row from the backend source.
      Parameters:
      index - the rows index OID value.
      Returns:
      the values of the fetched row or null if the row does not exists.
    • fetchNextRows

      protected abstract List<R> fetchNextRows(org.snmp4j.smi.OID lowerBound, int chunkSize)
      Fetches a list of rows from the backend source.
      Parameters:
      lowerBound - the lower bound index (inclusive) of the first row to return.
      chunkSize - the maximum number of rows to return. Less rows may be returned even if there are more available.
      Returns:
      a list of rows fetched from the backend. If the last element of the returned list is null, no more rows are available at the source.
    • removeRow

      public R removeRow(org.snmp4j.smi.OID index)
      Removes a row from the table. By default this method throws a UnsupportedOperationException.
      Parameters:
      index - the index of the target row.
      Returns:
      the removed row and null if such a row does not exist.
    • updateBuffer

      protected BufferedMOTableModel<R>.BufferedMOTableRow<R> updateBuffer(List<R> newBufferRows, BufferedMOTableModel<R>.BufferedMOTableRow<R> predecessor)
      Updates the internal buffer with a list of consecutive rows.
      Parameters:
      newBufferRows - a list of rows which must be in lexicographic order (regarding their index values) and without holes.
      predecessor - the preceding row of the buffer area that needs to be updated.
      Returns:
      the buffer row of the first row in the list. As buffer rows are linked by BufferedMOTableModel.BufferedMOTableRow.getNextRow() the buffered rows can be fully traversed by using that first row.
    • cleanupBuffer

      protected int cleanupBuffer()
      Removes any rows from the buffer that exceed the buffer's size limit (FIFO).
      Returns:
      the number of rows actually removed from the buffer.
    • getBufferHits

      public long getBufferHits()
      Returns the number of row accesses that were served by the buffer.
      Returns:
      the number of row accesses through the buffered.
    • getBufferMisses

      public long getBufferMisses()
      The number of row accesses that could not be served from the buffer and thus needed backend processing.
      Returns:
      the number of buffer misses.
    • resetBuffer

      public void resetBuffer()
      Removes all rows from the internal buffer. This method is synchronized to ensure a consistent buffer. It can be used to force a full buffer refresh.
    • toString

      public String toString()
      Overrides:
      toString in class Object