[SNMP4J] SNMP4J.AgentX questions

Frank Fock fock at agentpp.com
Sun Feb 17 19:01:24 CET 2008


Hi Eyal,

These issues are indeed bugs that can be fixed with
the below patches:

AgentXSubagent.registerSharedTableRows(..):

   public List registerSharedTableRows(AgentXSession session,
                                       OctetString context,
                                       AgentXSharedMOTable mo) {
     LinkedList failedRows = new LinkedList();
     AgentXSharedMOTableSupport sharedTableSupport =
         new AgentXSharedMOTableSupport(agentX, session, context);
     synchronized (mo) {
       if (mo instanceof AgentXSharedMutableMOTable) {
         ((AgentXSharedMutableMOTable)
          mo).setAgentXSharedMOTableSupport(sharedTableSupport);
       }
       // decouple iterator from table modifications (may still fail if 
table
       // is being modified while row list is copied - if such a 
concurrency is
       // needed a table model must be used that returns an table 
independent
       // iterator.
       ArrayList rows = new ArrayList(mo.getModel().getRowCount());
       for (Iterator it = mo.getModel().iterator(); it.hasNext();) {
         rows.add(it.next());
       }
       for (Iterator it = rows.iterator(); it.hasNext();) {
         MOTableRow row = (MOTableRow) it.next();
         OID newIndex = (OID) row.getIndex().clone();
         int status = sharedTableSupport.allocateIndex(context, 
mo.getIndexDef(),
             (byte)AgentXSharedMOTableSupport.INDEX_MODE_ALLOCATE,
             newIndex);
         if (status == AgentXProtocol.AGENTX_SUCCESS) {
           if ((newIndex instanceof AnyNewIndexOID) ||
               (newIndex instanceof NewIndexOID)) {
             if (mo instanceof AgentXSharedMutableMOTable) {
               ((AgentXSharedMutableMOTable)mo).
                   changeRowIndex(row.getIndex(), newIndex);
             }
           }
           status = sharedTableSupport.registerRow(mo, row);
           if (status != AgentXProtocol.AGENTX_SUCCESS) {
             sharedTableSupport.deallocateIndex(context, mo.getIndexDef(),
                                                row.getIndex());
             LOGGER.warn("Failed to register row with "+status+" for "+row);
             failedRows.add(row);
           }
         }
         else {
           LOGGER.warn("Failed to allocate index with "+status+" for row "+
                       row);
           failedRows.add(row);
         }
       }
     }
     return failedRows;
   }


DefaultAgentXSharedMOTable.changeRowIndex(..):

   public boolean changeRowIndex(OID oldIndex, OID newIndex) {
     if (model instanceof MOMutableTableModel) {
       MOMutableTableModel mutableModel = (MOMutableTableModel) model;
       MOTableRow r = mutableModel.removeRow(oldIndex);
       if (r == null) {
         return false;
       }
       r.getIndex().setValue(newIndex.getValue());
       MOTableRow existingRow = mutableModel.addRow(r);
       if (existingRow != null) {
         mutableModel.removeRow(newIndex);
         r.getIndex().setValue(oldIndex.getValue());
         mutableModel.addRow(r);
         mutableModel.addRow(existingRow);
         return false;
       }
       fireRowChanged(new MOTableRowEvent(this, this, r,
                                          MOTableRowEvent.UPDATED, false));
       return true;
     }
     return false;
   }

Best regards,
Frank

Eyal Schneider wrote:
> Hi,
> 
> I am trying to implement a simple AgentX subagent using SNMP4J. I
> encountered the following problems while trying to use shared tables.
> I suspect these are bugs, but I will be happy to be proven wrong  :)
> 
> 1 ) In AgentXSubagent.registerSharedTableRows(..) :
> The iteration over the rows is unsafe, since the row collection may be
> altered by the changeRowIndex(..) call (inside the iteration), resulting in
> a ConcurrentModificationException.
> 
> 2) In AgentXSubagent.registerSharedTableRows(..): it seems that the
> parameters are in wrong order. The old index is expected to come first, not
> last.
> 
> 3) DefaultAgentXSharedMOTable.changeRowIndex(..):
> The condition "if (mutableModel.addRow(r) == null)" should have been "if (
> mutableModel.addRow(r) != null)". If I understand correctly, null means that
> the row has been added without replacing an existing one.
> 
> I will be happy to have any comments about these issues.
> Thanks in advance,
> Eyal.
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list