📄 snmpmibtable.java
字号:
* @see com.sun.jmx.snmp.EnumRowStatus **/ protected boolean isRowReady(SnmpOid rowOid, Object userData) throws SnmpStatusException { return true; } /** * Check whether the control variable of the given row can be * switched to the new specified <code>newStatus</code>. * <p> * This method is called during the <i>check</i> phase of a SET * request when the control variable specifies <i>active</i> or * <i>notInService</i>. * <p> * By default it is assumed that nothing prevents putting the * row in the requested state, and this method does nothing. * It is simply provided as a hook so that specific checks can * be implemented. * <p> * Note that if the actual row deletion fails afterward, the * atomicity of the request is no longer guaranteed. * * <p> * @param req The sub-request that must be handled by this node. * * @param rowOid The <CODE>SnmpOid</CODE> identifying the table * row involved in the operation. * * @param depth The depth reached in the OID tree. * * @param newStatus The new status for the row: one of the * RowStatus code defined in * {@link com.sun.jmx.snmp.EnumRowStatus}. These codes * correspond to RowStatus codes as defined in RFC 2579, * plus the <i>unspecified</i> value which is SNMP Runtime specific. * * @exception SnmpStatusException if switching to this new state * would fail. * **/ protected void checkRowStatusChange(SnmpMibSubRequest req, SnmpOid rowOid, int depth, int newStatus) throws SnmpStatusException { } /** * Check whether the specified row can be removed from the table. * <p> * This method is called during the <i>check</i> phase of a SET * request when the control variable specifies <i>destroy</i> * <p> * By default it is assumed that nothing prevents row deletion * and this method does nothing. It is simply provided as a hook * so that specific checks can be implemented. * <p> * Note that if the actual row deletion fails afterward, the * atomicity of the request is no longer guaranteed. * * <p> * @param req The sub-request that must be handled by this node. * * @param rowOid The <CODE>SnmpOid</CODE> identifying the table * row involved in the operation. * * @param depth The depth reached in the OID tree. * * @exception SnmpStatusException if the row deletion must be * rejected. **/ protected void checkRemoveTableRow(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException { } /** * Remove a table row upon a remote manager request. * * This method is called internally when <code>getRowAction()</code> * yields <i>destroy</i> - i.e.: it is only called when a remote * manager requests the removal of a table row.<br> * You should never need to call this function directly. * <p> * By default, this method simply calls <code>removeEntry(rowOid) * </code>. * <p> * You can redefine this method if you need to implement some * specific behaviour when a remote row deletion is invoked. * <p> * Note that specific checks should not be implemented in this * method, but rather in <code>checkRemoveTableRow()</code>. * If <code>checkRemoveTableRow()</code> succeeds and this method * fails afterward, the atomicity of the original SET request can no * longer be guaranteed. * <p> * * @param req The sub-request that must be handled by this node. * * @param rowOid The <CODE>SnmpOid</CODE> identifying the table * row involved in the operation. * * @param depth The depth reached in the OID tree. * * @exception SnmpStatusException if the actual row deletion fails. * This should not happen since it would break the * atomicity of the SET request. Specific checks should * be implemented in <code>checkRemoveTableRow()</code> * if needed. If the entry does not exists, no exception * is generated and the method simply returns. * **/ protected void removeTableRow(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException { removeEntry(rowOid); } /** * This method takes care of initial RowStatus handling during the * check() phase of a SET request. * * In particular it will: * <ul><li>check that the given <code>rowAction</code> returned by * <code>getRowAction()</code> is valid.</li> * <li>Then depending on the <code>rowAction</code> specified it will: * <ul><li>either call <code>createNewEntry()</code> (<code> * rowAction = <i>createAndGo</i> or <i>createAndWait</i> * </code>),</li> * <li>or call <code>checkRemoveTableRow()</code> (<code> * rowAction = <i>destroy</i></code>),</li> * <li>or call <code>checkRowStatusChange()</code> (<code> * rowAction = <i>active</i> or <i>notInService</i></code>),</li> * <li>or generate a SnmpStatusException if the passed <code> * rowAction</code> is not correct.</li> * </ul></li></ul> * <p> * In principle, you should not need to redefine this method. * <p> * <code>beginRowAction()</code> is called during the check phase * of a SET request, before actual checking on the varbind list * is performed. * * <p> * @param req The sub-request that must be handled by this node. * * @param rowOid The <CODE>SnmpOid</CODE> identifying the table * row involved in the operation. * * @param depth The depth reached in the OID tree. * * @param rowAction The requested action as returned by <code> * getRowAction()</code>: one of the RowStatus codes defined in * {@link com.sun.jmx.snmp.EnumRowStatus}. These codes * correspond to RowStatus codes as defined in RFC 2579, * plus the <i>unspecified</i> value which is SNMP Runtime specific. * * @exception SnmpStatusException if the specified <code>rowAction</code> * is not valid or cannot be executed. * This should not happen since it would break the * atomicity of the SET request. Specific checks should * be implemented in <code>beginRowAction()</code> if needed. * * @see com.sun.jmx.snmp.EnumRowStatus **/ protected synchronized void beginRowAction(SnmpMibSubRequest req, SnmpOid rowOid, int depth, int rowAction) throws SnmpStatusException { final boolean isnew = req.isNewEntry(); final SnmpOid oid = rowOid; final int action = rowAction; switch (action) { case EnumRowStatus.unspecified: if (isnew) { if (isDebugOn()) debug("beginRowAction","Failed to create row[" + rowOid + "] : RowStatus = unspecified"); checkRowStatusFail(req,SnmpStatusException.snmpRspNoAccess); } break; case EnumRowStatus.createAndGo: case EnumRowStatus.createAndWait: if (isnew) { if (isCreationEnabled()) { if (isDebugOn()) debug("beginRowAction","Creating row[" + rowOid + "] : RowStatus = createAndGo | createAndWait"); createNewEntry(req,oid,depth); } else { if (isDebugOn()) debug("beginRowAction","Can't create row[" + rowOid + "] : RowStatus = createAndGo | createAndWait" + " but creation is disabled"); checkRowStatusFail(req, SnmpStatusException.snmpRspNoAccess); } } else { if (isDebugOn()) debug("beginRowAction","Can't create row[" + rowOid + "] : RowStatus = createAndGo | createAndWait" + " but row already exists"); checkRowStatusFail(req, SnmpStatusException.snmpRspInconsistentValue); } break; case EnumRowStatus.destroy: if (isnew) { if (isDebugOn()) debug("beginRowAction","Warning: can't destroy row[" + rowOid + "] : RowStatus = destroy" + " but row does not exist"); } else if (!isCreationEnabled()) { if (isDebugOn()) debug("beginRowAction","Can't destroy row[" + rowOid + "] : RowStatus = destroy " + " but creation is disabled"); checkRowStatusFail(req,SnmpStatusException.snmpRspNoAccess); } checkRemoveTableRow(req,rowOid,depth); break; case EnumRowStatus.active: case EnumRowStatus.notInService: if (isnew) { if (isDebugOn()) debug("beginRowAction","Can't switch state of row[" + rowOid + "] : specified RowStatus = active | notInService" + " but row does not exist"); checkRowStatusFail(req, SnmpStatusException.snmpRspInconsistentValue); } checkRowStatusChange(req,rowOid,depth,action); break; case EnumRowStatus.notReady: default: if (isDebugOn()) debug("beginRowAction","Invalid RowStatus value for row[" + rowOid + "] : specified RowStatus = " + action); checkRowStatusFail(req, SnmpStatusException.snmpRspInconsistentValue); } } /** * This method takes care of final RowStatus handling during the * set() phase of a SET request. * * In particular it will: * <ul><li>either call <code>setRowStatus(<i>active</i>)</code> * (<code> rowAction = <i>createAndGo</i> or <i>active</i> * </code>),</li> * <li>or call <code>setRowStatus(<i>notInService</i> or <i> * notReady</i>)</code> depending on the result of <code> * isRowReady()</code> (<code>rowAction = <i>createAndWait</i> * </code>),</li> * <li>or call <code>setRowStatus(<i>notInService</i>)</code> * (<code> rowAction = <i>notInService</i></code>), * <li>or call <code>removeTableRow()</code> (<code> * rowAction = <i>destroy</i></code>),</li> * <li>or generate a SnmpStatusException if the passed <code> * rowAction</code> is not correct. This should be avoided * since it would break SET request atomicity</li> * </ul> * <p> * In principle, you should not need to redefine this method. * <p> * <code>endRowAction()</code> is called during the set() phase * of a SET request, after the actual set() on the varbind list * has been performed. The varbind containing the control variable * is updated with the value returned by setRowStatus() (if it is * not <code>null</code>). * * <p> * @param req The sub-request that must be handled by this node. * * @param rowOid The <CODE>SnmpOid</CODE> identifying the table * row involved in the operation. * * @param depth The depth reached in the OID tree. * * @param rowAction The requested action as returned by <code> * getRowAction()</code>: one of the RowStatus codes defined in * {@link com.sun.jmx.snmp.EnumRowStatus}. These codes * correspond to RowStatus codes as defined in RFC 2579, * plus the <i>unspecified</i> value which is SNMP Runtime specific. * * @exception SnmpStatusException if the specified <code>rowAction</code> * is not valid. * * @see com.sun.jmx.snmp.EnumRowStatus **/ protected void endRowAction(SnmpMibSubRequest req, SnmpOid rowOid, int depth, int rowAction) throws SnmpStatusException { final boolean isnew = req.isNewEntry(); final SnmpOid oid = rowOid; final int action = rowAction; final Object data = req.getUserData(); SnmpValue value = null; switch (action) { case EnumRowStatus.unspecified: break; case EnumRowStatus.createAndGo: if (isDebugOn()) debug("endRowAction","Setting RowStatus to `active'" + " for row[" + rowOid + "] : requested RowStatus = " + "createAndGo"); value = setRowStatus(oid,EnumRowStatus.active,data); break; case EnumRowStatus.createAndWait: if (isRowReady(oid,data)) { if (isDebugOn()) debug("endRowAction", "Setting RowStatus to `notInService'" + " for row[" + rowOid + "] : requested RowStatus = " + "createAndWait"); value = setRowStatus(oid,EnumRowStatus.notInService,data); } else { if (isDebugOn()) debug("endRowAction", "Setting RowStatus to `notReady'" + " for row[" + rowOid + "] : requested RowStatus = " + "createAndWait"); value = setRowStatus(oid,EnumRowStatus.notReady,data); } break; case EnumRowStatus.destroy: if (isnew) { if (isDebugOn()) debug("endRowAction", "Warning: " + " requested RowStatus = destroy," + "but row[" + rowOid + "] does not exist."); } else { if (isDebugOn()) debug("endRowAction", "destroying row[" + rowOid + "] : requested RowStatus = destroy"); } removeTableRow(req,oid,depth); break; case EnumRowStatus.active: if (isDebugOn()) debug("endRowAction", "Setting RowStatus to `active'" + " for row[" + rowOid + "] : requested RowStatus = " + "active"); value = setRowStatus(oid,EnumRowStatus.active,data); break; case EnumRowStatus.notInService: if (isDebugOn()) debug("endRowAction",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -