[jboss-cvs] JBossAS SVN: r109573 - 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
Tue Nov 30 16:57:06 EST 2010


Author: thauser at redhat.com
Date: 2010-11-30 16:57:06 -0500 (Tue, 30 Nov 2010)
New Revision: 109573

Modified:
   branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
Log:
changes to the value returned after a failed set operation.

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-30 21:36:20 UTC (rev 109572)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2010-11-30 21:57:06 UTC (rev 109573)
@@ -344,7 +344,11 @@
 				try{
 				var = setValueFor(oid,newVal);
 				}
-				catch (ReadOnlyException e){log.debug("attempt to set a read-only attribute: " + newVB);}
+				catch (ReadOnlyException e){
+					log.debug("attempt to set a read-only attribute: " + newVB);
+					response = null;
+					return response;
+				}
 				
 				if (var != null){
 					log.debug("attempt to set value resulted in a null PDU being returned.");
@@ -582,41 +586,46 @@
 			try
         {
 			   Object val = server.getAttribute(be.mbean, be.attr.getName());
-// TODO: refactor all this type hogwash into a new method or even a new class.
-				if (val instanceof Long)
-           {
-					Long uin = (Long) val;
+			   ssy = prepForPdu(val);
+/*	// TODO: refactor all this type hogwash into a new method or even a new class.
+					if (val instanceof Long)
+	           {
+						Long uin = (Long) val;
+						
+						//consider Counter64 if there's problems
+						ssy = new Counter32(uin);
+					}
+	           else if (val instanceof String)
+	           {
+						String in = (String) val;
+						ssy = new OctetString(in.getBytes());
+					}
+	           else if (val instanceof Integer)
+	           {
+						Integer in = (Integer) val;
+						ssy = new Integer32(in);
+					}
 					
-					//consider Counter64 if there's problems
-					ssy = new Counter32(uin);
+					//not sure about how to handle this case yet
+	           else if (val instanceof OID)     
+	           {
+	        	   		ssy = new OID((OID)val);
+	           }
+	           else if (val instanceof TimeTicks)
+	           {
+	              ssy = (TimeTicks)val;
+	           }
+	           else if (val instanceof Counter32)
+	           {
+	        	   ssy = (Counter32) val;
+	           }
+	           else
+						log.info("Unknown type for " + be);*/
+				if (val == null){
+					log.info("Unknown type for " + be);
 				}
-           else if (val instanceof String)
-           {
-					String in = (String) val;
-					ssy = new OctetString(in.getBytes());
 				}
-           else if (val instanceof Integer)
-           {
-					Integer in = (Integer) val;
-					ssy = new Integer32(in);
-				}
-				
-				//not sure about how to handle this case yet
-           else if (val instanceof OID)     
-           {
-        	   		ssy = new OID((OID)val);
-           }
-           else if (val instanceof TimeTicks)
-           {
-              ssy = (TimeTicks)val;
-           }
-           else if (val instanceof Counter32)
-           {
-        	   ssy = (Counter32) val;
-           }
-           else
-					log.info("Unknown type for " + be);
-			}
+
         catch (Exception e)
         {
 				log.warn("getValueFor (" + be.mbean.toString() + ", "
@@ -691,13 +700,56 @@
 //		return ssy;
 //	}
 	
+	/**This method takes an Object that is typically going to be 
+	 * put into a VariableBinding for use in a PDU, and thus must be converted
+	 * into an SNMP type based on it's type. This Object is usually read 
+	 * from the MBean server.
+	 *  
+	 * @param val The value needing conversion. 
+	 * @return the converted value. null on failure.
+	 * 
+	 */
+	
+	private Variable prepForPdu(final Object val){
+		Variable result = null;
+		if (val instanceof Long)
+        {
+			result = new Counter32((Long)val);
+		}
+        else if (val instanceof String)
+        {
+        	result = new OctetString((String) val);
+		}
+        else if (val instanceof Integer)
+        {
+			result = new Integer32((Integer)val);
+		}
+        else if (val instanceof OID)     
+        {
+        	result = new OID((OID)val);
+        }
+        else if (val instanceof TimeTicks)
+        {
+        	result = (TimeTicks)val;
+        }
+        else if (val instanceof Counter32)
+        {
+     	   	result = (Counter32) val;
+        }
+        else
+        {
+        	result = null;
+        }
+		return result;
+	}	
+	
 	/** 
-	 * Get a proper type of variable based on an input variable from a 
-	 * VariableBinding.
+	 * Takes an instance of org.snmp4j.smi.Variable and returns a Java Class
+	 * representation. This is used to set mbean values given a PDU.
 	 * @param val the value to be converted
 	 * @return an Object created with the proper type. null if failure
 	 */
-	private Object convertValue(final Variable val){
+	private Object convertVariableToValue(final Variable val){
 		Object result = null;
 		if (val instanceof OctetString)
 		{	
@@ -759,7 +811,7 @@
 			try
          {		
 				
-			Object val = convertValue(newVal);
+			Object val = convertVariableToValue(newVal);
 		
 				if (val != null)
             { 
@@ -778,7 +830,7 @@
 			catch (Exception e )
          {
 				log.debug("setValueFor: exception " + e.getMessage());
-				ssy = newVal;
+				ssy = null;
 			}
 		}
 		else



More information about the jboss-cvs-commits mailing list