src/java.management/share/classes/sun/management/Agent.java

Print this page




 148                 warning(EXPORT_ADDRESS_FAILED, x.getMessage());
 149             }
 150         }
 151     }
 152 
 153     // jcmd ManagementAgent.start entry point
 154     // This method starts the remote JMX agent and starts neither
 155     // the local JMX agent nor the SNMP agent
 156     // @see #startLocalManagementAgent and also @see #startAgent.
 157     private static synchronized void startRemoteManagementAgent(String args) throws Exception {
 158         if (jmxServer != null) {
 159             throw new RuntimeException(getText(INVALID_STATE, "Agent already started"));
 160         }
 161 
 162         try {
 163             Properties argProps = parseString(args);
 164             Properties configProps = new Properties();
 165 
 166             // Load the management properties from the config file
 167             // if config file is not specified readConfiguration implicitly
 168             // reads <java.home>/lib/management/management.properties
 169 
 170             String fname = System.getProperty(CONFIG_FILE);
 171             readConfiguration(fname, configProps);
 172 
 173             // management properties can be overridden by system properties
 174             // which take precedence
 175             Properties sysProps = System.getProperties();
 176             synchronized (sysProps) {
 177                 configProps.putAll(sysProps);
 178             }
 179 
 180             // if user specifies config file into command line for either
 181             // jcmd utilities or attach command it overrides properties set in
 182             // command line at the time of VM start
 183             String fnameUser = argProps.getProperty(CONFIG_FILE);
 184             if (fnameUser != null) {
 185                 readConfiguration(fnameUser, configProps);
 186             }
 187 
 188             // arguments specified in command line of jcmd utilities


 387         } catch (InvocationTargetException x) {
 388             final Throwable cause = x.getCause();
 389             if (cause instanceof RuntimeException) {
 390                 throw (RuntimeException) cause;
 391             } else if (cause instanceof Error) {
 392                 throw (Error) cause;
 393             }
 394             // should not happen...
 395             throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT, cause);
 396         }
 397     }
 398 
 399     // read config file and initialize the properties
 400     private static void readConfiguration(String fname, Properties p) {
 401         if (fname == null) {
 402             String home = System.getProperty("java.home");
 403             if (home == null) {
 404                 throw new Error("Can't find java.home ??");
 405             }
 406             StringBuilder defaultFileName = new StringBuilder(home);
 407             defaultFileName.append(File.separator).append("lib");
 408             defaultFileName.append(File.separator).append("management");
 409             defaultFileName.append(File.separator).append("management.properties");
 410             // Set file name
 411             fname = defaultFileName.toString();
 412         }
 413         final File configFile = new File(fname);
 414         if (!configFile.exists()) {
 415             error(CONFIG_FILE_NOT_FOUND, fname);
 416         }
 417 
 418         InputStream in = null;
 419         try {
 420             in = new FileInputStream(configFile);
 421             BufferedInputStream bin = new BufferedInputStream(in);
 422             p.load(bin);
 423         } catch (FileNotFoundException e) {
 424             error(CONFIG_FILE_OPEN_FAILED, e.getMessage());
 425         } catch (IOException e) {
 426             error(CONFIG_FILE_OPEN_FAILED, e.getMessage());
 427         } catch (SecurityException e) {




 148                 warning(EXPORT_ADDRESS_FAILED, x.getMessage());
 149             }
 150         }
 151     }
 152 
 153     // jcmd ManagementAgent.start entry point
 154     // This method starts the remote JMX agent and starts neither
 155     // the local JMX agent nor the SNMP agent
 156     // @see #startLocalManagementAgent and also @see #startAgent.
 157     private static synchronized void startRemoteManagementAgent(String args) throws Exception {
 158         if (jmxServer != null) {
 159             throw new RuntimeException(getText(INVALID_STATE, "Agent already started"));
 160         }
 161 
 162         try {
 163             Properties argProps = parseString(args);
 164             Properties configProps = new Properties();
 165 
 166             // Load the management properties from the config file
 167             // if config file is not specified readConfiguration implicitly
 168             // reads <java.home>/conf/management/management.properties
 169 
 170             String fname = System.getProperty(CONFIG_FILE);
 171             readConfiguration(fname, configProps);
 172 
 173             // management properties can be overridden by system properties
 174             // which take precedence
 175             Properties sysProps = System.getProperties();
 176             synchronized (sysProps) {
 177                 configProps.putAll(sysProps);
 178             }
 179 
 180             // if user specifies config file into command line for either
 181             // jcmd utilities or attach command it overrides properties set in
 182             // command line at the time of VM start
 183             String fnameUser = argProps.getProperty(CONFIG_FILE);
 184             if (fnameUser != null) {
 185                 readConfiguration(fnameUser, configProps);
 186             }
 187 
 188             // arguments specified in command line of jcmd utilities


 387         } catch (InvocationTargetException x) {
 388             final Throwable cause = x.getCause();
 389             if (cause instanceof RuntimeException) {
 390                 throw (RuntimeException) cause;
 391             } else if (cause instanceof Error) {
 392                 throw (Error) cause;
 393             }
 394             // should not happen...
 395             throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT, cause);
 396         }
 397     }
 398 
 399     // read config file and initialize the properties
 400     private static void readConfiguration(String fname, Properties p) {
 401         if (fname == null) {
 402             String home = System.getProperty("java.home");
 403             if (home == null) {
 404                 throw new Error("Can't find java.home ??");
 405             }
 406             StringBuilder defaultFileName = new StringBuilder(home);
 407             defaultFileName.append(File.separator).append("conf");
 408             defaultFileName.append(File.separator).append("management");
 409             defaultFileName.append(File.separator).append("management.properties");
 410             // Set file name
 411             fname = defaultFileName.toString();
 412         }
 413         final File configFile = new File(fname);
 414         if (!configFile.exists()) {
 415             error(CONFIG_FILE_NOT_FOUND, fname);
 416         }
 417 
 418         InputStream in = null;
 419         try {
 420             in = new FileInputStream(configFile);
 421             BufferedInputStream bin = new BufferedInputStream(in);
 422             p.load(bin);
 423         } catch (FileNotFoundException e) {
 424             error(CONFIG_FILE_OPEN_FAILED, e.getMessage());
 425         } catch (IOException e) {
 426             error(CONFIG_FILE_OPEN_FAILED, e.getMessage());
 427         } catch (SecurityException e) {