HOME

com.ireasoning.protocol.snmp
Class SnmpTable

java.lang.Object
  extended bycom.ireasoning.protocol.snmp.SnmpTable
All Implemented Interfaces:
SnmpTableMBean

public abstract class SnmpTable
extends Object
implements SnmpTableMBean

This class is the base class of Snmp Table classes, such as IfTable in RFC1213.

Note: It's only intended to be used to represent MIB table on the agent side. It's not suitable for SNMP manager applications.


Field Summary
protected  long _lastUpdateTime
          Last update time
protected  Vector _rows
          Rows contained in this table.
protected  OIDTreeNode _tableNode
          The OIDTreeNode representation of this table node
protected  long _updateInterval
          The interval for table update.
 
Constructor Summary
SnmpTable(OIDTreeNode root, String oid)
          Constructor
 
Method Summary
 ArrayList addRow(Collection varbinds)
          Adds a new row.
 ArrayList addRow(SnmpTableEntry entry)
          Adds a new row.
 ArrayList addRow(SnmpTableEntry entry, String suffix)
          Adds a new row.
 void deleteAllRows()
          Deletes all rows in this table
 ArrayList deleteRow(int index)
           
 ArrayList deleteRow(SnmpTableEntry entry)
          Deletes the specified entry
 ArrayList deleteRow(String indexSuffix)
          Removes the row with the passed indexSuffix
 int getColumnCount()
          Returns the number of columns in this table
 ArrayList getColumnOIDs()
          Returns the OIDs of table column in an arraylist object
 String getIndexSuffix(int index)
          Returns the index suffix of row at specified index
 SnmpTableEntry getNextOID(SnmpOID oid)
          Returns null if next OID is out of this table's subtree; Its next oid is in this subtree, it returns an SnmpTableEntry object which contains the next OID (SnmpTableEntry.setOID method must be called, otherwise it may cause exceptions), caller will use SnmpTableEntry.getOID() to retrieve that OID value.
 SnmpTableEntry getNextOID(SnmpOID oid, SnmpPdu pdu)
          Returns null if next OID is out of this table's subtree; If the next oid is in this subtree, it returns an SnmpTableEntry object which contains the next OID (SnmpTableEntry.setOID method must be called, otherwise it may cause exceptions), caller will use SnmpTableEntry.getOID() to retrieve that OID value.
 SnmpTableEntry getOID(SnmpOID oid)
          Returns null if passed oid doesn't exist in this subtree; a non-null object if this oid exists in this subtree.
 SnmpTableEntry getOID(SnmpOID oid, SnmpPdu pdu)
          Returns null if passed oid doesn't exist in this subtree; a non-null object if this oid exists in this subtree.
 SnmpTableEntry getRow(int index)
          Returns row at specified index
 SnmpTableEntry getRow(String indexSuffix)
          Returns row whose index suffix is equal to the passed indexSuffix
 int getRowCount()
          Returns the number of rows in this table
 Vector getRows()
          Returns all rows in a Vector object.
 OIDTreeNode getTableNode()
          Returns the table node
 long getUpdateInterval()
          Returns the interval to call update() method, in milliseconds
 boolean isProcessSnmpRequestDirectly()
          Returns if this table processes snmp requests directly or not
 boolean isTimeToUpdate()
          Tests if it's time to call update() method
abstract  SnmpTableEntry newEntryInstance()
          Returns a new instance of SnmpTableEntry object
 void postAddRow(SnmpTableEntry entry)
          Gets called after this row is added
 void postDeleteRow(SnmpTableEntry entry)
          Gets called after this row is deleted
 void postSetValue(SnmpTableEntry entry, SnmpVarBind newValue, Collection varbinds)
          Deprecated, use postSetValue instead
 void postSetValue(SnmpTableEntry entry, SnmpVarBind newValue, SnmpPdu pdu)
          Gets called after setting new value to the passed entry object.
 boolean preAddRow(SnmpTableEntry entry)
          Gets called before this row is added.
 boolean preDeleteRow(SnmpTableEntry entry)
          Gets called before this row is deleted.
 boolean preSetValue(SnmpTableEntry entry, SnmpVarBind newValue, Collection varbinds)
          Deprecated, use preSetValue instead
 void preSetValue(SnmpTableEntry entry, SnmpVarBind newValue, SnmpPdu pdu)
          Gets called before setting new value to the passed entry object when agent receives an SNMP SET request.
 void setLastUpdateTime(long l)
          Sets the last update time
 void setProcessSnmpRequestDirectly(boolean b)
          If passed flag is true, SnmpBaseAgent class will relay SNMP request to this table object, and respective getter/setter methods of this table object will be invoked to process the requests falling into the subtree of this table
 void setTableNode(OIDTreeNode n)
          Sets table node
 void setUpdateInterval(long interval)
          Sets the interval to call update() method
 void update()
          Deprecated.
 void update(SnmpPdu pdu, SnmpOID currentOID)
          This method will be called when agent gets new requests and update interval has already passed (similar to the cache functionalities.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_tableNode

protected OIDTreeNode _tableNode
The OIDTreeNode representation of this table node


_rows

protected Vector _rows
Rows contained in this table. Its contains SnmpTableEntry objects


_updateInterval

protected long _updateInterval
The interval for table update. Default value is -1, which means update() method will never get called


_lastUpdateTime

protected long _lastUpdateTime
Last update time

See Also:
update(SnmpPdu pdu, SnmpOID currentOID)
Constructor Detail

SnmpTable

public SnmpTable(OIDTreeNode root,
                 String oid)
Constructor

Parameters:
root - the root node of MIB tree
oid - the OID value of this table node
Method Detail

getTableNode

public OIDTreeNode getTableNode()
Returns the table node


setTableNode

public void setTableNode(OIDTreeNode n)
Sets table node

Parameters:
n - the new table node

newEntryInstance

public abstract SnmpTableEntry newEntryInstance()
Returns a new instance of SnmpTableEntry object


addRow

public ArrayList addRow(SnmpTableEntry entry,
                        String suffix)
Description copied from interface: SnmpTableMBean
Adds a new row.

Note: It's not the preferred method for adding rows in most cases. addRow(SnmpTableEntry entry) method should be used instead.

Specified by:
addRow in interface SnmpTableMBean
Parameters:
entry - the new row to be added
suffix - the index suffix
Returns:
an arraylist of newly added OIDTreeNode objects. If nothing added, an empty arraylist is returned.
See Also:
SnmpTableMBean.addRow(SnmpTableEntry)

addRow

public ArrayList addRow(SnmpTableEntry entry)
Description copied from interface: SnmpTableMBean
Adds a new row.

Specified by:
addRow in interface SnmpTableMBean
Parameters:
entry - the new row to be added
Returns:
an arraylist of newly added OIDTreeNode objects. If nothing added, an empty arraylist is returned.

addRow

public ArrayList addRow(Collection varbinds)
Description copied from interface: SnmpTableMBean
Adds a new row.

Specified by:
addRow in interface SnmpTableMBean
Parameters:
varbinds - an array of SnmpVarBind objects, which contain the name/value of each column.
Returns:
an ArrayList of newly added OIDTreeNode objects. If nothing added, an empty arraylist is returned.

deleteRow

public ArrayList deleteRow(int index)

deleteRow

public ArrayList deleteRow(String indexSuffix)
Description copied from interface: SnmpTableMBean
Removes the row with the passed indexSuffix

Specified by:
deleteRow in interface SnmpTableMBean
Parameters:
indexSuffix - the index suffix of the row to be removed
Returns:
An ArrayList of SnmpOID objects which are the deleted nodes' SnmpOID. An empty ArrayList object is returned if nothing is deleted.

deleteRow

public ArrayList deleteRow(SnmpTableEntry entry)
Description copied from interface: SnmpTableMBean
Deletes the specified entry

Specified by:
deleteRow in interface SnmpTableMBean
Returns:
A collection of SnmpOID objects which are the deleted nodes' SnmpOID

deleteAllRows

public void deleteAllRows()
Deletes all rows in this table


getIndexSuffix

public String getIndexSuffix(int index)
Description copied from interface: SnmpTableMBean
Returns the index suffix of row at specified index

Specified by:
getIndexSuffix in interface SnmpTableMBean
Parameters:
index - the row index

getRowCount

public int getRowCount()
Description copied from interface: SnmpTableMBean
Returns the number of rows in this table

Specified by:
getRowCount in interface SnmpTableMBean

getColumnCount

public int getColumnCount()
Description copied from interface: SnmpTableMBean
Returns the number of columns in this table

Specified by:
getColumnCount in interface SnmpTableMBean

getRows

public Vector getRows()
Description copied from interface: SnmpTableMBean
Returns all rows in a Vector object. Each element in the vector is a SnmpTableEntry object.

Specified by:
getRows in interface SnmpTableMBean

getRow

public SnmpTableEntry getRow(int index)
Description copied from interface: SnmpTableMBean
Returns row at specified index

Specified by:
getRow in interface SnmpTableMBean
Parameters:
index - the row index

getRow

public SnmpTableEntry getRow(String indexSuffix)
Description copied from interface: SnmpTableMBean
Returns row whose index suffix is equal to the passed indexSuffix

Specified by:
getRow in interface SnmpTableMBean
Returns:
the SnmpTableEntry object. Or null if nothing found.

isTimeToUpdate

public boolean isTimeToUpdate()
Tests if it's time to call update() method

See Also:
setUpdateInterval(long), update(SnmpPdu pdu, SnmpOID currentOID)

update

public void update(SnmpPdu pdu,
                   SnmpOID currentOID)
This method will be called when agent gets new requests and update interval has already passed (similar to the cache functionalities. When cache's item is stale, it needs update). It'll take effect after you set update interval. If you need to make changes to the table upon requests, you can override this method. In this method, you can add, modify or delete rows.

Parameters:
pdu - received pdu
currentOID - the oid being processed

update

public void update()
Deprecated. Use update(SnmpPdu pdu, SnmpOID currentOID) instead.

See Also:
update(SnmpPdu pdu, SnmpOID currentOID)

setUpdateInterval

public void setUpdateInterval(long interval)
Sets the interval to call update() method

Parameters:
interval - time interval, in milliseconds
See Also:
update(SnmpPdu pdu, SnmpOID currentOID)

getUpdateInterval

public long getUpdateInterval()
Returns the interval to call update() method, in milliseconds

See Also:
update(SnmpPdu pdu, SnmpOID currentOID)

setLastUpdateTime

public void setLastUpdateTime(long l)
Sets the last update time


preAddRow

public boolean preAddRow(SnmpTableEntry entry)
Description copied from interface: SnmpTableMBean
Gets called before this row is added. Subclass can override this method if it wants to do some checkings before adding row.

Specified by:
preAddRow in interface SnmpTableMBean
Parameters:
entry - an instance of SnmpTableEntry or its sub class
Returns:
return true to add row; return false not to add row

postAddRow

public void postAddRow(SnmpTableEntry entry)
Description copied from interface: SnmpTableMBean
Gets called after this row is added

Specified by:
postAddRow in interface SnmpTableMBean
Parameters:
entry - an instance of SnmpTableEntry or its sub class

preDeleteRow

public boolean preDeleteRow(SnmpTableEntry entry)
Description copied from interface: SnmpTableMBean
Gets called before this row is deleted. Subclass can override this method if it wants to do some checkings before deleting row.

Specified by:
preDeleteRow in interface SnmpTableMBean
Parameters:
entry - an instance of SnmpTableEntry or its sub class
Returns:
true if continue to delete row, false so this row won't be deleted.

postDeleteRow

public void postDeleteRow(SnmpTableEntry entry)
Description copied from interface: SnmpTableMBean
Gets called after this row is deleted

Specified by:
postDeleteRow in interface SnmpTableMBean
Parameters:
entry - an instance of SnmpTableEntry or its sub class

preSetValue

public void preSetValue(SnmpTableEntry entry,
                        SnmpVarBind newValue,
                        SnmpPdu pdu)
Description copied from interface: SnmpTableMBean
Gets called before setting new value to the passed entry object when agent receives an SNMP SET request.

Because SNMP SET operation is atomic, you may need to override this method in your table classes which accept SET operations, and check the validity of passed newValue and the pdu object. If the value is not acceptable, SnmpException needs to be thrown, so this SET operation fails and proper error code is returned to SNMP manager.

Note: SNMP version information of the received packet can be retrieved by calling pdu.getVersion()

Specified by:
preSetValue in interface SnmpTableMBean
Parameters:
entry - SnmpTableEntry object for the row affected. It is null if this table is self-managed or this SET request is for creating a new row. For dynamic row creation, the passed entry is null, overriding preAddRow(SnmpTableEntry entry) method to get its value
newValue - the new value which is being processed
pdu - PDU object received
Returns:
true if no error; otherwise it indicates an unknown error

preSetValue

public boolean preSetValue(SnmpTableEntry entry,
                           SnmpVarBind newValue,
                           Collection varbinds)
Deprecated, use preSetValue instead

Specified by:
preSetValue in interface SnmpTableMBean

postSetValue

public void postSetValue(SnmpTableEntry entry,
                         SnmpVarBind newValue,
                         SnmpPdu pdu)
Description copied from interface: SnmpTableMBean
Gets called after setting new value to the passed entry object.

Specified by:
postSetValue in interface SnmpTableMBean
Parameters:
entry - SnmpTableEntry object for the row affected. It is null if this table is self-managed or this SET request is for creating a new row. For dynamic row creation, the passed entry is null, overriding postAddRow(SnmpTableEntry entry) method to get its value
newValue - the new value which is being processed
pdu - PDU object received

postSetValue

public void postSetValue(SnmpTableEntry entry,
                         SnmpVarBind newValue,
                         Collection varbinds)
Deprecated, use postSetValue instead

Specified by:
postSetValue in interface SnmpTableMBean

setProcessSnmpRequestDirectly

public void setProcessSnmpRequestDirectly(boolean b)
If passed flag is true, SnmpBaseAgent class will relay SNMP request to this table object, and respective getter/setter methods of this table object will be invoked to process the requests falling into the subtree of this table

The default value is false. Setting it to true is NOT recommended for most tables. It's appropriate when table takes too much memory space if using its table entry class.

if setProcessSnmpRequestDirectly(true), then these two methods must be implemented: getOID(SnmpOID oid) and getNextOID(SnmpOID oid)


isProcessSnmpRequestDirectly

public boolean isProcessSnmpRequestDirectly()
Returns if this table processes snmp requests directly or not


getNextOID

public SnmpTableEntry getNextOID(SnmpOID oid,
                                 SnmpPdu pdu)
Description copied from interface: SnmpTableMBean
Returns null if next OID is out of this table's subtree; If the next oid is in this subtree, it returns an SnmpTableEntry object which contains the next OID (SnmpTableEntry.setOID method must be called, otherwise it may cause exceptions), caller will use SnmpTableEntry.getOID() to retrieve that OID value. The returned SnmpTableEntry object will be passed to corresponding getter/setter methods. If it's not feasible to create a meaningful SnmpTableEntry, you can just create a empty SnmpTableEntry object with the next oid.

If setProcessSnmpRequestDirectly(true) is invoked for the table, this method is required, otherwise this method won't be used.

Specified by:
getNextOID in interface SnmpTableMBean
Parameters:
oid - oid to be processed
pdu - PDU object received

getNextOID

public SnmpTableEntry getNextOID(SnmpOID oid)
Description copied from interface: SnmpTableMBean
Returns null if next OID is out of this table's subtree; Its next oid is in this subtree, it returns an SnmpTableEntry object which contains the next OID (SnmpTableEntry.setOID method must be called, otherwise it may cause exceptions), caller will use SnmpTableEntry.getOID() to retrieve that OID value. The returned SnmpTableEntry object will be passed to corresponding getter/setter methods. If it's not feasible to create a meaningful SnmpTableEntry, you can just create a empty SnmpTableEntry object with the next oid.

If setProcessSnmpRequestDirectly(true) is invoked for the table, this method is required, otherwise this method won't be used.

Specified by:
getNextOID in interface SnmpTableMBean

getOID

public SnmpTableEntry getOID(SnmpOID oid,
                             SnmpPdu pdu)
Description copied from interface: SnmpTableMBean
Returns null if passed oid doesn't exist in this subtree; a non-null object if this oid exists in this subtree.

If setProcessSnmpRequestDirectly(true) is invoked for the table, this method is required, otherwise this method won't be used.

Specified by:
getOID in interface SnmpTableMBean
Parameters:
oid - oid to be processed
pdu - PDU object received

getOID

public SnmpTableEntry getOID(SnmpOID oid)
Description copied from interface: SnmpTableMBean
Returns null if passed oid doesn't exist in this subtree; a non-null object if this oid exists in this subtree.

If setProcessSnmpRequestDirectly(true) is invoked for the table, this method is required, otherwise this method won't be used.

Specified by:
getOID in interface SnmpTableMBean

getColumnOIDs

public ArrayList getColumnOIDs()
Returns the OIDs of table column in an arraylist object


HOME

Copyright © 2002 iReasoning Inc. All Rights Reserved.