[jboss-cvs] JBossAS SVN: r109459 - branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Nov 24 15:07:26 EST 2010


Author: thauser at redhat.com
Date: 2010-11-24 15:07:25 -0500 (Wed, 24 Nov 2010)
New Revision: 109459

Modified:
   branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
Log:
added support for Snmp set requests on rw attributes.

Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2010-11-24 18:59:51 UTC (rev 109458)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2010-11-24 20:07:25 UTC (rev 109459)
@@ -86,6 +86,7 @@
 	/** Has this RequestHandler instance been initialized? */
 	private boolean initialized = false;
 
+
 	// Constructors --------------------------------------------------
 
 	/**
@@ -305,7 +306,50 @@
 	 *         cannot process NOTE: this might be changed to throw an exception.
 	 */
 	public PDU snmpReceivedSet(PDU pdu)
-   {return null;
+   {
+		PDU response;
+		Variable var = null;
+		if (pdu instanceof ScopedPDU){
+			response = DefaultPDUFactory.createPDU(SnmpConstants.version3);
+		} else if (pdu instanceof PDUv1){
+			response = DefaultPDUFactory.createPDU(SnmpConstants.version1);
+		} else {
+			response = new PDU();
+		} 
+		response.setType(PDU.RESPONSE);
+		
+		final boolean trace = log.isTraceEnabled();
+		
+		if (trace) {
+			log.trace("requestID=" + pdu.getRequestID() + ", elementCount="
+					+ pdu.size());
+		}
+		
+		if (pdu != null){
+			//iterate through the VB in this PDU
+			Iterator it = pdu.getVariableBindings().iterator();
+			
+			while (it.hasNext()){
+				VariableBinding vb = (VariableBinding)it.next();
+				OID oid = vb.getOid();
+				Variable newVal = vb.getVariable();
+				//setup the new variable binding to put into the response pdu
+				VariableBinding newVB = new VariableBinding(oid,newVal);
+				
+				//some errorchecking ....
+				//else is good and do:
+				try{
+				var = setValueFor(oid,newVal);
+				}
+				catch (ReadOnlyException e){log.debug("ReadOnlyException in RequestHandlerImpl");}
+				//null on success. change this;
+			//	newVB.setVariable(var);
+				response.add(newVB);
+			}
+		}
+			
+			
+		//return null;
 //		final boolean trace = log.isTraceEnabled();
 //		SnmpPduRequest response = null;
 //		int errorStatus = SnmpPduPacket.ErrNoError;
@@ -349,7 +393,7 @@
 //		response.setErrorStatus(errorStatus);
 //		response.setErrorIndex(errorIndex);
 //
-//		return response;
+		return response;
 	}
 
 	/**
@@ -642,72 +686,77 @@
 //	 * @return null on success, non-null on failure
 //	 * @throws ReadOnlyException If the referred entry is read only.
 //	 */
-//	private SnmpSyntax setValueFor(final OID oid, final SnmpSyntax newVal) throws ReadOnlyException
-//   {
-//		final boolean trace = log.isTraceEnabled();
-//		
-//		BindEntry be = findBindEntryForOid(oid);
-//		
-//		if (trace)
-//			log.trace("setValueFor: found bind entry for " + oid);
-//		
-//		if (be != null)
-//      {
-//			if (trace)
-//				log.trace("setValueFor: " + be.toString());
-//         
-//			if (be.isReadWrite == false)
-//         {
-//				if (trace)
-//					log.trace("setValueFor: this is marked read only");
-//            
-//				throw new ReadOnlyException(oid);
-//			}
-//			try
-//         {		
-//				
-//				Object val = null;
-//				if (newVal instanceof OctetString)
-//            {
-//					val = newVal.toString();
-//				}
-//				else if (newVal instanceof Integer32)
-//            {
-//					val = new Integer(((Integer32)newVal).getValue());
-//				}
-//				else if (newVal instanceof Counter32)
-//            {
-//					val = new Long(((Counter32)newVal).getValue());
-//				}
-//				// TODO do more mumbo jumbo for type casting / changing
-//				
-//				if (val != null)
-//            { 
-//					Attribute at = new Attribute(be.attr.getName(), val);
-//					server.setAttribute(be.mbean, at);
-//					if (trace)
-//						log.trace("setValueFor: set attribute in mbean-Server");
-//				}
-//				else
-//            {
-//					log.debug("Did not find a suitable data type for newVal " + newVal);
-//					ssy = new SnmpNull();
-//				}
-//				// TODO
-//			}
-//			catch (Exception e )
-//         {
-//				log.debug("setValueFor: exception " + e.getMessage());
-//				ssy = new SnmpNull();
-//			}
-//		}
-//		else
-//      {
-//			ssy = new SnmpNull();
-//			log.info(NO_ENTRY_FOUND_FOR_OID + oid);
-//		}
-//		return ssy;
-//	}
+	private Variable setValueFor(final OID oid, final Variable newVal) throws ReadOnlyException
+   {
+		final boolean trace = log.isTraceEnabled();
+		
+		BindEntry be = findBindEntryForOid(oid);
+		Variable ssy = null;
+		
+		if (trace)
+			log.trace("setValueFor: found bind entry for " + oid);
+		
+		if (be != null)
+      {
+			if (trace)
+				log.trace("setValueFor: " + be.toString());
+         
+			if (be.isReadWrite == false)
+         {
+				if (trace)
+					log.trace("setValueFor: this is marked read only");
+            
+				throw new ReadOnlyException(oid);
+			}
+			try
+         {		
+				
+				Object val = null;
+				if (newVal instanceof OctetString)
+            {
+					val = newVal.toString();
+				}
+				else if (newVal instanceof Integer32)
+            {
+					val = new Integer(((Integer32)newVal).getValue());
+				}
+				else if (newVal instanceof Counter32)
+            {
+					val = new Long(((Counter32)newVal).getValue());
+				}
+				else if (newVal instanceof Counter64)
+				{
+					val = new Long(((Counter64)newVal).getValue());
+				}
+				// TODO do more mumbo jumbo for type casting / changing
+				
+				if (val != null)
+            { 
+					Attribute at = new Attribute(be.attr.getName(), val);
+					server.setAttribute(be.mbean, at);
+					if (trace)
+						log.trace("setValueFor: set attribute in mbean-Server");
+				}
+				else
+            {
+					log.debug("Did not find a suitable data type for newVal " + newVal);
+					ssy = newVal;
+			}
+				// TODO
+			}
+			catch (Exception e )
+         {
+				log.debug("setValueFor: exception " + e.getMessage());
+				ssy = newVal;
+			}
+		}
+		else
+      {
+			ssy = newVal;
+			log.info(NO_ENTRY_FOUND_FOR_OID + oid);
+		}
+		return ssy;
+	}
 
 
 	/**



More information about the jboss-cvs-commits mailing list