changeset 9053:b8008a2bf4fe

7068126: Enhance SNMP statuses Reviewed-by: dfuchs, hawtin
author sjiang
date Mon, 21 Oct 2013 09:56:06 +0200
parents d4f4a9915357
children d7ef65d3ee57
files src/share/classes/com/sun/jmx/snmp/agent/SnmpMibEntry.java src/share/classes/com/sun/jmx/snmp/agent/SnmpMibGroup.java src/share/classes/com/sun/jmx/snmp/agent/SnmpMibNode.java src/share/classes/com/sun/jmx/snmp/agent/SnmpMibOid.java src/share/classes/com/sun/jmx/snmp/agent/SnmpMibTable.java src/share/classes/com/sun/jmx/snmp/daemon/SnmpRequestHandler.java
diffstat 6 files changed, 88 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibEntry.java	Thu Oct 17 09:23:49 2013 -0700
+++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibEntry.java	Mon Oct 21 09:56:06 2013 +0200
@@ -27,17 +27,9 @@
 
 // java imports
 //
+import com.sun.jmx.snmp.SnmpDefinitions;
 import java.io.Serializable;
-import java.util.Hashtable;
-import java.util.Enumeration;
-
-// jmx imports
-//
-import com.sun.jmx.snmp.SnmpValue;
-import com.sun.jmx.snmp.SnmpVarBind;
 import com.sun.jmx.snmp.SnmpStatusException;
-import com.sun.jmx.snmp.agent.SnmpMibOid;
-import com.sun.jmx.snmp.agent.SnmpMibNode;
 
 /**
  * Represents a node in an SNMP MIB which corresponds to a table entry
@@ -99,7 +91,9 @@
      */
     public void validateVarId(long arc, Object userData)
         throws SnmpStatusException {
-        if (isVariable(arc) == false) throw noSuchNameException;
+        if (isVariable(arc) == false) {
+            throw new SnmpStatusException(SnmpDefinitions.snmpRspNoSuchName);
+        }
     }
 
     /**
--- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibGroup.java	Thu Oct 17 09:23:49 2013 -0700
+++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibGroup.java	Mon Oct 21 09:56:06 2013 +0200
@@ -108,8 +108,9 @@
      */
     public void validateVarId(long arc, Object userData)
         throws SnmpStatusException {
-        if (isVariable(arc) == false)
-            throw noSuchObjectException;
+        if (isVariable(arc) == false) {
+            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+        }
     }
 
 
@@ -360,17 +361,20 @@
             validateVarId(arc, data);
 
             // The trailing .0 is missing in the OID
-            if (depth+2 > length)
-                throw noSuchInstanceException;
+            if (depth+2 > length) {
+                throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
+            }
 
             // There are too many arcs left in the OID (there should remain
             // a single trailing .0)
-            if (depth+2 < length)
-                throw noSuchInstanceException;
+            if (depth+2 < length) {
+                throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
+            }
 
             // The last trailing arc is not .0
-            if (oid[depth+1] != 0L)
-                throw noSuchInstanceException;
+            if (oid[depth+1] != 0L) {
+                throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
+            }
 
             // It's one of our variable, register this node.
             handlers.add(this,depth,varbind);
@@ -389,12 +393,13 @@
         int length = oid.length;
         SnmpMibNode node = null;
 
-        if (handlers == null)
+        if (handlers == null) {
             // This should be considered as a genErr, but we do not want to
             // abort the whole request, so we're going to throw
             // a noSuchObject...
             //
-            throw noSuchObjectException;
+            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+        }
 
         final Object data = handlers.getUserData();
         final int pduVersion = handlers.getRequestPduVersion();
@@ -430,7 +435,7 @@
                                                         depth+1,handlers,
                                                         checker);
                 }catch(SnmpStatusException ex) {
-                    throw noSuchObjectException;
+                    throw new SnmpStatusException(SnmpStatusException.noSuchObject);
                 } finally {
                     checker.remove(depth);
                 }
@@ -455,7 +460,7 @@
                     try {
                         checker.checkCurrentOid();
                     } catch(SnmpStatusException e) {
-                        throw noSuchObjectException;
+                        throw new SnmpStatusException(SnmpStatusException.noSuchObject);
                     } finally {
                         checker.remove(depth,2);
                     }
@@ -500,7 +505,7 @@
             // The oid is not valid, we will throw an exception in order
             // to try with the next valid identifier...
             //
-            throw noSuchObjectException;
+            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
 
         } catch (SnmpStatusException e) {
             // We didn't find anything at the given arc, so we're going
--- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibNode.java	Thu Oct 17 09:23:49 2013 -0700
+++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibNode.java	Mon Oct 21 09:56:06 2013 +0200
@@ -155,7 +155,7 @@
                           long[] oid, int depth,
                           SnmpRequestTree handlers)
         throws SnmpStatusException {
-        throw noSuchObjectException;
+        throw new SnmpStatusException(SnmpStatusException.noSuchObject);
     }
 
     /**
@@ -183,7 +183,7 @@
                                  long[] oid, int pos, int depth,
                                  SnmpRequestTree handlers, AcmChecker checker)
         throws SnmpStatusException {
-        throw noSuchObjectException;
+        throw new SnmpStatusException(SnmpStatusException.noSuchObject);
     }
 
     /**
@@ -346,8 +346,9 @@
         final int[] a = table;
         final int val= (int) value;
 
-        if (a == null)
-            throw noSuchObjectException;
+        if (a == null) {
+            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+        }
 
         int low= 0;
         int max= a.length;
@@ -356,11 +357,13 @@
 
         // Basic check
         //
-        if (max < 1)
-            throw noSuchObjectException;
+        if (max < 1) {
+            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+        }
 
-        if (a[max-1] <= val)
-            throw noSuchObjectException;
+        if (a[max-1] <= val) {
+            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+        }
 
         while (low <= max) {
             elmt= a[curr];
@@ -400,15 +403,4 @@
      * Contains the list of variable identifiers.
      */
     protected int[] varList;
-
-    /**
-     * Contains a predefined exception that is often fired when an
-     * object is not found in the MIB.
-     */
-    static final protected SnmpStatusException noSuchInstanceException =
-        new SnmpStatusException(SnmpStatusException.noSuchInstance);
-    static final protected SnmpStatusException noSuchObjectException =
-        new SnmpStatusException(SnmpStatusException.noSuchObject);
-    static final protected SnmpStatusException noSuchNameException =
-        new SnmpStatusException(SnmpDefinitions.snmpRspNoSuchName);
 }
--- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibOid.java	Thu Oct 17 09:23:49 2013 -0700
+++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibOid.java	Mon Oct 21 09:56:06 2013 +0200
@@ -160,12 +160,10 @@
 
         if (depth > length) {
             // Nothing is left... the oid is not valid
-            throw noSuchObjectException;
-
+            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
         } else if (depth == length) {
             // The oid is not complete...
-            throw noSuchInstanceException;
-
+            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
         } else {
             // Some children variable or subobject is being querried
             // getChild() will raise an exception if no child is found.
@@ -205,12 +203,13 @@
         final int length = oid.length;
         SnmpMibNode node = null;
         long[] result = null;
-        if (handlers == null)
+        if (handlers == null) {
             // This should be considered as a genErr, but we do not want to
             // abort the whole request, so we're going to throw
             // a noSuchObject...
             //
-            throw noSuchObjectException;
+            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+        }
 
         final Object data = handlers.getUserData();
         final int pduVersion = handlers.getRequestPduVersion();
@@ -235,7 +234,7 @@
                 // SnmpOid result = null;
                 if (child == null) {
                     // shouldn't happen
-                    throw noSuchObjectException;
+                    throw new SnmpStatusException(SnmpStatusException.noSuchObject);
                     // validateVarId(index);
                     // handlers.add(this,varbind,depth);
                     // result = new SnmpOid(0);
@@ -444,11 +443,13 @@
         // first we need to retrieve the identifier in the list of children
         //
         final int pos= getInsertAt(id);
-        if (pos >= nbChildren)
-            throw noSuchObjectException;
+        if (pos >= nbChildren) {
+            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+        }
 
-        if (varList[pos] != (int) id)
-            throw noSuchObjectException;
+        if (varList[pos] != (int) id) {
+            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+        }
 
         // Access the node
         //
@@ -456,10 +457,11 @@
         try {
             child = children.elementAtNonSync(pos);
         } catch(ArrayIndexOutOfBoundsException e) {
-            throw noSuchObjectException;
+            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
         }
-        if (child == null)
-            throw noSuchInstanceException;
+        if (child == null) {
+            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
+        }
         return child;
     }
 
--- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibTable.java	Thu Oct 17 09:23:49 2013 -0700
+++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibTable.java	Mon Oct 21 09:56:06 2013 +0200
@@ -280,7 +280,7 @@
             SnmpVarBind var;
             for (Enumeration<SnmpVarBind> e= r.getElements(); e.hasMoreElements();) {
                 var = e.nextElement();
-                r.registerGetException(var,noSuchInstanceException);
+                r.registerGetException(var,new SnmpStatusException(SnmpStatusException.noSuchInstance));
             }
         }
 
@@ -1607,8 +1607,9 @@
     protected SnmpOid getNextOid(SnmpOid oid, Object userData)
         throws SnmpStatusException {
 
-        if (size == 0)
-            throw noSuchInstanceException;
+        if (size == 0) {
+            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
+        }
 
         final SnmpOid resOid = oid;
 
@@ -1619,7 +1620,7 @@
         if (last.equals(resOid)) {
             // Last element of the table ...
             //
-            throw noSuchInstanceException;
+            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
         }
 
         // First find the oid. This will allow to speed up retrieval process
@@ -1641,12 +1642,12 @@
                 // XX last = (SnmpOid) oids.elementAt(newPos);
                 last = tableoids[newPos];
             } catch(ArrayIndexOutOfBoundsException e) {
-                throw noSuchInstanceException;
+                throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
             }
         } else {
             // We are dealing with the last element of the table ..
             //
-            throw noSuchInstanceException;
+            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
         }
 
 
@@ -1668,8 +1669,9 @@
      */
     protected SnmpOid getNextOid(Object userData)
         throws SnmpStatusException {
-        if (size == 0)
-            throw noSuchInstanceException;
+        if (size == 0) {
+            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
+        }
         // XX return (SnmpOid) oids.firstElement();
         return tableoids[0];
     }
@@ -1875,10 +1877,10 @@
         // not support creation.
         // We know that the entry does not exists if (isentry == false).
         if (!hasEntry) {
-            if (!handlers.isCreationAllowed())
+            if (!handlers.isCreationAllowed()) {
                 // we're not doing a set
-                throw noSuchInstanceException;
-            else if (!isCreationEnabled())
+                throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
+            } else if (!isCreationEnabled())
                 // we're doing a set but creation is disabled.
                 throw new
                     SnmpStatusException(SnmpStatusException.snmpRspNoAccess);
@@ -1922,12 +1924,13 @@
 
             int length = oid.length;
 
-            if (handlers == null)
-            // This should be considered as a genErr, but we do not want to
-            // abort the whole request, so we're going to throw
-            // a noSuchObject...
-            //
-            throw noSuchObjectException;
+            if (handlers == null) {
+                // This should be considered as a genErr, but we do not want to
+                // abort the whole request, so we're going to throw
+                // a noSuchObject...
+                //
+                throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+            }
 
             final Object data = handlers.getUserData();
             final int pduVersion = handlers.getRequestPduVersion();
@@ -1961,7 +1964,7 @@
                 // so we won't find the next element in this table... (any
                 // element in this table will have a smaller OID)
                 //
-                throw noSuchObjectException;
+                throw new SnmpStatusException(SnmpStatusException.noSuchObject);
             } else if (oid[pos] < nodeId) {
                 // we must return the first leaf under the first columnar
                 // object, so we are back to our first case where pos was
@@ -2051,8 +2054,9 @@
                     //     in tables can't be properly supported (all rows
                     //     must have the same holes)
                     //
-                    if (skipEntryVariable(entryoid,var,data,pduVersion))
-                        throw noSuchObjectException;
+                    if (skipEntryVariable(entryoid,var,data,pduVersion)) {
+                        throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+                    }
                 } catch(SnmpStatusException se) {
                     entryoid = getNextOid(data);
                     var = getNextVarEntryId(entryoid,var,data,pduVersion);
@@ -2085,8 +2089,9 @@
             // So we throw the exception.
             // => will skip to next node in the MIB tree.
             //
-            if (entryoid == null || var == -1 ) throw noSuchObjectException;
-
+            if (entryoid == null || var == -1 ) {
+                throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+            }
 
             // So here we know both the row (entryoid) and the column (var)
             //
@@ -2097,8 +2102,9 @@
                 // for this specific entry, it is not readable for any
                 // other entry => skip to next column.
                 //
-                if (!isReadableEntryId(entryoid,var,data))
-                    throw noSuchObjectException;
+                if (!isReadableEntryId(entryoid,var,data)) {
+                    throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+                }
 
                 // Prepare the result and the ACM checker.
                 //
@@ -2161,8 +2167,9 @@
             // No need to continue, we throw an exception.
             // => will skip to next node in the MIB tree.
             //
-            if (entryoid == null || var == -1 )
-                throw noSuchObjectException;
+            if (entryoid == null || var == -1 ) {
+                throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+            }
         }
     }
 
@@ -2182,14 +2189,15 @@
 
         // Control the length of the oid
         //
-        if (pos +2 >= length)
-            throw noSuchInstanceException;
+        if (pos +2 >= length) {
+            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
+        }
 
         // Check that the entry identifier is specified
         //
-        if (oid[pos] != nodeId)
-            throw noSuchObjectException;
-
+        if (oid[pos] != nodeId) {
+            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
+        }
     }
 
     // ----------------------------------------------------------------------
--- a/src/share/classes/com/sun/jmx/snmp/daemon/SnmpRequestHandler.java	Thu Oct 17 09:23:49 2013 -0700
+++ b/src/share/classes/com/sun/jmx/snmp/daemon/SnmpRequestHandler.java	Mon Oct 21 09:56:06 2013 +0200
@@ -1146,7 +1146,4 @@
 
     static final private String InterruptSysCallMsg =
         "Interrupted system call";
-
-    static final private SnmpStatusException noSuchNameException =
-        new SnmpStatusException(SnmpDefinitions.snmpRspNoSuchName) ;
 }