- java.lang.Object
-
- org.snmp4j.util.AbstractSnmpUtility
-
- org.snmp4j.util.TableUtils
-
public class TableUtils extends AbstractSnmpUtility
TheTableUtilsclass provides utility functions to retrieve SNMP tabular data.- Since:
- 1.0.2
- Version:
- 2.5.11
- Author:
- Frank Fock
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classTableUtils.ColumnsOfRequestprotected classTableUtils.DenseTableRequestTheDenseTableRequestextends TableRequest to implement a faster table retrieval than the original.protected classTableUtils.InternalTableListenerprotected classTableUtils.LastReceivedprotected classTableUtils.LastReceivedColumnInfoprotected classTableUtils.Rowstatic classTableUtils.SparseTableModeclassTableUtils.TableRequest
-
Field Summary
Fields Modifier and Type Field Description static intROWSTATUS_ACTIVEstatic intROWSTATUS_CREATEANDGOstatic intROWSTATUS_CREATEANDWAITstatic intROWSTATUS_DESTROYstatic intROWSTATUS_NOTINSERVICEstatic intROWSTATUS_NOTREADY-
Fields inherited from class org.snmp4j.util.AbstractSnmpUtility
pduFactory, session
-
-
Constructor Summary
Constructors Constructor Description TableUtils(Session snmpSession, PDUFactory pduFactory)Creates aTableUtilsinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <A extends Address>
ResponseEvent<A>createRow(Target<A> target, OID rowStatusColumnOID, OID rowIndex, VariableBinding[] values)Creates a SNMP table row for a table that supports the RowStatus mechanism for row creation.protected TableUtils.TableRequestcreateTableRequest(Target<?> target, OID[] columnOIDs, TableListener listener, java.lang.Object userObject, OID lowerBoundIndex, OID upperBoundIndex, TableUtils.SparseTableMode sparseTableMode)<A extends Address>
ResponseEvent<A>destroyRow(Target<A> target, OID rowStatusColumnOID, OID rowIndex)Destroys a SNMP table row from a table that support the RowStatus mechanism for row creation/deletion.voidgetDenseTable(Target<?> target, OID[] columnOIDs, TableListener listener, java.lang.Object userObject, OID lowerBoundIndex, OID upperBoundIndex)Gets SNMP tabular data from one or more tables.intgetIgnoreMaxLexicographicRowOrderingErrors()Gets the maximum number of rows with wrong lexicographic ordering whicb will be return on a table retrieval withisCheckLexicographicOrdering()set totrue.intgetMaxNumColumnsPerPDU()Gets the maximum number of columns that will be retrieved per SNMP GETNEXT or GETBULK request.intgetMaxNumRowsPerPDU()Gets the maximum number of rows that will be retrieved per SNMP GETBULK request.java.util.List<TableEvent>getTable(Target<?> target, OID[] columnOIDs, OID lowerBoundIndex, OID upperBoundIndex)Gets synchronously SNMP tabular data from one or more tables.voidgetTable(Target<?> target, OID[] columnOIDs, TableListener listener, java.lang.Object userObject, OID lowerBoundIndex, OID upperBoundIndex)Gets SNMP tabular data from one or more tables.voidgetTable(Target<?> target, OID[] columnOIDs, TableListener listener, java.lang.Object userObject, OID lowerBoundIndex, OID upperBoundIndex, TableUtils.SparseTableMode sparseTableMode)Gets SNMP tabular data from one or more tables.booleanisCheckLexicographicOrdering()Indicates whether a single request on behalf ofgetTable(Target, OID[], OID, OID)orgetTable(Target, OID[], TableListener, Object, OID, OID)is sent to the agent or not.booleanisSendColumnPDUsMultiThreaded()voidsetCheckLexicographicOrdering(boolean checkLexicographicOrdering)Enables or disables lexicographic ordering checks.voidsetIgnoreMaxLexicographicRowOrderingErrors(int ignoreMaxLexicographicRowOrderingErrors)Sets the maximum number of rows that will be returned with statusRetrievalEvent.STATUS_WRONG_ORDERbefore the table retrieval will be stopped.voidsetMaxNumColumnsPerPDU(int numberOfColumnsPerChunk)Sets the maximum number of columns that will be retrieved per SNMP GETNEXT or GETBULK request.voidsetMaxNumRowsPerPDU(int numberOfRowsPerChunk)Sets the maximum number of rows that will be retrieved per SNMP GETBULK request.voidsetSendColumnPDUsMultiThreaded(boolean sendColumnPDUsMultiThreaded)Enable multi-threaded column PDU sending.
-
-
-
Field Detail
-
ROWSTATUS_ACTIVE
public static final int ROWSTATUS_ACTIVE
- See Also:
- Constant Field Values
-
ROWSTATUS_NOTINSERVICE
public static final int ROWSTATUS_NOTINSERVICE
- See Also:
- Constant Field Values
-
ROWSTATUS_NOTREADY
public static final int ROWSTATUS_NOTREADY
- See Also:
- Constant Field Values
-
ROWSTATUS_CREATEANDGO
public static final int ROWSTATUS_CREATEANDGO
- See Also:
- Constant Field Values
-
ROWSTATUS_CREATEANDWAIT
public static final int ROWSTATUS_CREATEANDWAIT
- See Also:
- Constant Field Values
-
ROWSTATUS_DESTROY
public static final int ROWSTATUS_DESTROY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TableUtils
public TableUtils(Session snmpSession, PDUFactory pduFactory)
Creates aTableUtilsinstance. The created instance is thread safe as long as the suppliedSessionandPDUFactoryare thread safe.- Parameters:
snmpSession- a SNMPSessioninstance.pduFactory- aPDUFactoryinstance that creates the PDU that are used by this instance to retrieve table data using GETBULK/GETNEXT operations.
-
-
Method Detail
-
getTable
public java.util.List<TableEvent> getTable(Target<?> target, OID[] columnOIDs, OID lowerBoundIndex, OID upperBoundIndex)
Gets synchronously SNMP tabular data from one or more tables. The data is returned row-by-row as a list ofTableEventinstances. Each instance represents a row (or an error condition). Besides the target agent, the OIDs of the columnar objects have to be specified for which instances should be retrieved. With a lower bound index and an upper bound index, the result set can be narrowed to improve performance. This method can be executed concurrently by multiple threads.- Parameters:
target- aTargetinstance.columnOIDs- an array of OIDs of the columnar objects whose instances should be retrieved. The columnar objects may belong to different tables. Typically they belong to tables that share a common index or sub-index prefix. Note: The result of this method is not defined if instance OIDs are supplied in this array!lowerBoundIndex- an optional parameter that specifies the lower bound index. If notnull, all returned rows have an index greater thanlowerBoundIndex.upperBoundIndex- an optional parameter that specifies the upper bound index. If notnull, all returned rows have an index less or equal thanupperBoundIndex.- Returns:
- a
ListofTableEventinstances. Each instance represents successfully retrieved row or an error condition. Error conditions (any status other thanRetrievalEvent.STATUS_OK) may only appear at the last element of the list.
-
createTableRequest
protected TableUtils.TableRequest createTableRequest(Target<?> target, OID[] columnOIDs, TableListener listener, java.lang.Object userObject, OID lowerBoundIndex, OID upperBoundIndex, TableUtils.SparseTableMode sparseTableMode)
-
getTable
public void getTable(Target<?> target, OID[] columnOIDs, TableListener listener, java.lang.Object userObject, OID lowerBoundIndex, OID upperBoundIndex, TableUtils.SparseTableMode sparseTableMode)
Gets SNMP tabular data from one or more tables. The data is returned asynchronously row-by-row through a supplied callback. Besides the target agent, the OIDs of the columnar objects have to be specified for which instances should be retrieved. With a lower bound index and an upper bound index, the result set can be narrowed to improve performance.This method may call the
TableListener.finished(org.snmp4j.util.TableEvent)method before it returns. If you want to synchronize the main thread with the finishing of the table retrieval, follow this pattern:synchronized (this) { TableListener myListener = ... { private boolean finished; public boolean isFinished() { return finished; } public void finished(TableEvent event) { .. finished = true; synchronized (event.getUserObject()) { event.getUserObject().notify(); } } }; tableUtil.getTable(..,..,myListener,this,..,..); while (!myListener.isFinished()) { wait(); } }- Parameters:
target- aTargetinstance.columnOIDs- an array of OIDs of the columnar objects whose instances should be retrieved. The columnar objects may belong to different tables. Typically they belong to tables that share a common index or sub-index prefix. Note: The result of this method is not defined if instance OIDs are supplied in this array!listener- aTableListenerthat is called withTableEventobjects when an error occured, new rows have been retrieved, or when the table has been retrieved completely.userObject- an user object that is transparently supplied to the above call back.lowerBoundIndex- an optional parameter that specifies the lower bound index. If notnull, all returned rows have an index greater thanlowerBoundIndex.upperBoundIndex- an optional parameter that specifies the upper bound index. If notnull, all returned rows have an index less or equal thanupperBoundIndex.sparseTableMode- defines how rows with non existing column values should be handled. Such rows can occur when new rows are being created or rows are removed from an agent while it is being
-
getTable
public void getTable(Target<?> target, OID[] columnOIDs, TableListener listener, java.lang.Object userObject, OID lowerBoundIndex, OID upperBoundIndex)
Gets SNMP tabular data from one or more tables. The data is returned asynchronously row-by-row through a supplied callback. Besides the target agent, the OIDs of the columnar objects have to be specified for which instances should be retrieved. With a lower bound index and an upper bound index, the result set can be narrowed to improve performance.This method may call the
TableListener.finished(org.snmp4j.util.TableEvent)method before it returns. If you want to synchronize the main thread with the finishing of the table retrieval, follow this pattern:synchronized (this) { TableListener myListener = ... { private boolean finished; public boolean isFinished() { return finished; } public void finished(TableEvent event) { .. finished = true; synchronized (event.getUserObject()) { event.getUserObject().notify(); } } }; tableUtil.getTable(..,..,myListener,this,..,..); while (!myListener.isFinished()) { wait(); } }- Parameters:
target- aTargetinstance.columnOIDs- an array of OIDs of the columnar objects whose instances should be retrieved. The columnar objects may belong to different tables. Typically they belong to tables that share a common index or sub-index prefix. Note: The result of this method is not defined if instance OIDs are supplied in this array!listener- aTableListenerthat is called withTableEventobjects when an error occured, new rows have been retrieved, or when the table has been retrieved completely.userObject- an user object that is transparently supplied to the above call back.lowerBoundIndex- an optional parameter that specifies the lower bound index. If notnull, all returned rows have an index greater thanlowerBoundIndex.upperBoundIndex- an optional parameter that specifies the upper bound index. If notnull, all returned rows have an index less or equal thanupperBoundIndex.- Since:
- 1.5
-
getDenseTable
public void getDenseTable(Target<?> target, OID[] columnOIDs, TableListener listener, java.lang.Object userObject, OID lowerBoundIndex, OID upperBoundIndex)
Gets SNMP tabular data from one or more tables. The data is returned asynchronously row-by-row through a supplied callback. Besides the target agent, the OIDs of the columnar objects have to be specified for which instances should be retrieved. With a lower bound index and an upper bound index, the result set can be narrowed to improve performance.This implementation must not be used with sparse tables, because it is optimized for dense tables and will not return correct results for sparse tables.
Rows that appear or disappear while is being retrieved, are dropped and will be not returned partially (seeTableUtils.SparseTableMode.denseTableDropIncompleteRows).- Parameters:
target- aTargetinstance.columnOIDs- an array of OIDs of the columnar objects whose instances should be retrieved. The columnar objects may belong to different tables. Typically they belong to tables that share a common index or sub-index prefix. Note: The result of this method is not defined if instance OIDs are supplied in this array!listener- aTableListenerthat is called withTableEventobjects when an error occurred, new rows have been retrieved, or when the table has been retrieved completely.userObject- an user object that is transparently supplied to the above call back.lowerBoundIndex- an optional parameter that specifies the lower bound index. If notnull, all returned rows have an index greater thanlowerBoundIndex.upperBoundIndex- an optional parameter that specifies the upper bound index. If notnull, all returned rows have an index less or equal thanlowerBoundIndex.- Since:
- 3.0
-
getMaxNumRowsPerPDU
public int getMaxNumRowsPerPDU()
Gets the maximum number of rows that will be retrieved per SNMP GETBULK request.- Returns:
- an integer greater than zero that specifies the maximum number of rows to retrieve per SNMP GETBULK operation.
-
setMaxNumRowsPerPDU
public void setMaxNumRowsPerPDU(int numberOfRowsPerChunk)
Sets the maximum number of rows that will be retrieved per SNMP GETBULK request. The default is 10.- Parameters:
numberOfRowsPerChunk- an integer greater than zero that specifies the maximum number of rows to retrieve per SNMP GETBULK operation.
-
getMaxNumColumnsPerPDU
public int getMaxNumColumnsPerPDU()
Gets the maximum number of columns that will be retrieved per SNMP GETNEXT or GETBULK request.- Returns:
- an integer greater than zero that specifies the maximum columns of rows to retrieve per SNMP GETNEXT or GETBULK operation.
-
setMaxNumColumnsPerPDU
public void setMaxNumColumnsPerPDU(int numberOfColumnsPerChunk)
Sets the maximum number of columns that will be retrieved per SNMP GETNEXT or GETBULK request. The default is 10.- Parameters:
numberOfColumnsPerChunk- an integer greater than zero that specifies the maximum columns of rows to retrieve per SNMP GETNEXT or GETBULK operation.
-
isSendColumnPDUsMultiThreaded
public boolean isSendColumnPDUsMultiThreaded()
-
setSendColumnPDUsMultiThreaded
public void setSendColumnPDUsMultiThreaded(boolean sendColumnPDUsMultiThreaded)
Enable multi-threaded column PDU sending. If set totrueand if themaxNumColumnsPerPDUvalue is less than the number of columns to be retrieved in aTableUtilsrequest, then the requests for the columns will be splitted in two or more columns and the requests will be send to the agent concurrently without waiting for the response of the first/previous PDU. By default, this is disabled.- Parameters:
sendColumnPDUsMultiThreaded- iftrue, multi-threaded processing of column PDUs is enabled, otherwise only a single request will be sent to the agent on behalf agetTable(Target, OID[], OID, OID)orgetTable(Target, OID[], TableListener, Object, OID, OID).
-
isCheckLexicographicOrdering
public boolean isCheckLexicographicOrdering()
Indicates whether a single request on behalf ofgetTable(Target, OID[], OID, OID)orgetTable(Target, OID[], TableListener, Object, OID, OID)is sent to the agent or not.- Returns:
falseif single requests are sent,trueif more than a single request may be sent at a time.
-
getIgnoreMaxLexicographicRowOrderingErrors
public int getIgnoreMaxLexicographicRowOrderingErrors()
Gets the maximum number of rows with wrong lexicographic ordering whicb will be return on a table retrieval withisCheckLexicographicOrdering()set totrue.- Returns:
- the number of ignored row ordering errors.
- Since:
- 2.5.11
-
setIgnoreMaxLexicographicRowOrderingErrors
public void setIgnoreMaxLexicographicRowOrderingErrors(int ignoreMaxLexicographicRowOrderingErrors)
Sets the maximum number of rows that will be returned with statusRetrievalEvent.STATUS_WRONG_ORDERbefore the table retrieval will be stopped. If this value is set to zero and lexicographic ordering check is enabled bysetCheckLexicographicOrdering(boolean), then table retrieval finishes immediately when the error is detected. Otherwise retrieval continues until the maximum errors are detected and then the row cache will be returned too, although it may contain already incomplete rows based on correctly or incorrectly (!) ordered rows. The default value is three. That means, even if the ordering error occurs at the end of the table and- Parameters:
ignoreMaxLexicographicRowOrderingErrors- the maximum numbers of rows with lexicographic ordering error to be returned before finishing table retrieve automatically. Setting this value has no effect ifisCheckLexicographicOrdering()isfalse.- Since:
- 2.5.11
-
setCheckLexicographicOrdering
public void setCheckLexicographicOrdering(boolean checkLexicographicOrdering)
Enables or disables lexicographic ordering checks. By default, those checks are enabled, because otherwise with agents, that do not implement correct lexicographic ordering, endless looping could occur.- Parameters:
checkLexicographicOrdering-falseto disable checks which could increase performance.- Since:
- 2.5.10
-
createRow
public <A extends Address> ResponseEvent<A> createRow(Target<A> target, OID rowStatusColumnOID, OID rowIndex, VariableBinding[] values)
Creates a SNMP table row for a table that supports the RowStatus mechanism for row creation.- Type Parameters:
A- type of the targetAddress- Parameters:
target- the Target SNMP entity for the operation.rowStatusColumnOID- the column OID of the RowStatus column (without any instance identifier).rowIndex- the OID denoting the index of the table row to create.values- the values of columns to set in the row. Ifvaluesisnullthe row is created via the tripple mode row creation mechanism (RowStatus is set to createAndWait). Otherwise, each variable binding has to contain the OID of the columnar object ID (without any instance identifier) and its value. On return, the variable bindings will be modified so that the variable binding OIDs will contain the instance OIDs of the respective columns (thus column OID + rowIndex).- Returns:
- ResponseEvent
the ResponseEvent instance returned by the SNMP session on response
of the internally sent SET request. If
null, an IO exception has occurred. Otherwise, if the response PDU isnulla timeout has occurred. Otherwise, check the error status forSnmpConstants.SNMP_ERROR_SUCCESSto verify that the row creation was successful. - Since:
- 1.6
-
destroyRow
public <A extends Address> ResponseEvent<A> destroyRow(Target<A> target, OID rowStatusColumnOID, OID rowIndex)
Destroys a SNMP table row from a table that support the RowStatus mechanism for row creation/deletion.- Type Parameters:
A- address type of the target.- Parameters:
target- the Target SNMP entity for the operation.rowStatusColumnOID- the column OID of the RowStatus column (without any instance identifier).rowIndex- the OID denoting the index of the table row to destroy.- Returns:
- ResponseEvent
the ResponseEvent instance returned by the SNMP session on response
of the internally sent SET request. If
null, an IO exception has occurred. Otherwise, if the response PDU isnulla timeout has occurred, Otherwise, check the error status forSnmpConstants.SNMP_ERROR_SUCCESSto verify that the row creation was successful. - Since:
- 1.7.6
-
-