Package org.snmp4j.agent.mox
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
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
BufferedMOTableModel.BufferedMOTableRow<R extends org.snmp4j.agent.mo.MOTableRow>
The BufferedMOTableRow is a wrapper class that holds additional information for the buffering.protected class
The RowBufferIterator implements the iterator needed by theMOTableModel
to traverse the model's rows. -
Field Summary
Modifier and TypeFieldDescriptionprotected final List
<BufferedMOTableModel<R>.BufferedMOTableRow<R>> protected final SortedMap
<org.snmp4j.smi.OID, BufferedMOTableModel<R>.BufferedMOTableRow<R>> protected long
The number of rows that were read from the buffer without backend access.protected long
The number of rows that were read from the backend, because they were not found or not valid in the buffer.protected long
The timeout for buffered rows in 10^-9 seconds.protected int
The number of rows that are fetched withfetchNextRows(org.snmp4j.smi.OID, int)
consecutively to minimize the number of backend read operations.protected int
The number of columns in this table model.protected BufferedMOTableModel<R>.BufferedMOTableRow
<R> protected BufferedMOTableModel<R>.BufferedMOTableRow
<R> protected int
The maximum number of rows in the buffer.protected org.snmp4j.agent.mo.MOTableRowFactory
<R> -
Constructor Summary
ModifierConstructorDescriptionprotected
BufferedMOTableModel
(org.snmp4j.agent.mo.MOTableRowFactory<R> rowFactory) Creates a BufferedMOTableModel with the specifiedMOTableRowFactory
. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Removes any rows from the buffer that exceed the buffer's size limit (FIFO).abstract boolean
containsRow
(org.snmp4j.smi.OID index) fetchNextRows
(org.snmp4j.smi.OID lowerBound, int chunkSize) Fetches a list of rows from the backend source.protected abstract org.snmp4j.smi.Variable[]
fetchRow
(org.snmp4j.smi.OID index) Fetches the specified row from the backend source.abstract org.snmp4j.smi.OID
firstRow()
long
Returns the number of row accesses that were served by the buffer.long
The number of row accesses that could not be served from the buffer and thus needed backend processing.long
Gets the timeout nano-seconds for buffered rows.int
Returns the chunk size for GETNEXT like buffer fetching with thefetchNextRows(org.snmp4j.smi.OID, int)
operation.int
protected BufferedMOTableModel<R>.BufferedMOTableRow
<R> Gets the first row from the buffer or the backend if not available from the buffer.protected BufferedMOTableModel<R>.BufferedMOTableRow
<R> Gets the last row from the buffer or the backend if not available from the buffer.int
Returns the maximum number of rows in the buffer.getRow
(org.snmp4j.smi.OID index) 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.abstract int
org.snmp4j.agent.mo.MOTableRowFactory
<R> protected BufferedMOTableModel<R>.BufferedMOTableRow
<R> getRowFromBuffer
(org.snmp4j.smi.OID index) Gets a row from the buffer.protected boolean
isRowValid
(long lastRefreshNanoTime) Tests if the given timestamp (in nano seconds as retrieved fromSystem.nanoTime()
) denotes a valid row.iterator()
abstract org.snmp4j.smi.OID
lastRow()
removeRow
(org.snmp4j.smi.OID index) Removes a row from the table.void
Removes all rows from the internal buffer.void
setBufferTimeoutNanoSeconds
(long bufferTimeoutNanoSeconds) Sets the timeout nano-seconds for buffered rows.void
setChunkSize
(int chunkSize) Sets the chunk size for GETNEXT like buffer fetching with thefetchNextRows(org.snmp4j.smi.OID, int)
operation.void
setMaxBufferSize
(int maxBufferSize) Sets the maximum number of rows in the buffer.void
setRowFactory
(org.snmp4j.agent.mo.MOTableRowFactory<R> rowFactory) Sets the factory instance to be used for creating rows for this model.tailIterator
(org.snmp4j.smi.OID lowerBound) toString()
protected BufferedMOTableModel<R>.BufferedMOTableRow
<R> updateBuffer
(List<R> newBufferRows, BufferedMOTableModel<R>.BufferedMOTableRow<R> predecessor) Updates the internal buffer with a list of consecutive rows.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.snmp4j.agent.mo.MOTableModel
isEmpty
-
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 columnCountThe number of columns in this table model. -
bufferTimeoutNanoSeconds
protected long bufferTimeoutNanoSecondsThe timeout for buffered rows in 10^-9 seconds. -
chunkSize
protected int chunkSizeThe number of rows that are fetched withfetchNextRows(org.snmp4j.smi.OID, int)
consecutively to minimize the number of backend read operations. -
maxBufferSize
protected int maxBufferSizeThe maximum number of rows in the buffer. While requests processing the actual upper bound of the buffer might be the sum ofgetMaxBufferSize()
andgetChunkSize()
. -
bufferHits
protected long bufferHitsThe number of rows that were read from the buffer without backend access. -
bufferMisses
protected long bufferMissesThe number of rows that were read from the backend, because they were not found or not valid in the buffer.
-
-
Constructor Details
-
BufferedMOTableModel
Creates a BufferedMOTableModel with the specifiedMOTableRowFactory
.- Parameters:
rowFactory
- the row factory to be used to create rows from backend data.
-
-
Method Details
-
setRowFactory
Sets the factory instance to be used for creating rows for this model.- Parameters:
rowFactory
- aMOTableRowFactory
instance ornull
to disable row creation.
-
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 thefetchNextRows(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 thefetchNextRows(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 interfaceorg.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
-
getRowCount
public abstract int getRowCount()- Specified by:
getRowCount
in interfaceorg.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 interfaceorg.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
-
getRow
- Specified by:
getRow
in interfaceorg.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
-
getRow
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
- iftrue
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
- Specified by:
iterator
in interfaceorg.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
-
tailIterator
- Specified by:
tailIterator
in interfaceorg.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
-
lastIndex
public abstract org.snmp4j.smi.OID lastIndex()- Specified by:
lastIndex
in interfaceorg.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
-
firstIndex
public abstract org.snmp4j.smi.OID firstIndex()- Specified by:
firstIndex
in interfaceorg.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
-
firstRow
- Specified by:
firstRow
in interfaceorg.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
-
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
- Specified by:
lastRow
in interfaceorg.snmp4j.agent.mo.MOTableModel<R extends org.snmp4j.agent.mo.MOTableRow>
-
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 fromSystem.nanoTime()
) denotes a valid row.- Parameters:
lastRefreshNanoTime
- the last refresh timestamp from a buffered row.- Returns:
true
if(System.nanoTime() - lastRefreshNanoTime < bufferTimeoutNanoSeconds)
-
getRowFromBuffer
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
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
Removes a row from the table. By default this method throws aUnsupportedOperationException
.- 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
-