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

📄 snmpmib.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	}	// Optimization: we're going to pass the whole SnmpRequestTree	// to the "set" method, so that we don't have to rebuild it there.	//	if (req instanceof SnmpMibRequestImpl) {	    ((SnmpMibRequestImpl)req).setRequestTree(handlers);	}    }    /**     * Processes a <CODE>getNext</CODE> operation.     *      */    // Implements the method defined in SnmpMibAgent. See SnmpMibAgent    // for java-doc    //    public void getNext(SnmpMibRequest req) throws SnmpStatusException {	// Build the request tree for the operation	// The subrequest stored in the request tree are valid GET requests	SnmpRequestTree handlers = getGetNextHandlers(req);	SnmpRequestTree.Handler h = null;	SnmpMibNode meta = null;	if (isDebugOn()) 	    debug("getNext","Processing handlers for GET-NEXT... ");	// Now invoke get() for each subrequest of the request tree.	for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) {	    h = (SnmpRequestTree.Handler) eh.nextElement();	    	    // Gets the Meta node. It can be either a Group Meta or a 	    // Table Meta.	    //	    meta = handlers.getMetaNode(h);	    // Gets the depth of the Meta node in the OID tree	    int depth = handlers.getOidDepth(h);	    for (Enumeration rqs=handlers.getSubRequests(h);		 rqs.hasMoreElements();) {		// Invoke the get() operation		meta.get((SnmpMibSubRequest)rqs.nextElement(),depth);	    }	}    }        /**     * Processes a <CODE>getBulk</CODE> operation.     * The method implements the <CODE>getBulk</CODE> operation by calling      * appropriately the <CODE>getNext</CODE> method.     *     */    // Implements the method defined in SnmpMibAgent. See SnmpMibAgent    // for java-doc    //    public void getBulk(SnmpMibRequest req, int nonRepeat, int maxRepeat) 	throws SnmpStatusException {             getBulkWithGetNext(req, nonRepeat, maxRepeat);    }        /**     * Gets the root object identifier of the MIB.     * <P>In order to be accurate, the method should be called once the      * MIB is fully initialized (that is, after a call to <CODE>init</CODE>     * or <CODE>preRegister</CODE>).     *     * @return The root object identifier.     */    public long[] getRootOid() {                if( rootOid == null) {            Vector list= new Vector(10);            // Ask the tree to do the job !            //            root.getRootOid(list);            // Now format the result            //            rootOid= new long[list.size()];            int i=0;            for(Enumeration e= list.elements(); e.hasMoreElements(); ) {                Integer val= (Integer) e.nextElement();                rootOid[i++]= val.longValue();            }        }        return rootOid;    }      // --------------------------------------------------------------------    // PRIVATE METHODS    //---------------------------------------------------------------------    /**     * This method builds the temporary request-tree that will be used to     * perform the SNMP request associated with the given vector of varbinds     * `list'.      *     * @param req The SnmpMibRequest object holding the varbind list      *             concerning this MIB.     * @param createflag Indicates whether the operation allow for creation     *        of new instances (ie: it is a SET).     * @param atomic Indicates whether the operation is atomic or not.     * @param type Request type (from SnmpDefinitions).     *     * @return The request-tree where the original varbind list has been     *         dispatched to the appropriate nodes.     */    private SnmpRequestTree getHandlers(SnmpMibRequest req, 					boolean createflag, boolean atomic,					int type) 	throws SnmpStatusException {	// Build an empty request tree	SnmpRequestTree handlers = 	    new SnmpRequestTree(req,createflag,type);        int index=0;        SnmpVarBind var = null;        final int ver= req.getVersion();	// For each varbind in the list finds its handling node.        for (Enumeration e= req.getElements(); e.hasMoreElements(); index++) {            var= (SnmpVarBind) e.nextElement();            try {		// Find the handling node for this varbind.                root.findHandlingNode(var,var.oid.longValue(false),				      0,handlers);            } catch(SnmpStatusException x) {		if (isDebugOn()) 		    debug("getHandlers","Couldn't find a handling node for "			  + var.oid.toString());		// If the operation is atomic (Check/Set) or the version		// is V1 we must generate an exception.		//                if (ver == SnmpDefinitions.snmpVersionOne) {		    if (isDebugOn()) 			debug("getHandlers","\tV1: Throwing exception");		    // The index in the exception must correspond to the 		    // SNMP index ...		    //		    final SnmpStatusException sse = 			new SnmpStatusException(x, index + 1);		    sse.initCause(x);		    throw sse;		} else if ((type == SnmpDefinitions.pduWalkRequest)   ||			   (type == SnmpDefinitions.pduSetRequestPdu)) {		    final int status = 			SnmpRequestTree.mapSetException(x.getStatus(),ver); 		    if (isDebugOn()) 			debug("getHandlers","\tSET: Throwing exception");		    final SnmpStatusException sse = 			new SnmpStatusException(status, index + 1);		    sse.initCause(x);		    throw sse;		} else if (atomic) {		    // Should never come here... 		    if (isDebugOn()) 			debug("getHandlers","\tATOMIC: Throwing exception");		    final SnmpStatusException sse = 			new SnmpStatusException(x, index + 1);		    sse.initCause(x);		    throw sse;		}		final int status = 		    SnmpRequestTree.mapGetException(x.getStatus(),ver);		    		if (status == SnmpStatusException.noSuchInstance) {		    if (isDebugOn()) 			debug("getHandlers", 			      "\tGET: Registering noSuchInstance");		    var.value= SnmpVarBind.noSuchInstance;		} else if (status == SnmpStatusException.noSuchObject) {					    if (isDebugOn()) 			debug("getHandlers",			      "\tGET: Registering noSuchObject");			var.value= SnmpVarBind.noSuchObject;		} else {		    if (isDebugOn()) 			debug("getHandlers",			      "\tGET: Registering global error: "			      + status);		    final SnmpStatusException sse = 			new SnmpStatusException(status, index + 1);		    sse.initCause(x);		    throw sse;		}	    }        }	return handlers;    }    /**     * This method builds the temporary request-tree that will be used to     * perform the SNMP GET-NEXT request associated with the given vector      * of varbinds `list'.      *     * @param req The SnmpMibRequest object holding the varbind list      *             concerning this MIB.     *     * @return The request-tree where the original varbind list has been     *         dispatched to the appropriate nodes, and where the original     *         OIDs have been replaced with the correct "next" OID.     */    private SnmpRequestTree getGetNextHandlers(SnmpMibRequest req)	throws SnmpStatusException {	// Creates an empty request tree, no entry creation is allowed (false)	SnmpRequestTree handlers = new 	    SnmpRequestTree(req,false,SnmpDefinitions.pduGetNextRequestPdu);	// Sets the getNext flag: if version=V2, status exception are 	// transformed in  endOfMibView	handlers.setGetNextFlag();	if (isDebugOn()) 	    debug("getGetNextHandlers","Received MIB request : " + req);	AcmChecker checker = new AcmChecker(req);	int index=0;        SnmpVarBind var = null;        final int ver= req.getVersion();	SnmpOid original = null;	// For each varbind, finds the handling node.	// This function has the side effect of transforming a GET-NEXT	// request into a valid GET request, replacing the OIDs in the	// original GET-NEXT request with the OID of the first leaf that	// follows.        for (Enumeration e= req.getElements(); e.hasMoreElements(); index++) {            var = (SnmpVarBind) e.nextElement();	    SnmpOid result = null;            try {		// Find the node handling the OID that follows the varbind		// OID. `result' contains this next leaf OID.		//ACM loop.		if (isDebugOn()) 		    debug("getGetNextHandlers"," Next Oid of :" + var.oid);		result = new SnmpOid(root.findNextHandlingNode				     (var,var.oid.longValue(false),0,				      0,handlers, checker));				if (isDebugOn()) 		    debug("getGetNextHandlers"," is :" + result);		// We replace the varbind original OID with the OID of the		// leaf object we have to return.		var.oid = result;            } catch(SnmpStatusException x) {		// if (isDebugOn()) 		//    debug("getGetNextHandlers",		//	  "Couldn't find a handling node for "		//	  + var.oid.toString());		                if (ver == SnmpDefinitions.snmpVersionOne) {		    if (isDebugOn()) 			debug("getGetNextHandlers","\tThrowing exception" + 			      x.toString());		    // The index in the exception must correspond to the 		    // SNMP index ...		    //                    throw new SnmpStatusException(x, index + 1);		}		if (isDebugOn()) 		    debug("getGetNextHandlers","Exception : " + x.getStatus());		                var.setSnmpValue(SnmpVarBind.endOfMibView);            }           }	return handlers;    }        // Returns true if debug is on    private final static boolean isDebugOn() {        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP);    }    // Prints a debug message    private final static void debug(String func, String info) {        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, 		   "SnmpMib", func, info);    }    // --------------------------------------------------------------------    // PROTECTED VARIABLES    // --------------------------------------------------------------------    /**     * The top element in the Mib tree.     * @serial     */    protected SnmpMibOid root;      // --------------------------------------------------------------------    // PRIVATE VARIABLES    // --------------------------------------------------------------------    /**     * The root object identifier of the MIB.     */    private transient long[] rootOid= null;} 

⌨️ 快捷键说明

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