⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmpmibtable.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * @(#)file      SnmpMibTable.java * @(#)author    Sun Microsystems, Inc. * @(#)version   4.59 * @(#)date      08/09/12 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * */package com.sun.jmx.snmp.agent;// java imports//import java.io.Serializable;import java.util.Date;import java.util.Vector;import java.util.Enumeration;// jmx imports//import javax.management.Notification;import javax.management.ObjectName;import javax.management.NotificationFilter;import javax.management.NotificationListener;import javax.management.NotificationBroadcaster;import javax.management.MBeanNotificationInfo;import javax.management.ListenerNotFoundException;import com.sun.jmx.snmp.SnmpOid;import com.sun.jmx.snmp.SnmpValue;import com.sun.jmx.snmp.SnmpInt;import com.sun.jmx.snmp.SnmpVarBind;import com.sun.jmx.snmp.SnmpStatusException;import com.sun.jmx.snmp.EnumRowStatus;import com.sun.jmx.trace.Trace; /** * This class is the base class for SNMP table metadata. * <p> * Its responsibility is to manage a sorted array of OID indexes * according to the SNMP indexing scheme over the "real" table. * Each object of this class can be bound to an * {@link com.sun.jmx.snmp.agent.SnmpTableEntryFactory} to which it will * forward remote entry creation requests, and invoke callbacks * when an entry has been successfully added to / removed from * the OID index array. * </p> * * <p> * For each table defined in the MIB, mibgen will generate a specific * class called Table<i>TableName</i> that will implement the  * SnmpTableEntryFactory interface, and a corresponding  * <i>TableName</i>Meta class that will extend this class. <br> * The Table<i>TableName</i> class corresponds to the MBean view of the * table while the <i>TableName</i>Meta class corresponds to the * MIB metadata view of the same table. * </p> * * <p> * Objects of this class are instantiated by the generated  * whole MIB class extending {@link com.sun.jmx.snmp.agent.SnmpMib} * You should never need to instantiate this class directly. * </p> * * <p><b>This API is a Sun Microsystems internal API  and is subject  * to change without notice.</b></p> * @see com.sun.jmx.snmp.agent.SnmpMib * @see com.sun.jmx.snmp.agent.SnmpMibEntry * @see com.sun.jmx.snmp.agent.SnmpTableEntryFactory * @see com.sun.jmx.snmp.agent.SnmpTableSupport * * @version     4.59     04/07/06 * @author      Sun Microsystems, Inc */public abstract class SnmpMibTable extends SnmpMibNode     implements NotificationBroadcaster, Serializable {      /**     * Create a new <CODE>SnmpMibTable</CODE> metadata node.     *     * <p>     * @param mib The SNMP MIB to which the metadata will be linked.     */    public SnmpMibTable(SnmpMib mib) {        this.theMib= mib;    	setCreationEnabled(false);    }        // -------------------------------------------------------------------    // PUBLIC METHODS    // -------------------------------------------------------------------            /**     * This method is invoked when the creation of a new entry is requested     * by a remote SNMP manager.     * <br>By default, remote entry creation is disabled - and this method      * will not be called. You can dynamically switch the entry creation     * policy by calling <code>setCreationEnabled(true)</code> and <code>     * setCreationEnabled(false)</code> on this object.     * <p><b><i>     * This method is called internally by the SNMP runtime and you      * should never need to call it directly. </b></i>However you might want      * to extend it in order to implement your own specific application      * behaviour, should the default behaviour not be at your convenience.     * </p>     * <p>     * @param req   The SNMP  subrequest requesting this creation     * @param rowOid  The OID indexing the conceptual row (entry) for which      *                the creation was requested.     * @param depth The position of the columnar object arc in the OIDs     *              from the varbind list.     *     * @exception SnmpStatusException if the entry cannot be created.     */    public abstract void createNewEntry(SnmpMibSubRequest req, SnmpOid rowOid,					int depth) 	throws SnmpStatusException;    /**     * Tell whether the specific version of this metadata generated     * by <code>mibgen</code> requires entries to be registered with     * the MBeanServer. In this case an ObjectName will have to be      * passed to addEntry() in order for the table to behave correctly      * (case of the generic metadata).     * <p>     * If that version of the metadata does not require entry to be     * registered, then passing an ObjectName becomes optional (null     * can be passed instead).     *     * @return <code>true</code> if registration is required by this     *         version of the metadata.     */    public abstract boolean isRegistrationRequired();    /**     * Tell whether a new entry should be created when a SET operation     * is received for an entry that does not exist yet.     *      * @return true if a new entry must be created, false otherwise.<br>     *         [default: returns <CODE>false</CODE>]     **/    public boolean isCreationEnabled() {	return creationEnabled;    }    /**     * This method lets you dynamically switch the creation policy.     *     * <p>     * @param remoteCreationFlag Tells whether remote entry creation must     *        be enabled or disabled.     * <ul><li>     * <CODE>setCreationEnabled(true)</CODE> will enable remote entry     *      creation via SET operations.</li>     * <li>     * <CODE>setCreationEnabled(false)</CODE> will disable remote entry     *      creation via SET operations.</li>     * <p> By default remote entry creation via SET operation is disabled.     * </p>     * </ul>     **/    public void setCreationEnabled(boolean remoteCreationFlag) {	creationEnabled = remoteCreationFlag;    }    /**     * Return <code>true</code> if the conceptual row contains a columnar     * object used to control creation/deletion of rows in this table.     * <p>     * This  columnar object can be either a variable with RowStatus     * syntax as defined by RFC 2579, or a plain variable whose     * semantics is table specific.     * <p>     * By default, this function returns <code>false</code>, and it is     * assumed that the table has no such control variable.<br>     * When <code>mibgen</code> is used over SMIv2 MIBs, it will generate     * an <code>hasRowStatus()</code> method returning <code>true</code>     * for each table containing an object with RowStatus syntax.     * <p>     * When this method returns <code>false</code> the default mechanism     * for remote entry creation is used.     * Otherwise, creation/deletion is performed as specified     * by the control variable (see getRowAction() for more details).     * <p>     * This method is called internally when a SET request involving     * this table is processed.     * <p>     * If you need to implement a control variable which do not use     * the RowStatus convention as defined by RFC 2579, you should     * subclass the generated table metadata class in order to redefine     * this method and make it returns <code>true</code>.<br>     * You will then have to redefine the isRowStatus(), mapRowStatus(),      * isRowReady(), and setRowStatus() methods to suit your specific     * implementation.     * <p>     * @return <li><code>true</code> if this table contains a control      *         variable (eg: a variable with RFC 2579 RowStatus syntax),     *         </li>     *         <li><code>false</code> if this table does not contain     *         any control variable.</li>     *     **/    public boolean hasRowStatus() {	return false;    }    // ---------------------------------------------------------------------    //    // Implements the method defined in SnmpMibNode.    //    // ---------------------------------------------------------------------    /**     * Generic handling of the <CODE>get</CODE> operation.     * <p> The default implementation of this method is to     * <ul>     * <li> check whether the entry exists, and if not register an      *      exception for each varbind in the list.     * <li> call the generated      *      <CODE>get(req,oid,depth+1)</CODE> method. </li>     * </ul>      * <p>     * <pre>     * public void get(SnmpMibSubRequest req, int depth)     *	  throws SnmpStatusException {     *    boolean         isnew  = req.isNewEntry();     *     * 	  // if the entry does not exists, then registers an error for     *    // each varbind involved (nb: this should not happen, since      *    // the error should already have been detected earlier)     *    //     *    if (isnew) {     *        SnmpVarBind     var = null;     *        for (Enumeration e= req.getElements(); e.hasMoreElements();) {     *            var = (SnmpVarBind) e.nextElement();      *            req.registerGetException(var,noSuchNameException);     *        }     *    }     *     *    final SnmpOid oid = req.getEntryOid();     *    get(req,oid,depth+1);     * }     * </pre>     * <p> You should not need to override this method in any cases, because     * it will eventually call      * <CODE>get(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>get(SnmpMibSubRequest req, int depth)</CODE> on the generated      * derivative of <CODE>SnmpMibEntry</CODE>.     * <p>     *     */    public void get(SnmpMibSubRequest req, int depth) 	throws SnmpStatusException {	final boolean         isnew  = req.isNewEntry();	final SnmpMibSubRequest  r      = req;	// if the entry does not exists, then registers an error for	// each varbind involved (nb: should not happen, the error	// should have been registered earlier)		if (isnew) {	    SnmpVarBind     var = null;	    for (Enumeration e= r.getElements(); e.hasMoreElements();) {		var      = (SnmpVarBind) e.nextElement(); 		r.registerGetException(var,noSuchInstanceException);	    }	}	final SnmpOid     oid    = r.getEntryOid();	// SnmpIndex   index  = buildSnmpIndex(oid.longValue(false), 0);	// get(req,index,depth+1);	//	get(req,oid,depth+1);    }    // ---------------------------------------------------------------------    //    // Implements the method defined in SnmpMibNode.    //    // ---------------------------------------------------------------------    /**     * Generic handling of the <CODE>check</CODE> operation.     * <p> The default implementation of this method is to     * <ul>      * <li> check whether a new entry must be created, and if remote     *      creation of entries is enabled, create it. </li>     * <li> call the generated      *      <CODE>check(req,oid,depth+1)</CODE> method. </li>     * </ul>      * <p>     * <pre>     * public void check(SnmpMibSubRequest req, int depth)     *	  throws SnmpStatusException {     *    final SnmpOid     oid    = req.getEntryOid();     *    final int         action = getRowAction(req,oid,depth+1);     *     *    beginRowAction(req,oid,depth+1,action);     *    check(req,oid,depth+1);     * }     * </pre>     * <p> You should not need to override this method in any cases, because     * it will eventually call      * <CODE>check(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>check(SnmpMibSubRequest req, int depth)</CODE> on the generated      * derivative of <CODE>SnmpMibEntry</CODE>.     * <p>     *     */    public void check(SnmpMibSubRequest req, int depth) 	throws SnmpStatusException {	final SnmpOid     oid    = req.getEntryOid();	final int         action = getRowAction(req,oid,depth+1);	final boolean dbg = isDebugOn();	if (dbg) debug("check","Calling beginRowAction");	beginRowAction(req,oid,depth+1,action);	if (dbg) debug("check","Calling check for " + req.getSize() + 		       " varbinds.");	check(req,oid,depth+1);	if (dbg) debug("check","check finished");    }    // ---------------------------------------------------------------------    //    // Implements the method defined in SnmpMibNode.    //    // ---------------------------------------------------------------------    /**     * Generic handling of the <CODE>set</CODE> operation.     * <p> The default implementation of this method is to     * call the generated      * <CODE>set(req,oid,depth+1)</CODE> method.     * <p>     * <pre>     * public void set(SnmpMibSubRequest req, int depth)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -