< prev index next >

src/jdk.management.agent/share/classes/jdk/internal/agent/Agent.java

Print this page




 437 
 438             /*
 439              * If the jmxremote.port property is set then we start the
 440              * RMIConnectorServer for remote M&M.
 441              *
 442              * If the jmxremote or jmxremote.port properties are set then
 443              * we start a RMIConnectorServer for local M&M. The address
 444              * of this "local" server is exported as a counter to the jstat
 445              * instrumentation buffer.
 446              */
 447             if (jmxremote != null || jmxremotePort != null) {
 448                 if (jmxremotePort != null) {
 449                     jmxServer = ConnectorBootstrap.
 450                             startRemoteConnectorServer(jmxremotePort, props);
 451                     startDiscoveryService(props);
 452                 }
 453                 startLocalManagementAgent();
 454             }
 455 
 456         } catch (AgentConfigurationError e) {
 457             error(e.getError(), e.getParams());
 458         } catch (Exception e) {
 459             error(e);
 460         }
 461     }
 462 
 463     private static void startDiscoveryService(Properties props)
 464             throws IOException, JdpException {
 465         // Start discovery service if requested
 466         String discoveryPort = props.getProperty("com.sun.management.jdp.port");
 467         String discoveryAddress = props.getProperty("com.sun.management.jdp.address");
 468         String discoveryShouldStart = props.getProperty("com.sun.management.jmxremote.autodiscovery");
 469 
 470         // Decide whether we should start autodicovery service.
 471         // To start autodiscovery following conditions should be met:
 472         // autodiscovery==true OR (autodicovery==null AND jdp.port != NULL)
 473 
 474         boolean shouldStart = false;
 475         if (discoveryShouldStart == null){
 476             shouldStart = (discoveryPort != null);
 477         }


 670             error(key);
 671         } else {
 672             StringBuilder message = new StringBuilder(params[0]);
 673             for (int i = 1; i < params.length; i++) {
 674                 message.append(' ').append(params[i]);
 675             }
 676             error(key, message.toString());
 677         }
 678     }
 679 
 680     public static void error(String key, String message) {
 681         String keyText = getText(key);
 682         System.err.print(getText("agent.err.error") + ": " + keyText);
 683         System.err.println(": " + message);
 684         throw new RuntimeException(keyText + ": " + message);
 685     }
 686 
 687     public static void error(Exception e) {
 688         e.printStackTrace();
 689         System.err.println(getText(AGENT_EXCEPTION) + ": " + e.toString());

















 690         throw new RuntimeException(e);
 691     }
 692 
 693     public static void warning(String key, String message) {
 694         System.err.print(getText("agent.err.warning") + ": " + getText(key));
 695         System.err.println(": " + message);
 696     }
 697 
 698     private static void initResource() {
 699         try {
 700             messageRB =
 701                 ResourceBundle.getBundle("jdk.internal.agent.resources.agent");
 702         } catch (MissingResourceException e) {
 703             throw new Error("Fatal: Resource for management agent is missing");
 704         }
 705     }
 706 
 707     public static String getText(String key) {
 708         if (messageRB == null) {
 709             initResource();


 437 
 438             /*
 439              * If the jmxremote.port property is set then we start the
 440              * RMIConnectorServer for remote M&M.
 441              *
 442              * If the jmxremote or jmxremote.port properties are set then
 443              * we start a RMIConnectorServer for local M&M. The address
 444              * of this "local" server is exported as a counter to the jstat
 445              * instrumentation buffer.
 446              */
 447             if (jmxremote != null || jmxremotePort != null) {
 448                 if (jmxremotePort != null) {
 449                     jmxServer = ConnectorBootstrap.
 450                             startRemoteConnectorServer(jmxremotePort, props);
 451                     startDiscoveryService(props);
 452                 }
 453                 startLocalManagementAgent();
 454             }
 455 
 456         } catch (AgentConfigurationError e) {
 457             error(e);
 458         } catch (Exception e) {
 459             error(e);
 460         }
 461     }
 462 
 463     private static void startDiscoveryService(Properties props)
 464             throws IOException, JdpException {
 465         // Start discovery service if requested
 466         String discoveryPort = props.getProperty("com.sun.management.jdp.port");
 467         String discoveryAddress = props.getProperty("com.sun.management.jdp.address");
 468         String discoveryShouldStart = props.getProperty("com.sun.management.jmxremote.autodiscovery");
 469 
 470         // Decide whether we should start autodicovery service.
 471         // To start autodiscovery following conditions should be met:
 472         // autodiscovery==true OR (autodicovery==null AND jdp.port != NULL)
 473 
 474         boolean shouldStart = false;
 475         if (discoveryShouldStart == null){
 476             shouldStart = (discoveryPort != null);
 477         }


 670             error(key);
 671         } else {
 672             StringBuilder message = new StringBuilder(params[0]);
 673             for (int i = 1; i < params.length; i++) {
 674                 message.append(' ').append(params[i]);
 675             }
 676             error(key, message.toString());
 677         }
 678     }
 679 
 680     public static void error(String key, String message) {
 681         String keyText = getText(key);
 682         System.err.print(getText("agent.err.error") + ": " + keyText);
 683         System.err.println(": " + message);
 684         throw new RuntimeException(keyText + ": " + message);
 685     }
 686 
 687     public static void error(Exception e) {
 688         e.printStackTrace();
 689         System.err.println(getText(AGENT_EXCEPTION) + ": " + e.toString());
 690         throw new RuntimeException(e);
 691     }
 692 
 693     public static void error(AgentConfigurationError e) {
 694         String keyText = getText(e.getError());
 695         String[] params = e.getParams();
 696 
 697         System.err.print(getText("agent.err.error") + ": " + keyText);
 698 
 699         if (params != null && params.length != 0) {
 700            StringBuffer message = new StringBuffer(params[0]);
 701            for (int i = 1; i < params.length; i++) {
 702                message.append(" " + params[i]);
 703            }
 704            System.err.println(": " + message);
 705         }
 706         e.printStackTrace();
 707         throw new RuntimeException(e);
 708     }
 709 
 710     public static void warning(String key, String message) {
 711         System.err.print(getText("agent.err.warning") + ": " + getText(key));
 712         System.err.println(": " + message);
 713     }
 714 
 715     private static void initResource() {
 716         try {
 717             messageRB =
 718                 ResourceBundle.getBundle("jdk.internal.agent.resources.agent");
 719         } catch (MissingResourceException e) {
 720             throw new Error("Fatal: Resource for management agent is missing");
 721         }
 722     }
 723 
 724     public static String getText(String key) {
 725         if (messageRB == null) {
 726             initResource();
< prev index next >