FileDocCategorySizeDatePackage
SnmpSubBulkRequestHandler.javaAPI DocJava SE 5 API9020Fri Aug 26 14:55:06 BST 2005com.sun.jmx.snmp.daemon

SnmpSubBulkRequestHandler

public class SnmpSubBulkRequestHandler extends SnmpSubRequestHandler

Fields Summary
private com.sun.jmx.snmp.daemon.SnmpAdaptorServer
server
protected int
nonRepeat
Specific to the sub request
protected int
maxRepeat
protected int
globalR
R as defined in RCF 1902 for the global request the sub-request is associated to.
protected int
size
Constructors Summary
protected SnmpSubBulkRequestHandler(com.sun.jmx.snmp.SnmpEngine engine, com.sun.jmx.snmp.daemon.SnmpAdaptorServer server, com.sun.jmx.snmp.internal.SnmpIncomingRequest incRequest, com.sun.jmx.snmp.agent.SnmpMibAgent agent, com.sun.jmx.snmp.SnmpPdu req, int nonRepeat, int maxRepeat, int R)
The constuctor initialize the subrequest with the whole varbind list contained in the original request.


                        
      
					 
					 
					  
					  
					 
                                          
					  
	super(engine, incRequest, agent, req);
	init(server, req, nonRepeat, maxRepeat, R);
    
protected SnmpSubBulkRequestHandler(com.sun.jmx.snmp.daemon.SnmpAdaptorServer server, com.sun.jmx.snmp.agent.SnmpMibAgent agent, com.sun.jmx.snmp.SnmpPdu req, int nonRepeat, int maxRepeat, int R)
The constuctor initialize the subrequest with the whole varbind list contained in the original request.

	super(agent, req);
	init(server, req, nonRepeat, maxRepeat, R);
    
Methods Summary
private com.sun.jmx.snmp.SnmpVarBindfindVarBind(com.sun.jmx.snmp.SnmpVarBind element, com.sun.jmx.snmp.SnmpVarBind result)
The method updates find out which element to use at update time. Handle oid overlapping as well

	
	if (element == null) return null;

	if (result.oid == null) {
	     return element;
	}

	if (element.value == SnmpVarBind.endOfMibView) return result;

	if (result.value == SnmpVarBind.endOfMibView) return element;

	final SnmpValue val = result.value;

	int comp = element.oid.compareTo(result.oid);
	if(isDebugOn()) {
	    trace("findVarBind","Comparing OID element : " + element.oid +
		  " with result : " + result.oid);
	    trace("findVarBind","Values element : " + element.value +
		  " result : " + result.value);
	}
	if (comp < 0) {
	    // Take the smallest (lexicographically)
	    //
	    return element;
	}
	else {
	    if(comp == 0) {
		// Must compare agent used for reply
		// Take the deeper within the reply
		if(isDebugOn()) {
		    trace("findVarBind"," oid overlapping. Oid : " + 
			  element.oid + "value :" + element.value);
		    trace("findVarBind","Already present varBind : " + 
			  result);
		}
		SnmpOid oid = result.oid;
		SnmpMibAgent deeperAgent = server.getAgentMib(oid);

		if(isDebugOn())
		    trace("findVarBind","Deeper agent : " + deeperAgent);
		if(deeperAgent == agent) {
		    if(isDebugOn())
			trace("updateResult","The current agent is the deeper one. Update the value with the current one");
		    return element;
		} else {
		    if(isDebugOn())
			trace("updateResult","Current is not the deeper, return the previous one.");
		    return result;
		}
		    
		/*
		   Vector v = new Vector();
		   SnmpMibRequest getReq = createMibRequest(v,
		   version,
		   null);
		   SnmpVarBind realValue = new SnmpVarBind(oid);
		   getReq.addVarBind(realValue);
		   try {
		   deeperAgent.get(getReq);
		   } catch(SnmpStatusException e) {
		   e.printStackTrace();
		   }
		   
		   if(isDebugOn())
		   trace("findVarBind", "Biggest priority value is : " +  
		   realValue.value);
		   
		   return realValue;
		*/
		
	    }
	    else {
		if(isDebugOn())
		    trace("findVarBind",
			  "The right varBind is the already present one");
		return result;
	    }
	}
    
private voidinit(com.sun.jmx.snmp.daemon.SnmpAdaptorServer server, com.sun.jmx.snmp.SnmpPdu req, int nonRepeat, int maxRepeat, int R)

	this.server = server;
        this.nonRepeat= nonRepeat;
        this.maxRepeat= maxRepeat;  
        this.globalR= R;
	
	final int max= translation.length;
        final SnmpVarBind[] list= req.varBindList;
        final NonSyncVector nonSyncVarBind = ((NonSyncVector)varBind);
        for(int i=0; i < max; i++) {
            translation[i]= i;
            // we need to allocate a new SnmpVarBind. Otherwise the first
            // sub request will modify the list...
            //
	    final SnmpVarBind newVarBind = 
		new SnmpVarBind(list[i].oid, list[i].value);
            nonSyncVarBind.addNonSyncElement(newVarBind);
        }
    
protected java.lang.StringmakeDebugTag()

        return "SnmpSubBulkRequestHandler";
    
public voidrun()

    
        size= varBind.size();
    
        try {
            // Invoke a getBulk operation
            //
	    /* NPCTE fix for bugId 4492741, esc 0, 16-August-2001 */
	    final ThreadContext oldContext =
                ThreadContext.push("SnmpUserData",data);
	    try {
		if (isTraceOn()) {
                	trace("run", "[" + Thread.currentThread() + 
			"]:getBulk operation on " + agent.getMibName());
		}
		agent.getBulk(createMibRequest(varBind,version,data), 
			      nonRepeat, maxRepeat);
	    } finally {
                ThreadContext.restore(oldContext);
            }  
	    /* end of NPCTE fix for bugId 4492741 */
	    
        } catch(SnmpStatusException x) {
            errorStatus = x.getStatus() ;
            errorIndex=  x.getErrorIndex();
            if (isDebugOn()) {
                debug("run", "[" + Thread.currentThread() + 
		      "]:an Snmp error occured during the operation");
                debug("run", x);
            }
        }
        catch(Exception x) {
            errorStatus = SnmpDefinitions.snmpRspGenErr ;
            if (isDebugOn()) {
                debug("run", "[" + Thread.currentThread() + 
		      "]:a generic error occured during the operation");
                debug("run", x);
            }
        }
        if (isTraceOn()) {
            trace("run", "[" + Thread.currentThread() + 
		  "]:operation completed");
        }
    
protected voidupdateResult(com.sun.jmx.snmp.SnmpVarBind[] result)
The method updates a given var bind list with the result of a previsouly invoked operation. Prior to calling the method, one must make sure that the operation was successful. As such the method getErrorIndex or getErrorStatus should be called.

	// we can assume that the run method is over ...
        // 

        final Enumeration e= varBind.elements();
        final int max= result.length;

        // First go through all the values once ...
        for(int i=0; i < size; i++) {
            // May be we should control the position ...
            //
            if (e.hasMoreElements() == false)
                return;

	    // bugId 4641694: must check position in order to avoid 
	    //       ArrayIndexOutOfBoundException
	    final int pos=translation[i];
	    if (pos >= max) {
		debug("updateResult","Position `"+pos+"' is out of bound...");
		continue;
	    }

	    final SnmpVarBind element= (SnmpVarBind) e.nextElement();
	    
	    if (element == null) continue;
	    if (isDebugOn())
		trace("updateResult", "Non repeaters Current element : " + 
		      element + " from agent : " + agent);
	    final SnmpVarBind res = findVarBind(element,result[pos]);
	    
	    if(res == null) continue;
	    
	    result[pos] = res;
	}
 
        // Now update the values which have been repeated
        // more than once.
        int localR= size - nonRepeat;
        for (int i = 2 ; i <= maxRepeat ; i++) {
            for (int r = 0 ; r < localR ; r++) {
                final int pos = (i-1)* globalR + translation[nonRepeat + r] ;
                if (pos >= max)
                    return;
                if (e.hasMoreElements() ==false)
                    return;
                final SnmpVarBind element= (SnmpVarBind) e.nextElement();
		
		if (element == null) continue;
		if (isDebugOn())
		    trace("updateResult", "Repeaters Current element : " + 
			  element + " from agent : " + agent);
		final SnmpVarBind res = findVarBind(element, result[pos]);
		
		if(res == null) continue;
	    
		result[pos] = res;
            }
        }