jdk/src/share/classes/sun/management/Agent.java
changeset 11530 a9d059c15b80
parent 5506 202f599c92aa
child 11991 800d0ff7b043
equal deleted inserted replaced
11529:e08d565262ce 11530:a9d059c15b80
   214                 Class.forName(SNMP_ADAPTOR_BOOTSTRAP_CLASS_NAME,true,null);
   214                 Class.forName(SNMP_ADAPTOR_BOOTSTRAP_CLASS_NAME,true,null);
   215             final Method initializeMethod =
   215             final Method initializeMethod =
   216                     adaptorClass.getMethod("initialize",
   216                     adaptorClass.getMethod("initialize",
   217                         String.class, Properties.class);
   217                         String.class, Properties.class);
   218             initializeMethod.invoke(null,snmpPort,props);
   218             initializeMethod.invoke(null,snmpPort,props);
   219         } catch (ClassNotFoundException x) {
   219         } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException x) {
   220             // The SNMP packages are not present: throws an exception.
   220             // snmp runtime doesn't exist - initialization fails
   221             throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,x);
       
   222         } catch (NoSuchMethodException x) {
       
   223             // should not happen...
       
   224             throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,x);
   221             throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,x);
   225         } catch (InvocationTargetException x) {
   222         } catch (InvocationTargetException x) {
   226             final Throwable cause = x.getCause();
   223             final Throwable cause = x.getCause();
   227             if (cause instanceof RuntimeException)
   224             if (cause instanceof RuntimeException)
   228                 throw (RuntimeException) cause;
   225                 throw (RuntimeException) cause;
   229             else if (cause instanceof Error)
   226             else if (cause instanceof Error)
   230                 throw (Error) cause;
   227                 throw (Error) cause;
   231             // should not happen...
   228             // should not happen...
   232             throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,cause);
   229             throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,cause);
   233         } catch (IllegalAccessException x) {
       
   234             // should not happen...
       
   235             throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,x);
       
   236         }
   230         }
   237     }
   231     }
   238 
   232 
   239     // read config file and initialize the properties
   233     // read config file and initialize the properties
   240     private static void readConfiguration(String fname, Properties p) {
   234     private static void readConfiguration(String fname, Properties p) {
   271                 try {
   265                 try {
   272                     in.close();
   266                     in.close();
   273                 } catch (IOException e) {
   267                 } catch (IOException e) {
   274                     error(CONFIG_FILE_CLOSE_FAILED, fname);
   268                     error(CONFIG_FILE_CLOSE_FAILED, fname);
   275                 }
   269                 }
   276             }
   270              }
   277         }
   271          }
   278     }
   272     }
   279 
   273 
   280     public static void startAgent() throws Exception {
   274     public static void startAgent() throws Exception {
   281         String prop = System.getProperty("com.sun.management.agent.class");
   275         String prop = System.getProperty("com.sun.management.agent.class");
   282 
   276 
   307             try {
   301             try {
   308                 // Instantiate the named class.
   302                 // Instantiate the named class.
   309                 // invoke the premain(String args) method
   303                 // invoke the premain(String args) method
   310                 Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(cname);
   304                 Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(cname);
   311                 Method premain = clz.getMethod("premain",
   305                 Method premain = clz.getMethod("premain",
   312                                                new Class[] { String.class });
   306                                                new Class<?>[] { String.class });
   313                 premain.invoke(null, /* static */
   307                 premain.invoke(null, /* static */
   314                                new Object[] { args });
   308                                new Object[] { args });
   315             } catch (ClassNotFoundException ex) {
   309             } catch (ClassNotFoundException ex) {
   316                 error(AGENT_CLASS_NOT_FOUND, "\"" + cname + "\"");
   310                 error(AGENT_CLASS_NOT_FOUND, "\"" + cname + "\"");
   317             } catch (NoSuchMethodException ex) {
   311             } catch (NoSuchMethodException ex) {