public class DefaultMOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>> extends Object implements MOTable<R,C,M>, MOScope, SerializableManagedObject
DefaultMOTable class is the default implementation of the
MOTable class. For most use cases, it is not necessary to customize
this class through deriving your own sub-class. Instead, using a different
MOTableModel as table data provider is sufficient.
The default table model can be used to hold the data of a SNMP conceptual
table as real tabular data. If you want to implement a virtual table, you
will have to directly implement the interfaces MOTableModel or
MOMutableTableModel to access the data based on the actual view.
| Modifier and Type | Class and Description |
|---|---|
static class |
DefaultMOTable.ChangeSet |
| Modifier and Type | Field and Description |
|---|---|
protected Vector<MOChangeListener> |
moChangeListeners |
protected M |
model |
protected Vector<MOTableRowListener<R>> |
moTableRowListeners |
protected WeakHashMap<Request,Map<org.snmp4j.smi.OID,R>> |
newRows |
protected WeakHashMap<Request,Map<org.snmp4j.smi.OID,DefaultMOTable.ChangeSet>> |
pendingChanges |
| Constructor and Description |
|---|
DefaultMOTable(org.snmp4j.smi.OID oid,
MOTableIndex indexDef,
C[] columns) |
DefaultMOTable(org.snmp4j.smi.OID oid,
MOTableIndex indexDef,
C[] columns,
M model)
Creates a new SNMP table with the specified "Entry" OID, INDEX, columns,
and
MOTableModel. |
| Modifier and Type | Method and Description |
|---|---|
void |
addMOChangeListener(MOChangeListener l)
Adds a
MOChangeListener that needs to be informed about
state changes of this table. |
void |
addMOTableRowListener(MOTableRowListener<R> l)
Adds a
MOTableRowListener listener that needs to be informed
about row changes (creation, addition, removal). |
R |
addNewRow(org.snmp4j.smi.OID index,
org.snmp4j.smi.Variable[] initialValues)
Creates a new row for this table with the supplied index and initial
values and then immediately calls
MOTable.addRow(MOTableRow). |
protected DefaultMOTable.ChangeSet |
addPendingChanges(SubRequest subRequest,
MOTableRow row,
boolean newRow) |
boolean |
addRow(R row)
Adds the supplied row to the underlying table model and fires the
appropriate
MOTableRowEvent. |
void |
cleanup(SubRequest request)
Cleansup a (sub)request and frees all resources locked during
the preparation phase.
|
void |
commit(SubRequest request)
Commits a previously prepared SET (sub)request.
|
boolean |
covers(org.snmp4j.smi.OID oid)
Checks if this scope covers the supplied OID.
|
R |
createRow(org.snmp4j.smi.OID index)
Creates a new row for this table with the supplied index and
default values.
|
R |
createRow(org.snmp4j.smi.OID index,
org.snmp4j.smi.Variable[] initialValues)
Creates a new row for this table with the supplied index and initial
values.
|
org.snmp4j.smi.OID |
find(MOScope range)
Finds the object identifier of the first object instance in the specified
range.
|
protected MOTableCellInfo |
findCell(MOScope range,
SubRequest request) |
protected void |
fireAfterMOChange(MOChangeEvent changeEvent) |
protected void |
fireAfterPrepareMOChange(MOChangeEvent changeEvent) |
protected void |
fireBeforeMOChange(MOChangeEvent changeEvent) |
protected void |
fireBeforePrepareMOChange(MOChangeEvent changeEvent) |
protected void |
fireRowChanged(MOTableRowEvent<R> event) |
void |
get(SubRequest request)
Processes a GET request and return the result in the supplied sub-request.
|
MOTableCellInfo |
getCellInfo(org.snmp4j.smi.OID oid)
Returns a
MOTableCellInfo instance for the supplied
cell OID. |
org.snmp4j.smi.OID |
getCellOID(org.snmp4j.smi.OID index,
int col) |
protected int |
getChangesFromRequest(org.snmp4j.smi.OID index,
MOTableRow row,
SubRequest request,
org.snmp4j.smi.Variable[] values,
boolean setDefaultValues,
boolean newRow) |
C |
getColumn(int index)
Gets the column definition for the specified column.
|
int |
getColumnCount()
Returns the number of columns in this table.
|
int |
getColumnIndex(int id)
Returns the zero based column index for the specified column
sub-identifier.
|
C[] |
getColumns()
Gets the column definitions for this table.
|
org.snmp4j.smi.Variable[] |
getDefaultValues()
Returns an array of variables where each variable corresponds to the
column with the same index.
|
org.snmp4j.smi.OID |
getID()
Gets the unique object ID of the managed object.
|
MOTableIndex |
getIndexDef()
Gets the index definition of this table.
|
org.snmp4j.smi.OID |
getIndexPart(org.snmp4j.smi.OID anyOID)
Returns the index part of a column instance identifier of this table.
|
org.snmp4j.smi.OID |
getLowerBound()
Gets the lower bound OID of the scope.
|
M |
getModel()
Gets the table model of this table.
|
protected Map<org.snmp4j.smi.OID,R> |
getNewRows(Request key) |
org.snmp4j.smi.OID |
getOID()
Returns the OID of the table entry.
|
protected DefaultMOTable.ChangeSet |
getPendingChangeSet(SubRequest subRequest,
org.snmp4j.smi.OID index) |
protected org.snmp4j.smi.Variable[] |
getPersistentValues(MOTableRow row)
Gets the values of a row that need to be made persistent on behalf of
a
save(MOOutput output) call. |
MOScope |
getScope()
Returns the scope of object identifiers this managed object is managing.
|
org.snmp4j.smi.OID |
getUpperBound()
Gets the upper bound OID of the scope.
|
protected org.snmp4j.smi.Variable |
getValue(MOTableRow row,
int col,
SubRequest req) |
org.snmp4j.smi.Variable |
getValue(org.snmp4j.smi.OID cellOID)
Gets the value of the cell instance with the specified instance OID.
|
org.snmp4j.smi.Variable |
getValue(org.snmp4j.smi.OID index,
int col)
Gets the value of the cell instance in the specified column and row.
|
org.snmp4j.smi.Variable |
getValue(org.snmp4j.smi.OID index,
int col,
SubRequest req) |
protected boolean |
hasNewRows(Request key) |
protected boolean |
isChangeSetComplete(SubRequest subRequest,
org.snmp4j.smi.OID index,
int column) |
boolean |
isCovered(MOScope other)
Checks whether the supplied scope is covered by this scope.
|
boolean |
isLowerIncluded()
Indicates whether the lower bound OID is included in the scope or not.
|
boolean |
isOverlapping(MOScope other)
Checks whether the supplied scope overlap with this one, thus sharing at
least one OID with the supplied one.
|
boolean |
isUpperIncluded()
Indicates whether the upper bound OID is included in the scope or not.
|
boolean |
isVolatile()
Tests if this instance of a SerializableManagedObject should be
serialized or deserialized through persistent storage
load or save operation.
|
void |
load(MOInput input)
Loads the content of the managed object from the specified input (stream).
|
boolean |
next(SubRequest request)
Finds the successor instance for the object instance ID (OID) given
by the supplied sub-request and returns it within the supplied sub-request
object.
|
void |
prepare(SubRequest request)
Prepares a SET (sub)request.
|
int |
removeAll()
Removes all rows from this table.
|
void |
removeMOChangeListener(MOChangeListener l)
Removes a
MOChangeListener |
void |
removeMOTableRowListener(MOTableRowListener<R> l)
Removes
MOTableRowListener instance. |
R |
removeRow(org.snmp4j.smi.OID index)
Removes the row with the specified index and returns it if the operation
was successful.
|
void |
save(MOOutput output)
Saves the (non-volatile) content of this managed object to the specified
output (stream).
|
void |
setModel(M model) |
boolean |
setValue(org.snmp4j.smi.VariableBinding newValueAndInstancceOID)
Sets the value of a particular MIB object instance managed by
this
ManagedObject. |
void |
setVolatile(boolean isVolatile) |
String |
toString() |
void |
undo(SubRequest request)
Compensates (undo) a (sub)request when a commit of another subrequest
failed with an error.
|
void |
update(MOScope updateScope)
Update the content of this table that is covered by the supplied
scope.
|
protected void |
update(MOScope range,
SubRequest request)
Update this table for the supplied search range and sub-request if it has
not yet been updated for that request.
|
protected M extends MOTableModel<R> model
protected WeakHashMap<Request,Map<org.snmp4j.smi.OID,R extends MOTableRow>> newRows
protected WeakHashMap<Request,Map<org.snmp4j.smi.OID,DefaultMOTable.ChangeSet>> pendingChanges
protected transient Vector<MOChangeListener> moChangeListeners
protected transient Vector<MOTableRowListener<R extends MOTableRow>> moTableRowListeners
public DefaultMOTable(org.snmp4j.smi.OID oid,
MOTableIndex indexDef,
C[] columns)
public DefaultMOTable(org.snmp4j.smi.OID oid,
MOTableIndex indexDef,
C[] columns,
M model)
MOTableModel.oid - the OID of the SNMP table's Entry object. If the table is ifTable
(1.3.6.1.2.1.2.2) then the OID to provide is 1.3.6.1.2.1.2.2.1
which is the ifEntry OID. By SMI rule, you can simply append ".1" to
the table OID.indexDef - the index definition of the table based on the INDEX clause of the
table MIB definition.columns - the column definitions which may also include non-accessible columns.model - the table model holding the table data.public MOTableCellInfo getCellInfo(org.snmp4j.smi.OID oid)
MOTableMOTableCellInfo instance for the supplied
cell OID. The returned object contains the index, column index, and
column ID of the specified cell, if available.getCellInfo in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>oid - cell instance OID.MOTableCellInfo instance with the index, column index
and column ID of the specified cell if available.public int getColumnIndex(int id)
MOTablegetColumnIndex in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>id - a column sub-identifier (normally one based) as defined in the MIB
specification.id. The column index
points into the column array returned by MOTable.getColumns().
A value less than zero indicates that such a column does not exists
currently but could be inserted at the (-n)-1 position
if n is the returned value.public C getColumn(int index)
MOTablegetColumn in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>index - the (zero-based) column index.MOColumn instance describing the attributes of requested
column.public int getColumnCount()
MOTablegetColumnCount in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>public R createRow(org.snmp4j.smi.OID index, org.snmp4j.smi.Variable[] initialValues)
MOMutableTableModel
instance or if one of the MOTableRowListener deny the row creation
attempt then null will be returned.createRow in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>index - the index OID of the new row.initialValues - the initial values that should be assigned to the new row. If the array
contains less values than this table has columns, default values will
be created for the missing columns.MOTableRow instance or null if
the row cannot be created.public R addNewRow(org.snmp4j.smi.OID index, org.snmp4j.smi.Variable[] initialValues)
MOTableMOTable.addRow(MOTableRow).
If one of the MOTableRowListener deny the row creation
attempt then null will be returned and MOTable.addRow(MOTableRow)
will not be called.
This method is the same as calling:
R newRow = createRow(index, initialValues);
if (newRow != null) {
addRow(newRow);
}
return newRow;
addNewRow in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>index - the index OID of the new row.initialValues - the initial values that should be assigned to the new row.MOTableRow instance or null if
the row cannot be created.public R createRow(org.snmp4j.smi.OID index)
MOTableMOTableRowListener
deny the row creation attempt then null will be returned.createRow in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>index - the index OID of the new row.MOTableRow instance or null if
the row cannot be created.public boolean addRow(R row)
MOTableRowEvent. Since this method is typically
called during the commit phase of a SET request that creates a table,
it should be avoided to return an error here. Instead, error checking
should be placed in the prepare(org.snmp4j.agent.request.SubRequest) method.addRow in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>row - the MOTableRow to add.true if the row has been added or false
if it could not be added.public R removeRow(org.snmp4j.smi.OID index)
MOTableremoveRow in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>index - the index OID of the row to remove.null if the row cannot be found or
cannot be removed.public int removeAll()
public void commit(SubRequest request)
ManagedObjectcommit in interface ManagedObjectrequest - the SubRequest to process.public final org.snmp4j.smi.OID getIndexPart(org.snmp4j.smi.OID anyOID)
MOTablegetIndexPart in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>anyOID - the OID of a column instance. The returned result is undefined, when
this OID is not a column instance OID.instanceIdentifier column instance OID.public org.snmp4j.smi.OID getCellOID(org.snmp4j.smi.OID index,
int col)
public org.snmp4j.smi.OID find(MOScope range)
MOTablefind in interface ManagedObjectfind in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>range - a MOScope specifying the search range.null if no such instance exists.protected MOTableCellInfo findCell(MOScope range, SubRequest request)
public MOScope getScope()
ManagedObjectgetScope in interface ManagedObjectMOScope that defines a range (possibly also a single
or none instance OID) of object IDs managed by this managed object.public org.snmp4j.smi.Variable getValue(org.snmp4j.smi.OID cellOID)
MOTablegetValue in interface ManagedObjectValueAccessgetValue in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>cellOID - the instance OID of the requested cell.null if such a cell does not
exist.public org.snmp4j.smi.Variable getValue(org.snmp4j.smi.OID index,
int col,
SubRequest req)
public org.snmp4j.smi.Variable getValue(org.snmp4j.smi.OID index,
int col)
MOTablegetValue in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>index - the row index of the cell.col - the column index of the cell.null if such a cell does not
exist.protected org.snmp4j.smi.Variable getValue(MOTableRow row, int col, SubRequest req)
public void update(MOScope updateScope)
This method is part of the UpdatableManagedObject interface.
Although the DefaultMOTable does not implement that interface,
subclasses of this class may do so easily by overriding this hook-up
method.
updateScope - the scope to update. If null the whole managed object is
updated.update(MOScope range, SubRequest request)protected void update(MOScope range, SubRequest request)
By default, the
update(MOScope updateScope) is being called on behalf of this
method call (which itself does not nothing by default). You may choose
either to implement the UpdatableManagedObject interface and
implement its interface in a subclass. Then it is recommended to overwrite
this method by an empty method. Otherwise, do not implement the
UpdatableManagedObject interface.
range - the search range.request - the sub-request triggered the update or null if that
request cannot be determined.public void get(SubRequest request)
ManagedObjectget in interface ManagedObjectrequest - the SubRequest to process.public boolean next(SubRequest request)
ManagedObjectnext in interface ManagedObjectrequest - the SubRequest to process.true if the search request found an appropriate instance,
false otherwise.public void prepare(SubRequest request)
ManagedObjectprepare in interface ManagedObjectrequest - the SubRequest to process.protected int getChangesFromRequest(org.snmp4j.smi.OID index,
MOTableRow row,
SubRequest request,
org.snmp4j.smi.Variable[] values,
boolean setDefaultValues,
boolean newRow)
protected boolean hasNewRows(Request key)
protected boolean isChangeSetComplete(SubRequest subRequest, org.snmp4j.smi.OID index, int column)
protected DefaultMOTable.ChangeSet addPendingChanges(SubRequest subRequest, MOTableRow row, boolean newRow)
protected DefaultMOTable.ChangeSet getPendingChangeSet(SubRequest subRequest, org.snmp4j.smi.OID index)
public void cleanup(SubRequest request)
ManagedObjectcleanup in interface ManagedObjectrequest - the SubRequest to process.public void undo(SubRequest request)
ManagedObjectundo in interface ManagedObjectrequest - the SubRequest to process.public org.snmp4j.smi.OID getOID()
MOTablegetOID in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>public void setModel(M model)
public void setVolatile(boolean isVolatile)
public M getModel()
MOTablegetModel in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>public C[] getColumns()
MOTablegetColumns in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>public MOTableIndex getIndexDef()
MOTablegetIndexDef in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>public boolean isVolatile()
SerializableManagedObjectisVolatile in interface SerializableManagedObjecttrue if SerializableManagedObject.load(org.snmp4j.agent.io.MOInput) and SerializableManagedObject.save(org.snmp4j.agent.io.MOOutput) should not be
called through a persistent storage operation and false
if these method should be called.public org.snmp4j.smi.OID getLowerBound()
MOScopeMOScope.isLowerIncluded().getLowerBound in interface MOScopepublic org.snmp4j.smi.OID getUpperBound()
MOScopeMOScope.isUpperIncluded().getUpperBound in interface MOScopepublic boolean isLowerIncluded()
MOScopeisLowerIncluded in interface MOScopetrue if the lower bound is included.public boolean isUpperIncluded()
MOScopeisUpperIncluded in interface MOScopetrue if the upper bound is included.public boolean isCovered(MOScope other)
MOScopepublic boolean isOverlapping(MOScope other)
MOScopeisOverlapping in interface MOScopeother - a MOScope.true if there exists at least one OID that is included in
both scopes.public void addMOChangeListener(MOChangeListener l)
MOTableMOChangeListener that needs to be informed about
state changes of this table.addMOChangeListener in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>l - a MOChangeListener instance.public void removeMOChangeListener(MOChangeListener l)
MOTableMOChangeListenerremoveMOChangeListener in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>l - a MOChangeListener instance.protected void fireBeforePrepareMOChange(MOChangeEvent changeEvent)
protected void fireAfterPrepareMOChange(MOChangeEvent changeEvent)
protected void fireBeforeMOChange(MOChangeEvent changeEvent)
protected void fireAfterMOChange(MOChangeEvent changeEvent)
public void addMOTableRowListener(MOTableRowListener<R> l)
MOTableMOTableRowListener listener that needs to be informed
about row changes (creation, addition, removal).addMOTableRowListener in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>l - a MOTableRowListener instance.public void removeMOTableRowListener(MOTableRowListener<R> l)
MOTableMOTableRowListener instance.removeMOTableRowListener in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>l - a MOTableRowListener instance.protected void fireRowChanged(MOTableRowEvent<R> event)
public org.snmp4j.smi.OID getID()
RegisteredManagedObjectgetID in interface RegisteredManagedObjectpublic void load(MOInput input) throws IOException
SerializableManagedObjectload in interface SerializableManagedObjectinput - a MOInput instance.IOException - if an MOInput operation fails.public void save(MOOutput output) throws IOException
SerializableManagedObjectsave in interface SerializableManagedObjectoutput - a MOOutput instance.IOException - if an MOOutput operation fails.protected org.snmp4j.smi.Variable[] getPersistentValues(MOTableRow row)
save(MOOutput output) call.row - a MOTableRow that is being saved into a MOOutput stream.Variable instances that need to be saved.
Typically, these are all columns of the row - including hidden
extension columns/values.public org.snmp4j.smi.Variable[] getDefaultValues()
MOTablenull and contains that default value.getDefaultValues in interface MOTable<R extends MOTableRow,C extends MOColumn,M extends MOTableModel<R>>Variable instances.public boolean covers(org.snmp4j.smi.OID oid)
MOScopepublic boolean setValue(org.snmp4j.smi.VariableBinding newValueAndInstancceOID)
ManagedObjectValueAccessManagedObject. This is a low level operation, thus
no change events will be fired.setValue in interface ManagedObjectValueAccessnewValueAndInstancceOID - a VariableBinding identifying the object instance to modify
by its OID and the new value by its variable part.true if the object instance exists and has been modified
successfully, false otherwise.Copyright © 2020 SNMP4J.org. All rights reserved.