com.adventnet.snmp.beans
Class SnmpTable

java.lang.Object
  |
  +--com.adventnet.snmp.beans.SnmpServer
        |
        +--com.adventnet.snmp.beans.SnmpTarget
              |
              +--com.adventnet.snmp.beans.SnmpTable
Direct Known Subclasses:
ClippedTable, SnmpTableModel

public class SnmpTable
extends SnmpTarget
implements java.lang.Runnable

The SnmpTable class handles polling for SNMP tables. It has been designed to support the Model-View-Controller design of JFC/swing applications, although this class can be used without JFC. An extension of this class in the com.adventnet.snmp.ui package is explicitly for JFC.

To use the table class, instantiate, and identify the SNMP table to be used. Then perform operations on the table, or register for table change events. For example,

  	SnmpTable table = new SnmpTable();
  	table.setTargetHost( "localhost" ); // set the agent hostname
  	table.loadMibs("rfc1213-mib"); // load MIBs
  
table.addSnmpTableListener(listener); // specify the listener
table.setTableOID("ifTable"); // this starts polling of table data

The resources used by this class are automatically garbage collected. No need to close sessions, or other cleanup by the user.

See the getSnmpTable.java application in the applications directory.

See Also:
Serialized Form

Field Summary
(package private)  int ADDandDELcol
           
(package private)  java.lang.String augmentedTableoid
           
(package private)  java.util.Vector cnam
           
(package private)  java.util.Vector colOIDs
           
(package private)  java.lang.Class[] columnClass
           
(package private)  java.lang.String[] columnNames
           
(package private)  java.util.Vector columns
           
(package private)  java.util.Vector columnsPolled
           
(package private)  int DATA_TYPE
           
(package private)  boolean[] editable
           
(package private)  java.util.Vector externalIndices
           
(package private)  int[] holes
           
(package private)  int holesCount
           
(package private)  boolean holesGot
           
(package private)  boolean isAugmentedTable
           
(package private)  boolean isEntryStatus
           
(package private)  boolean isNotInSubTree
           
(package private)  java.util.Vector noAccessIndex
           
(package private)  java.util.Vector nodes
           
(package private)  int num_col
           
(package private)  boolean performSets
           
(package private)  int pollInterval
           
(package private)  boolean RETRIEVAL_MODE
           
(package private)  int[] rootoid
           
(package private)  int rowtry
           
(package private)  boolean shifting
           
static int SNMP_VARIABLE_BINDING_DATA
          Constant to specify the format in which the data has to be returned.
static int SNMP_VARIABLE_DATA
          Constant to specify the format in which the data has to be returned.
static int STRING_DATA
          Constant to specify the format in which the data has to be returned.String is the default.
(package private)  java.util.Vector syntax
           
(package private)  java.util.Vector tableData
           
(package private)  java.util.Vector tableListeners
           
(package private)  SnmpOID tableOID
           
(package private)  java.lang.Thread thisThread
           
 
Fields inherited from class com.adventnet.snmp.beans.SnmpTarget
ackFlag, debugListeners, genericTrap, genericTraps, informReqID, mibModules, serialize, SNMPGET, SNMPGETBULK, SNMPGETNEXT, SNMPINFORM, SNMPREPORT, SNMPRESPONSE, SNMPSET, SNMPTRAP, snmpTrapEnterprise, snmpTrapOid, SNMPV2TRAP, upTime, VERSION1, VERSION2C, VERSION3
 
Fields inherited from class com.adventnet.snmp.beans.SnmpServer
api, applet, ASN1_ERROR_ERR, ASN1_ERROR_OID, attemptCompleteData, attemptPartialData, AUTH_NO_PRIV, AUTH_PRIV, authKey, authPassword, authProtocol, broadCast, clientID, community, contextID, contextName, count, debugon, DECRYPT_ERROR_ERR, DECRYPT_ERROR_OID, discoveryTimeSyncListener, enc, engineID, engineTable, error, errorCode, errorcodes, errorIndex, exceptionCode, exceptionCodes, finalize_called, group, group_oidList, isName, isNotSet, isSendPDUByGroup, listeners, localAddrs, localPort, logFlag, loggerImpl, logLevel, logType, matchServ, matchtable, MAX_NUM_ROWS, maxRepetitions, MD5_AUTH, mibOps, NO_AUTH, NO_AUTH_NO_PRIV, nonRepeaters, NOT_TIME_WINDOWS_ERR, NOT_TIME_WINDOWS_OID, nullsession_targets, oidList, options, pduErrorIndex, pollertargets, pollInterval, port, port_targets, principal, printStr, privKey, privPassword, privProtocol, propertylisteners, protocol, reqHandler, reqid, retries, secModel, securityLevel, sendTimeoutEvents, sentreqid, session, session_port_targets, session_targets, sessionName, SHA_AUTH, SNMPGET, SNMPGETBULK, SNMPGETNEXT, SNMPINFORM, SNMPREPORT, SNMPRESPONSE, SNMPSET, snmpStore, SNMPTRAP, SNMPV2TRAP, targetHost, targets, timeout, UKN_ENGINEID_ERR, UKN_ENGINEID_OID, UKN_USERNAMES_ERR, UKN_USERNAMES_OID, UNSUPP_SEC_LEVEL_ERR, UNSUPP_SEC_LEVEL_OID, userError, userErrorCode, usmTable, v3ErrorTable, validateUser, varbinds_per_request, varList, version, VERSION1, VERSION2C, VERSION3, writeCommunity, WRONG_DIGEST_ERR, WRONG_DIGEST_OID
 
Constructor Summary
SnmpTable()
          Use this constructor for applications.
SnmpTable(java.applet.Applet applet)
          Use this constructor for applets.
SnmpTable(int protocol, ProtocolOptions options)
          Use this constructor for applications which uses protocols other than UDP/IP.
SnmpTable(int port, java.lang.String session)
          Use this constructor for creating a new session for this application.
SnmpTable(SnmpSession ses, MibOperations mib)
          This constructor is used to create an SnmpTable instance with a specified SnmpSession and MibOperations.
 
Method Summary
 void addRow(boolean Status, java.lang.String[] oidlist, java.lang.String[] s)
          To add a new row of data into the table.
 void addSnmpTableListener(SnmpTableListener l)
          Adds a SnmpTableListener instance to the listener's list.Whenever a change in SnmpTable occurs all the registered listeners will be notified.
protected  void checkDifferences(java.util.Vector oldData)
          This method compares current table data with old data and notifies registered listeners of changes
protected  void compareRow(int row, java.util.Vector oldData)
          This method compares current data with old data for a given row and notifies registered listeners of changes
 void deleteRow(java.lang.String oid)
          To delete a row of data from the table.
protected  void finalize()
          Cleans up an object when there are no more references to the object.
protected  void genTableEvent(SnmpTableEvent evt)
          Generate the table events to the listeners.
 java.lang.Object getCellValue(java.lang.String tableOID, int rowIndex, int columnIndex)
          To get the value for the cell specified by the row and column index.
 java.lang.String[] getColumn(int columnIndex)
          Returns a string array of data for a column in the Table,represented by the index.
 java.lang.String[] getColumn(java.lang.String columnName)
          Returns a string array of data for a column in the Table, represented by the column name.Set the tableOID using setTableOID().
 java.lang.Class getColumnClass(int columnIndex)
          Returns the class to be used as renderer and editor for the column.
 int getColumnCount()
          Returns the number of columns in the table corresponding to the table OID already set.
 MibNode getColumnMibNode(int columnIndex)
          To Get the MibNode corresponding to the table column specified by the column index
 java.lang.String getColumnName(int columnIndex)
          Returns the name of the column specified by the column index.
 int getDataType()
          Returns the datatype in which the table data will be returned.
 int[] getHoles()
          Returns the index of the not-implemented columns.Holes are the columns that are not defined in the agent.
 java.lang.String[][] getIndices()
          Returns the indices of the SnmpTable.
 java.lang.String[][] getNotAccessibleIndex()
          Returns the values for the not-accessible indices in the table.
 java.lang.String[] getNotAccessibleIndexColumns()
          Returns the names of the not-accessible index columns in the table.
 boolean getPerformSets()
          To check if the values will get set if some change is made in any table field which has write access(any editable cell).
 void getPerformSets(boolean allowSets)
          To Activate/Deactivate an editable table field (cell).
 int getPollInterval()
          Returns the current polling interval in seconds.
 boolean getRetrievalMode()
          Returns the mode of retrieval of table data.
 SnmpVarBind[] getRow(int index)
          To get data for a table row,specified by its position in the table.
(package private)  SnmpVarBind[] getRow(int index, java.util.Vector data)
          Return the ith row
 java.lang.String[] getRow(java.lang.String tableOID, java.lang.String index)
          Returns the data for a row of the Table specified by the index .
(package private)  SnmpVarBind getRowCol(int rowIndex, int colIndex)
          Return the specified item
 int getRowCount()
          Returns the number of rows of data available in the SnmpTable.
(package private)  SnmpVarBind[] getRowFromArray(int index)
           
 java.lang.String getTableOID()
          To get table oid used with this SnmpTable instance.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          To get the value for the cell specified by the row and column index.
 boolean isCellEditable(int rowIndex, int columnIndex)
          To check if the cell at the specified index is editable or not.
 void refreshTable()
          Refreshes the table data.
 void removeSnmpTableListener(SnmpTableListener l)
          Remove a listener from the list that's notified each time a change in the SNMP Table occurs.
 void run()
          The run method does polling and updates of the table at specified polling itervals.
 void setCellValue(java.lang.String tableOID, java.lang.Object aValue, int rowIndex, int columnIndex)
          Sets the value for the cell specified by the row and column index.
 void setColumnsPolled(java.util.Vector index)
          Sets the columns that needs to be polled.
 void setDataType(int type)
          Set the type in which the data has to be returned when the table data is got using the getValueAt or getCellValue methods.By default these methods will return table data as String objects.To get the table data as SnmpVar or SnmpVarBind object, the respective constant can be set using setDataType() method.
 void setObjectIDList(java.lang.String[] s)
          Sets the column names of the table that needs to be polled.
(package private)  void setObjectIDListWoStart(java.lang.String[] oids)
           
 void setParams(java.lang.String host, java.lang.String mib, java.lang.String tableOID)
          To set multiple parameters like TargetHost,MibModule and TableOID
 void setPollInterval(int i)
          To set the polling interval in seconds.
 void setRetrievalMode(boolean mode)
          To set the mode of retrieval.
(package private)  void setSuperObjectIDList(java.lang.String[] s)
           
 void setTableOID(java.lang.String tableOID)
          Sets the table OID to be used with this SnmpTable instance.
 void setTableOIDWoStart(java.lang.String tableOID)
          To set the table OID without starting polling.
 void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
          Sets the value for the cell specified by the row and column index.
protected  void showErrorMessage(java.lang.String str)
           
 void startPollingTable()
          Method to start the polling of Table.This can be used after setting the table column oids using setObjectIDList.If the method setTableOID is used to set the oid of the table,this method need not be called explicitly as the setTableOID() method calls this method internally.
 void stopPollingTable()
          Method to stop the polling of Table.
 
Methods inherited from class com.adventnet.snmp.beans.SnmpTarget
addLogClient, addLogClient, addObjectID, addResultListener, addSnmpOID, addSnmpPropertyListener, addUserError, addV3HandShakeResultListener, enableDebugForPDU, genEvent, genTimeoutEvent, getAttemptComplete, getAttemptPartial, getAuthPassword, getAuthProtocol, getCommunity, getCompleteResponse, getContextID, getContextName, getDebug, getEngineID, getErrorCode, getErrorCodes, getErrorIndex, getErrorString, getExceptionCode, getExceptionCodes, getIgnoreSpecificControlCodes, getMaxNumRows, getMaxRepetitions, getMibModules, getMibOperations, getNonRepeaters, getObjectID, getObjectID, getObjectIDList, getPduErrorIndex, getPrincipal, getPrivPassword, getRetries, getSecurityLevel, getSecurityModel, getSendTimeoutEvents, getSnmpOID, getSnmpOIDList, getSnmpVariables, getSnmpVersion, getTargetHost, getTargetPort, getTimeout, getUserErrorCode, getUserErrorString, getV1TrapOids, getVarBindCount, getWriteCommunity, isInSubTree, isInSubTree, isSerialize, loadMibs, releaseResources, removeLogClient, removeResultListener, removeSnmpPropertyListener, removeV3HandShakeListener, setAttemptComplete, setAttemptPartial, setAuthPassword, setAuthProtocol, setClientID, setCommunity, setContextID, setContextName, setDebug, setEngineID, setIgnoreSpecificControlCodes, setMaxNumRows, setMaxRepetitions, setMibModules, setNonRepeaters, setObjectID, setObjectID, setParams, setParams, setPrincipal, setPrivPassword, setRetries, setSecurityLevel, setSecurityModel, setSendTimeoutEvents, setSnmpOID, setSnmpOIDList, setSnmpVersion, setTargetHost, setTargetPort, setTimeout, setVarBindCount, setWriteCommunity, snmpGet, snmpGet, snmpGetAllList, snmpGetAllVariableBindings, snmpGetAllVariables, snmpGetBulkList, snmpGetBulkVariableBindings, snmpGetBulkVariables, snmpGetList, snmpGetList, snmpGetNext, snmpGetNext, snmpGetNextList, snmpGetNextList, snmpGetNextVariable, snmpGetNextVariableBinding, snmpGetNextVariableBindings, snmpGetNextVariables, snmpGetVariable, snmpGetVariableBinding, snmpGetVariableBindings, snmpGetVariables, snmpSendInformAcknowledgement, snmpSendInformRequest, snmpSendInformRequest, snmpSendNotification, snmpSendNotification, snmpSendTrap, snmpSendTrap, snmpSet, snmpSet, snmpSetList, snmpSetVariable, snmpSetVariableList, snmpSetVariables, updateMibs, vetoableChange
 
Methods inherited from class com.adventnet.snmp.beans.SnmpServer
assignLogger, async_create_v3_tables, create_v3_tables, genEvent, getCharacterEncoding, getCompleteResponse, getGROUPSNMPResponse, getHostAddress, getLocalAddresses, getMibPath, getOverwriteCMI, getPacketBufferSize, getPdu, getSecLevelForTimeSync, getSecurityProvider, getSecurityTable, getSerializedMibFileName, getSimpleDateFormat, getSnmpEngineID, getSnmpEngineTable, getSNMPResponse, getSNMPResponse, getSNMPResponse, getTimeoutInMilliSec, getTimeToWait, getUSMTable, getV3ConfigTable, initJdbcParams, initSecurityProvider, initSnmpStore, isBroadcastFeatureEnable, isLoadFromCompiledMibs, isLoadFromSerializedMibs, isLoadMibsFromDatabase, isOverwriteCMI, isOverwriteMibsInDatabase, isReadDesc, isSendPDUByGroup, isSerializeMibs, isSetAutoInformResponse, isSupportedSecurityModel, isV3DatabaseFlag, isValidateUser, logErrorMessage, logInfoMessage, manage_v3_tables, managing_v3_tables, sendSNMPRequest, sendSNMPRequest, sendSNMPRequest, setAutoInformResponse, setBroadcastFeatureEnable, setCharacterEncoding, setErrorMessage, setLoadFromCompiledMibs, setLoadFromSerializedMibs, setLoadMibsFromDatabase, setMibOperations, setMibPath, setOverwriteCMI, setOverwriteMibsInDatabase, setPacketBufferSize, setPduParams, setReadDesc, setReceiveBufferSize, setSecLevelForTimeSync, setSendPDUByGroup, setSerializedMibFileName, setSerializeMibs, setSimpleDateFormat, setSnmpEngineID, setTimeoutInMilliSec, setTimeToWait, setV3ConfigTable, setV3DatabaseFlag, updateEntry, validateUser
 
Methods inherited from class java.lang.Object
, clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isEntryStatus

boolean isEntryStatus

tableData

java.util.Vector tableData

thisThread

transient volatile java.lang.Thread thisThread

pollInterval

int pollInterval

performSets

boolean performSets

tableListeners

java.util.Vector tableListeners

tableOID

SnmpOID tableOID

DATA_TYPE

int DATA_TYPE

RETRIEVAL_MODE

boolean RETRIEVAL_MODE

columnsPolled

java.util.Vector columnsPolled

colOIDs

java.util.Vector colOIDs

isNotInSubTree

boolean isNotInSubTree

holesCount

int holesCount

holes

int[] holes

holesGot

boolean holesGot

augmentedTableoid

java.lang.String augmentedTableoid

isAugmentedTable

boolean isAugmentedTable

rootoid

int[] rootoid

ADDandDELcol

int ADDandDELcol

num_col

int num_col

shifting

boolean shifting

columns

java.util.Vector columns

nodes

java.util.Vector nodes

columnNames

java.lang.String[] columnNames

columnClass

java.lang.Class[] columnClass

editable

boolean[] editable

cnam

java.util.Vector cnam

externalIndices

java.util.Vector externalIndices

syntax

java.util.Vector syntax

noAccessIndex

java.util.Vector noAccessIndex

rowtry

int rowtry

STRING_DATA

public static final int STRING_DATA
Constant to specify the format in which the data has to be returned.String is the default.

SNMP_VARIABLE_DATA

public static final int SNMP_VARIABLE_DATA
Constant to specify the format in which the data has to be returned.

SNMP_VARIABLE_BINDING_DATA

public static final int SNMP_VARIABLE_BINDING_DATA
Constant to specify the format in which the data has to be returned.
Constructor Detail

SnmpTable

public SnmpTable(SnmpSession ses,
                 MibOperations mib)
This constructor is used to create an SnmpTable instance with a specified SnmpSession and MibOperations. Using this constructor the user can decide which SnmpSession and MibOperations instance should be used by SnmpTable.
Parameters:
ses - Instance of SnmpSession but not null and also the created SnmpSession should be opened before using in this constructor.
mib - Instance of MibOperations

SnmpTable

public SnmpTable()
Use this constructor for applications.

SnmpTable

public SnmpTable(int protocol,
                 ProtocolOptions options)
Use this constructor for applications which uses protocols other than UDP/IP.

SnmpTable

public SnmpTable(int port,
                 java.lang.String session)
Use this constructor for creating a new session for this application. If the session name is same the tables will share the same session. If the port is 0 it will use the available free port.

SnmpTable

public SnmpTable(java.applet.Applet applet)
Use this constructor for applets.
Method Detail

setParams

public void setParams(java.lang.String host,
                      java.lang.String mib,
                      java.lang.String tableOID)
To set multiple parameters like TargetHost,MibModule and TableOID
Parameters:
host - target host
mib - mib file
tableOID - OID of the table

getRowCount

public int getRowCount()
Returns the number of rows of data available in the SnmpTable.
Returns:
number of rows in the Table.

getColumnCount

public int getColumnCount()
Returns the number of columns in the table corresponding to the table OID already set.
Returns:
the number of columns available in the SnmpTable.

getColumnName

public java.lang.String getColumnName(int columnIndex)
Returns the name of the column specified by the column index.
Parameters:
columnIndex - index of the column in the table.
Returns:
the name of the column.

getColumnClass

public java.lang.Class getColumnClass(int columnIndex)
Returns the class to be used as renderer and editor for the column.
Parameters:
columnIndex - index of the column in the table
Returns:
the Class to be used as renderer and editor for the column and null if the columnIndex is invalid.

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
To check if the cell at the specified index is editable or not.
Parameters:
rowIndex - index of the row to which the cell belongs
columnIndex - index of the column to which the cell belongs
Returns:
true if the cell is editable and false otherwise.

getCellValue

public java.lang.Object getCellValue(java.lang.String tableOID,
                                     int rowIndex,
                                     int columnIndex)
To get the value for the cell specified by the row and column index. The row and column index represent the position of the row and column in the table,both starting with zero. TableOID need not be set separately.If the object to be returned is required as a SnmpVar or SnmpVarBind object,then it can be set using setDataType() method. By default a String object will be returned. The following errorcodes can be set MIB_NODE_UNAVAIL,INVALID_TABLE_OID
Parameters:
tableOID - OID of the table to which the cell belongs.
rowIndex - position of the row whose value is to be looked up.
columnIndex - position of the column whose value is to be looked up.
Returns:
the value for the cell as a String data.Null if tableOID is invalid.
See Also:
ErrorMessages, SnmpTarget.getErrorString(), SnmpTarget.getErrorCode(), setDataType(int type), setCellValue(String tableOID,Object aValue, int rowIndex,int columnIndex)

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
To get the value for the cell specified by the row and column index. The row and column index represent the position of the row and column in the table,both starting with zero. TableOID should be set seperately using setTableOID(). If the object to be returned is required as an object of SnmpVar or SnmpVarBind, then it can be set using setDataType() method.By Default String data will be returned.
Parameters:
rowIndex - position of the row whose value is to be looked up.
columnIndex - position of the column whose value is to be looked up.
Returns:
the value for the cell as a String data.Null if TableOID is invalid.
See Also:
setDataType(int type), setValueAt(Object aValue, int rowIndex,int columnIndex)

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
Sets the value for the cell specified by the row and column index. The row and column index represent the position of the row and column in the table,both starting with zero. TableOID should be set using setTableOID(). The new value can be a String or SnmpVar or SnmpVarBind object.

The following errorCodes can be set SNMP_NOT_INIT, INVALID_VERSION, OID_NOT_SPECIFIED, REQ_TIMEDOUT, EMPTY_VAR_BIND, IP_ADDR_NOT_SPECIFIED, SESSION_REMOTE_HOST_UNKNOWN, SECURITYEXP_CONNECTING_REMOTE_HOST, UNKNOWN_ERR, SNMP errors defined in ErrorMessages. INVALID_CONTEXT_NAME ,INVALID_CONTEXT_ID.

Parameters:
aValue - the new value that needs to be set.
rowIndex - position of the row whose value is to be changed.
columnIndex - position of the column whose value is to be changed.
See Also:
getValueAt(int rowIndex, int columnIndex), ErrorMessages, SnmpTarget.getErrorCode(), SnmpTarget.getErrorString()

showErrorMessage

protected void showErrorMessage(java.lang.String str)

setCellValue

public void setCellValue(java.lang.String tableOID,
                         java.lang.Object aValue,
                         int rowIndex,
                         int columnIndex)
Sets the value for the cell specified by the row and column index. The row and column index represent the position of the row and column in the table,both starting with zero. If this method is used to set the value,then the Table OID need not be set seperately using setTableOID() method. The new value can be a String or SnmpVar or SnmpVarBind object.

The following errorCodes can be set SNMP_NOT_INIT, INVALID_VERSION, OID_NOT_SPECIFIED, REQ_TIMEDOUT, EMPTY_VAR_BIND, IP_ADDR_NOT_SPECIFIED, SESSION_REMOTE_HOST_UNKNOWN, SECURITYEXP_CONNECTING_REMOTE_HOST, UNKNOWN_ERR, SNMP errors defined in ErrorMessages. INVALID_CONTEXT_NAME ,INVALID_CONTEXT_ID.

Parameters:
tableOID - OID of the table to which the cell belongs.
aValue - the new value that needs to be set.
rowIndex - position of the row whose value is to be changed.
columnIndex - position of the column whose value is to be changed.
See Also:
getCellValue(String tableOID, int rowIndex, int columnIndex), ErrorMessages, SnmpTarget.getErrorCode(), SnmpTarget.getErrorString()

addSnmpTableListener

public void addSnmpTableListener(SnmpTableListener l)
Adds a SnmpTableListener instance to the listener's list.Whenever a change in SnmpTable occurs all the registered listeners will be notified.
Parameters:
l - an instance of SnmpTableListener to be added.A instance of a class implementing SnmpTableListener interface.
See Also:
SnmpTableListener

removeSnmpTableListener

public void removeSnmpTableListener(SnmpTableListener l)
Remove a listener from the list that's notified each time a change in the SNMP Table occurs.
Parameters:
l - an instance of SnmpTableListener which needs to be removed from the list.
See Also:
SnmpTableListener

getTableOID

public java.lang.String getTableOID()
To get table oid used with this SnmpTable instance. MIB containing this table must be loaded in this VM.
Returns:
the Table OID as a String value.

setTableOIDWoStart

public void setTableOIDWoStart(java.lang.String tableOID)
                        throws