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

📄 snmprequesttree.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }    //-------------------------------------------------------------------    // Tells whether we are currently processing a SET request (check/set)    //-------------------------------------------------------------------    public boolean isSetRequest() {	return setreqflag;    }    //-------------------------------------------------------------------    // Returns the protocol version in which the original request is     // evaluated.    //-------------------------------------------------------------------    public int getVersion() {	return version;    }    //-------------------------------------------------------------------    // Returns the actual protocol version of the request PDU.    //-------------------------------------------------------------------    public int getRequestPduVersion() {	return request.getRequestPduVersion();    }    //-------------------------------------------------------------------    // Returns the SnmpMibNode associated with the given handler    //-------------------------------------------------------------------    public SnmpMibNode getMetaNode(Handler handler) {	return handler.meta;    }    //-------------------------------------------------------------------    // Indicates the depth of the arc in the OID that identifies the     // SnmpMibNode associated with the given handler    //-------------------------------------------------------------------    public int getOidDepth(Handler handler) {	return handler.depth;    }    //-------------------------------------------------------------------    // returns an enumeration of the SnmpMibSubRequest's to be invoked on    // the SnmpMibNode associated with a given Handler node.     // If this node is a group, there will be a single subrequest.    // If it is a table, there will be one subrequest per entry involved.    //-------------------------------------------------------------------    public Enumeration getSubRequests(Handler handler) {	return new Enum(this,handler);    }    //-------------------------------------------------------------------    // returns an enumeration of the Handlers stored in the Hashtable.    //-------------------------------------------------------------------    public Enumeration getHandlers() {	return hashtable.elements();    }    //-------------------------------------------------------------------    // adds a varbind to a handler node sublist    //-------------------------------------------------------------------    public void add(SnmpMibNode meta, int depth, SnmpVarBind varbind)	throws SnmpStatusException {	registerNode(meta,depth,null,varbind,false,null);    }    //-------------------------------------------------------------------    // adds an entry varbind to a handler node sublist    //-------------------------------------------------------------------    public void add(SnmpMibNode meta, int depth, SnmpOid entryoid,		    SnmpVarBind varbind, boolean isnew) 	throws SnmpStatusException {	registerNode(meta,depth,entryoid,varbind,isnew,null);    }    //-------------------------------------------------------------------    // adds an entry varbind to a handler node sublist - specifying the    // varbind which holds the row status    //-------------------------------------------------------------------    public void add(SnmpMibNode meta, int depth, SnmpOid entryoid,		    SnmpVarBind varbind, boolean isnew, 		    SnmpVarBind statusvb)     	throws SnmpStatusException {	registerNode(meta,depth,entryoid,varbind,isnew,statusvb);    }    //-------------------------------------------------------------------    //-------------------------------------------------------------------    // Protected interface    //-------------------------------------------------------------------    //-------------------------------------------------------------------    //-------------------------------------------------------------------    // Type of the request (see SnmpDefinitions)    //-------------------------------------------------------------------    void setPduType(int pduType) {	type = pduType;	setreqflag = ((pduType == SnmpDefinitions.pduWalkRequest) ||	    (pduType == SnmpDefinitions.pduSetRequestPdu));    }    //-------------------------------------------------------------------    // We deal with a GET-NEXT request    //-------------------------------------------------------------------    void setGetNextFlag() {	getnextflag = true;    }        //-------------------------------------------------------------------    // Tell whether creation is allowed.    //-------------------------------------------------------------------     void switchCreationFlag(boolean flag) {	creationflag = flag;    }    //-------------------------------------------------------------------    // Returns the subrequest handled by the SnmpMibNode itself    // (in principle, only for Groups)    //-------------------------------------------------------------------    SnmpMibSubRequest getSubRequest(Handler handler) {	if (handler == null) return null;	return new SnmpMibSubRequestImpl(request,handler.getSubList(),				      null,false,getnextflag,null);    }    //-------------------------------------------------------------------    // Returns the subrequest associated with the entry identified by    // the given entry (only for tables)    //-------------------------------------------------------------------    SnmpMibSubRequest getSubRequest(Handler handler, SnmpOid oid) {	if (handler == null) return null;	final int pos = handler.getEntryPos(oid);	if (pos == -1) return null;	return new SnmpMibSubRequestImpl(request,					 handler.getEntrySubList(pos),					 handler.getEntryOid(pos),					 handler.isNewEntry(pos),					 getnextflag,					 handler.getRowStatusVarBind(pos));    }    //-------------------------------------------------------------------    // Returns the subrequest associated with the entry identified by    // the given entry (only for tables). The `entry' parameter is an    // index relative to the position of the entry in the handler sublist.    //-------------------------------------------------------------------    SnmpMibSubRequest getSubRequest(Handler handler, int entry) {	if (handler == null) return null;	return new 	    SnmpMibSubRequestImpl(request,handler.getEntrySubList(entry),				  handler.getEntryOid(entry),				  handler.isNewEntry(entry),getnextflag,				  handler.getRowStatusVarBind(entry));    }    //-------------------------------------------------------------------    //-------------------------------------------------------------------    // Private section    //-------------------------------------------------------------------    //-------------------------------------------------------------------    //-------------------------------------------------------------------    // stores a handler node in the Hashtable    //-------------------------------------------------------------------    private void put(Object key, Handler handler) {	if (handler == null) return;	if (key == null) return;	if (hashtable == null) hashtable = new Hashtable();	hashtable.put(key,handler);    }    //-------------------------------------------------------------------    // finds a handler node in the Hashtable    //-------------------------------------------------------------------    private Handler get(Object key) {	if (key == null) return null;	if (hashtable == null) return null;	return (Handler) hashtable.get(key);    }    //-------------------------------------------------------------------    // Search for the given oid in `oids'. If none is found, returns -1    // otherwise, returns the index at which the oid is located.    //-------------------------------------------------------------------    private static int findOid(SnmpOid[] oids, int count, SnmpOid oid) {	final int size = count;        int low= 0;        int max= size - 1;        int curr= low + (max-low)/2;        //System.out.println("Try to retrieve: " + oid.toString());        while (low <= max) {            final SnmpOid pos = oids[curr];                  //System.out.println("Compare with" + pos.toString());            // never know ...we might find something ...            //            final int comp = oid.compareTo(pos);            if (comp == 0)                return curr;                  if (oid.equals(pos)) {                return curr;            }            if (comp > 0) {                low = curr + 1;            } else {                max = curr - 1;            }            curr = low + (max-low)/2;        }        return -1;    }    //-------------------------------------------------------------------    // Return the index at which the given oid should be inserted in the    // `oids' array.    //-------------------------------------------------------------------    private static int getInsertionPoint(SnmpOid[] oids, int count, 					 SnmpOid oid) {	final SnmpOid[] localoids = oids;	final int size = count;        int low= 0;        int max= size - 1;        int curr= low + (max-low)/2;        while (low <= max) {                  final SnmpOid pos = localoids[curr];                  // never know ...we might find something ...            //            final int comp= oid.compareTo(pos);	    // In the calling method we will have to check for this case...            //    if (comp == 0)            //       return -1;	    // Returning curr instead of -1 avoids having to call	    // findOid() first and getInsertionPoint() afterwards.	    // We can simply call getInsertionPoint() and then checks whether	    // there's an OID at the returned position which equals the	    // given OID.            if (comp == 0)                return curr;                  if (comp>0) {                low= curr +1;            } else {                max= curr -1;            }            curr= low + (max-low)/2;        }        return curr;    }    //-------------------------------------------------------------------    // adds a varbind in a handler node sublist    //-------------------------------------------------------------------    private void registerNode(SnmpMibNode meta, int depth, SnmpOid entryoid,			      SnmpVarBind varbind, boolean isnew, 			      SnmpVarBind statusvb) 	throws SnmpStatusException {	if (meta == null) {	    if (isDebugOn())		debug("registerNode","meta-node is null!!!");	    return;	}	if (varbind == null) {	    if (isDebugOn())		debug("registerNode","varbind is null!!!");	    return ;	}	final Object key = meta;	// retrieve the handler node associated with the given meta, 	// if any	Handler handler = get(key);	// If no handler node was found for that meta, create one.	if (handler == null) {	    // if (isDebugOn())             //    debug("registerNode", "adding node for " +	    //          varbind.oid.toString());	    handler = new Handler(type);	    handler.meta  = meta;	    handler.depth = depth;	    put(key,handler);	} 	// else {	//   if (isDebugOn()) 	//	debug("registerNode","found node for " +	//	      varbind.oid.toString());	// }	// Adds the varbind in the handler node's sublist.	if (entryoid == null) 	    handler.addVarbind(varbind);	else 	    handler.addVarbind(varbind,entryoid,isnew,statusvb);	return ;    }        private final static boolean isDebugOn() {        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP);    }    private final static void debug(String func, String info) {        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, 		   "SnmpRequestTree", func, info);    }    //-------------------------------------------------------------------    // private variables    //-------------------------------------------------------------------    private Hashtable hashtable    = null;   // Hashtable of Handler objects    private SnmpMibRequest request = null;   // The original list of varbinds    private int       version      = 0;      // The protocol version    private boolean   creationflag = false;  // Does the operation allow                                              // creation of entries    private boolean   getnextflag  = false;  // Does the operation allow                                              // creation of entries    private int       type         = 0;      // Request PDU type as defined                                             // in SnmpDefinitions    private boolean   setreqflag   = false;  // True if we're processing a                                             // SET request (check/set).}

⌨️ 快捷键说明

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