📄 snmpmibtable.java
字号:
* throws SnmpStatusException { * final SnmpOid oid = req.getEntryOid(); * final int action = getRowAction(req,oid,depth+1); * * set(req,oid,depth+1); * endRowAction(req,oid,depth+1,action); * } * </pre> * <p> You should not need to override this method in any cases, because * it will eventually call * <CODE>set(SnmpMibSubRequest req, int depth)</CODE> on the generated * derivative of <CODE>SnmpMibEntry</CODE>. If you need to implement * specific policies for minimizing the accesses made to some remote * underlying resources, or if you need to implement some consistency * checks between the different values provided in the varbind list, * you should then rather override * <CODE>set(SnmpMibSubRequest req, int depth)</CODE> on the generated * derivative of <CODE>SnmpMibEntry</CODE>. * <p> * */ public void set(SnmpMibSubRequest req, int depth) throws SnmpStatusException { final boolean dbg = isDebugOn(); if (dbg) debug("set","Entering set."); final SnmpOid oid = req.getEntryOid(); final int action = getRowAction(req,oid,depth+1); if (dbg) debug("set","Calling set for " + req.getSize() + "varbinds."); set(req,oid,depth+1); if (dbg) debug("set","Calling endRowAction"); endRowAction(req,oid,depth+1,action); if (dbg) debug("set","RowAction finished"); } /** * Add a new entry in this <CODE>SnmpMibTable</CODE>. * Also triggers the addEntryCB() callback of the * {@link com.sun.jmx.snmp.agent.SnmpTableEntryFactory} interface * if this node is bound to a factory. * * This method assumes that the given entry will not be registered. * If the entry is going to be registered, or if ObjectName's are * required, then * {@link com.sun.jmx.snmp.agent.SnmpMibTable#addEntry(SnmpOid, * ObjectName, Object)} should be prefered. * <br> This function is mainly provided for backward compatibility. * * <p> * @param rowOid The <CODE>SnmpOid</CODE> identifying the table * row to be added. * @param entry The entry to add. * * @exception SnmpStatusException The entry couldn't be added * at the position identified by the given * <code>rowOid</code>, or this version of the metadata * requires ObjectName's. */ // public void addEntry(SnmpIndex index, Object entry) public void addEntry(SnmpOid rowOid, Object entry) throws SnmpStatusException { addEntry(rowOid, null, entry); } /** * Add a new entry in this <CODE>SnmpMibTable</CODE>. * Also triggers the addEntryCB() callback of the * {@link com.sun.jmx.snmp.agent.SnmpTableEntryFactory} interface * if this node is bound to a factory. * * <p> * @param oid The <CODE>SnmpOid</CODE> identifying the table * row to be added. * * @param name The ObjectName with which this entry is registered. * This parameter can be omitted if isRegistrationRequired() * return false. * * @param entry The entry to add. * * @exception SnmpStatusException The entry couldn't be added * at the position identified by the given * <code>rowOid</code>, or if this version of the metadata * requires ObjectName's, and the given name is null. */ // protected synchronized void addEntry(SnmpIndex index, ObjectName name, // Object entry) public synchronized void addEntry(SnmpOid oid, ObjectName name, Object entry) throws SnmpStatusException { if (isRegistrationRequired() == true && name == null) throw new SnmpStatusException(SnmpStatusException.badValue); if (size == 0) { // indexes.addElement(index); // XX oids.addElement(oid); insertOid(0,oid); if (entries != null) entries.addElement(entry); if (entrynames != null) entrynames.addElement(name); size++; // triggers callbacks on the entry factory // if (factory != null) { try { factory.addEntryCb(0,oid,name,entry,this); } catch (SnmpStatusException x) { removeOid(0); if (entries != null) entries.removeElementAt(0); if (entrynames != null) entrynames.removeElementAt(0); throw x; } } // sends the notifications // sendNotification(SnmpTableEntryNotification.SNMP_ENTRY_ADDED, (new Date()).getTime(), entry, name); return; } // Get the insertion position ... // int pos= 0; // bug jaw.00356.B : use oid rather than index to get the // insertion point. // pos= getInsertionPoint(oid,true); if (pos == size) { // Add a new element in the vectors ... // // indexes.addElement(index); // XX oids.addElement(oid); insertOid(tablecount,oid); if (entries != null) entries.addElement(entry); if (entrynames != null) entrynames.addElement(name); size++; } else { // Insert new element ... // try { // indexes.insertElementAt(index, pos); // XX oids.insertElementAt(oid, pos); insertOid(pos,oid); if (entries != null) entries.insertElementAt(entry, pos); if (entrynames != null) entrynames.insertElementAt(name,pos); size++; } catch(ArrayIndexOutOfBoundsException e) { } } // triggers callbacks on the entry factory // if (factory != null) { try { factory.addEntryCb(pos,oid,name,entry,this); } catch (SnmpStatusException x) { removeOid(pos); if (entries != null) entries.removeElementAt(pos); if (entrynames != null) entrynames.removeElementAt(pos); throw x; } } // sends the notifications // sendNotification(SnmpTableEntryNotification.SNMP_ENTRY_ADDED, (new Date()).getTime(), entry, name); } /** * Remove the specified entry from the table. * Also triggers the removeEntryCB() callback of the * {@link com.sun.jmx.snmp.agent.SnmpTableEntryFactory} interface * if this node is bound to a factory. * * <p> * @param rowOid The <CODE>SnmpOid</CODE> identifying the table * row to remove. * * @param entry The entry to be removed. This parameter is not used * internally, it is simply passed along to the * removeEntryCB() callback. * * @exception SnmpStatusException if the specified entry couldn't * be removed (if the given <code>rowOid</code> is not * valid for instance). */ public synchronized void removeEntry(SnmpOid rowOid, Object entry) throws SnmpStatusException { int pos = findObject(rowOid); if (pos == -1) return; removeEntry(pos,entry); } /** * Remove the specified entry from the table. * Also triggers the removeEntryCB() callback of the * {@link com.sun.jmx.snmp.agent.SnmpTableEntryFactory} interface * if this node is bound to a factory. * * <p> * @param rowOid The <CODE>SnmpOid</CODE> identifying the table * row to remove. * * @exception SnmpStatusException if the specified entry couldn't * be removed (if the given <code>rowOid</code> is not * valid for instance). */ public void removeEntry(SnmpOid rowOid) throws SnmpStatusException { int pos = findObject(rowOid); if (pos == -1) return; removeEntry(pos,null); } /** * Remove the specified entry from the table. * Also triggers the removeEntryCB() callback of the * {@link com.sun.jmx.snmp.agent.SnmpTableEntryFactory} interface * if this node is bound to a factory. * * <p> * @param pos The position of the entry in the table. * * @param entry The entry to be removed. This parameter is not used * internally, it is simply passed along to the * removeEntryCB() callback. * * @exception SnmpStatusException if the specified entry couldn't * be removed. */ public synchronized void removeEntry(int pos, Object entry) throws SnmpStatusException { if (pos == -1) return; if (pos >= size) return; Object obj = entry; if (entries != null && entries.size() > pos) { obj = entries.elementAt(pos); entries.removeElementAt(pos); } ObjectName name = null; if (entrynames != null && entrynames.size() > pos) { name = (ObjectName) entrynames.elementAt(pos); entrynames.removeElementAt(pos); } final SnmpOid rowOid = tableoids[pos]; removeOid(pos); size --; if (obj == null) obj = entry; if (factory != null) factory.removeEntryCb(pos,rowOid,name,obj,this); sendNotification(SnmpTableEntryNotification.SNMP_ENTRY_REMOVED, (new Date()).getTime(), obj, name); } /** * Get the entry corresponding to the specified rowOid. * * <p> * @param rowOid The <CODE>SnmpOid</CODE> identifying the * row to be retrieved. * * @return The entry. * * @exception SnmpStatusException There is no entry with the specified * <code>rowOid</code> in the table. */ public synchronized Object getEntry(SnmpOid rowOid) throws SnmpStatusException { int pos= findObject(rowOid); if (pos == -1) throw new SnmpStatusException(SnmpStatusException.noSuchInstance); return entries.elementAt(pos); } /** * Get the ObjectName of the entry corresponding to the * specified rowOid. * The result of this method is only meaningful if * isRegistrationRequired() yields true. * * <p> * @param rowOid The <CODE>SnmpOid</CODE> identifying the table * row whose ObjectName we want to retrieve. * * @return The object name of the entry. * * @exception SnmpStatusException There is no entry with the specified * <code>rowOid</code> in the table. */ public synchronized ObjectName getEntryName(SnmpOid rowOid) throws SnmpStatusException { int pos = findObject(rowOid); if (entrynames == null) return null; if (pos == -1 || pos >= entrynames.size()) throw new SnmpStatusException(SnmpStatusException.noSuchInstance); return (ObjectName) entrynames.elementAt(pos); } /** * Return the entries stored in this table <CODE>SnmpMibTable</CODE>. * <p> * If the subclass generated by mibgen uses the generic way to access * the entries (i.e. if it goes through the MBeanServer) then some of * the entries may be <code>null</code>. It all depends whether a non * <code>null</code> entry was passed to addEntry().<br> * Otherwise, if it uses the standard way (access the entry directly * through their standard MBean interface) this array will contain all * the entries. * <p> * @return The entries array. */ public Object[] getBasicEntries() { Object[] array= new Object[size]; entries.copyInto(array); return array; } /** * Get the size of the table. * * @return The number of entries currently registered in this table. */ public int getSize() { return size; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -