src/share/classes/sun/tools/jconsole/JConsole.java

Print this page




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.tools.jconsole;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.beans.*;
  31 import java.io.*;
  32 import java.lang.reflect.InvocationTargetException;
  33 import java.net.*;
  34 import java.util.*;
  35 import java.util.List;
  36 
  37 import javax.swing.*;
  38 import javax.swing.border.*;
  39 import javax.swing.event.*;
  40 import javax.swing.plaf.*;
  41 import javax.management.remote.JMXServiceURL;
  42 import javax.management.remote.JMXConnector;
  43 import javax.security.auth.login.FailedLoginException;
  44 import javax.net.ssl.SSLHandshakeException;
  45 
  46 import com.sun.tools.jconsole.JConsolePlugin;
  47 
  48 import sun.net.util.IPAddressUtil;

  49 
  50 import static sun.tools.jconsole.Resources.*;
  51 import static sun.tools.jconsole.Utilities.*;
  52 
  53 @SuppressWarnings("serial")
  54 public class JConsole extends JFrame
  55     implements ActionListener, InternalFrameListener {
  56 
  57     static /*final*/ boolean IS_GTK;
  58     static /*final*/ boolean IS_WIN;
  59 
  60     static {
  61         // Apply the system L&F if it is GTK or Windows, and
  62         // the L&F is not specified using a system property.
  63         if (System.getProperty("swing.defaultlaf") == null) {
  64             String systemLaF = UIManager.getSystemLookAndFeelClassName();
  65             if (systemLaF.equals("com.sun.java.swing.plaf.gtk.GTKLookAndFeel") ||
  66                 systemLaF.equals("com.sun.java.swing.plaf.windows.WindowsLookAndFeel")) {
  67 
  68                 try {
  69                     UIManager.setLookAndFeel(systemLaF);
  70                 } catch (Exception e) {
  71                     System.err.println(Resources.getText("JConsole: ", e.getMessage()));
  72                 }
  73             }
  74         }
  75 
  76         updateLafValues();
  77     }
  78 
  79 
  80     static void updateLafValues() {
  81         String lafName = UIManager.getLookAndFeel().getClass().getName();
  82         IS_GTK = lafName.equals("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
  83         IS_WIN = lafName.equals("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
  84 
  85         //BorderedComponent.updateLafValues();
  86     }
  87 
  88 
  89     private final static String title =
  90         Resources.getText("Java Monitoring & Management Console");
  91     public final static String ROOT_URL =
  92         "service:jmx:";
  93 
  94     private static int updateInterval = 4000;
  95     private static String pluginPath = "";
  96 
  97     private JMenuBar menuBar;
  98     private JMenuItem hotspotMI, connectMI, exitMI;
  99     private WindowMenu windowMenu;
 100     private JMenuItem tileMI, cascadeMI, minimizeAllMI, restoreAllMI;
 101     private JMenuItem userGuideMI, aboutMI;
 102 
 103     private JButton connectButton;
 104     private JDesktopPane desktop;
 105     private ConnectDialog connectDialog;
 106     private CreateMBeanDialog createDialog;
 107 
 108     private ArrayList<VMInternalFrame> windows =
 109         new ArrayList<VMInternalFrame>();
 110 
 111     private int frameLoc = 5;
 112     static boolean debug;
 113 
 114     public JConsole(boolean hotspot) {
 115         super(title);
 116 
 117         setRootPane(new FixedJRootPane());
 118         setAccessibleDescription(this,
 119                                  getText("JConsole.accessibleDescription"));
 120         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 121 
 122         menuBar = new JMenuBar();
 123         setJMenuBar(menuBar);
 124 
 125         // TODO: Use Actions !
 126 
 127         JMenu connectionMenu = new JMenu(getText("Connection"));
 128         connectionMenu.setMnemonic(getMnemonicInt("Connection"));
 129         menuBar.add(connectionMenu);
 130         if(hotspot) {
 131             hotspotMI = new JMenuItem(getText("Hotspot MBeans..."));
 132             hotspotMI.setMnemonic(getMnemonicInt("Hotspot MBeans..."));
 133             hotspotMI.setAccelerator(KeyStroke.
 134                                      getKeyStroke(KeyEvent.VK_H,
 135                                                   InputEvent.CTRL_MASK));
 136             hotspotMI.addActionListener(this);
 137             connectionMenu.add(hotspotMI);
 138 
 139             connectionMenu.addSeparator();
 140         }
 141 
 142         connectMI = new JMenuItem(Resources.getText("New Connection..."));
 143         connectMI.setMnemonic(getMnemonicInt("New Connection..."));
 144         connectMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
 145                                                         InputEvent.CTRL_MASK));
 146         connectMI.addActionListener(this);
 147         connectionMenu.add(connectMI);
 148 
 149         connectionMenu.addSeparator();
 150 
 151         exitMI = new JMenuItem(Resources.getText("Exit"));
 152         exitMI.setMnemonic(getMnemonicInt("Exit"));
 153         exitMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,
 154                                                      InputEvent.ALT_MASK));
 155         exitMI.addActionListener(this);
 156         connectionMenu.add(exitMI);
 157 
 158 
 159         JMenu helpMenu = new JMenu(getText("HelpMenu.title"));
 160         helpMenu.setMnemonic(getMnemonicInt("HelpMenu.title"));
 161         menuBar.add(helpMenu);
 162 
 163         if (AboutDialog.isBrowseSupported()) {
 164             userGuideMI = new JMenuItem(getText("HelpMenu.UserGuide.title"));
 165             userGuideMI.setMnemonic(getMnemonicInt("HelpMenu.UserGuide.title"));
 166             userGuideMI.addActionListener(this);
 167             helpMenu.add(userGuideMI);
 168             helpMenu.addSeparator();
 169         }
 170         aboutMI = new JMenuItem(getText("HelpMenu.About.title"));
 171         aboutMI.setMnemonic(getMnemonicInt("HelpMenu.About.title"));
 172         aboutMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
 173         aboutMI.addActionListener(this);
 174         helpMenu.add(aboutMI);
 175     }
 176 
 177     public JDesktopPane getDesktopPane() {
 178         return desktop;
 179     }
 180 
 181     public List<VMInternalFrame> getInternalFrames() {
 182         return windows;
 183     }
 184 
 185     private void createMDI() {
 186         // Restore title - we now show connection name on internal frames
 187         setTitle(title);
 188 
 189         Container cp = getContentPane();
 190         Component oldCenter =
 191             ((BorderLayout)cp.getLayout()).
 192             getLayoutComponent(BorderLayout.CENTER);
 193 
 194         windowMenu = new WindowMenu(Resources.getText("Window"));
 195         windowMenu.setMnemonic(getMnemonicInt("Window"));
 196         // Add Window menu before Help menu
 197         menuBar.add(windowMenu, menuBar.getComponentCount() - 1);
 198 
 199         desktop = new JDesktopPane();
 200         desktop.setBackground(new Color(235, 245, 255));
 201 
 202         cp.add(desktop, BorderLayout.CENTER);
 203 
 204         if (oldCenter instanceof VMPanel) {
 205             addFrame((VMPanel)oldCenter);
 206         }
 207     }
 208 
 209     private class WindowMenu extends JMenu {
 210         VMInternalFrame[] windowMenuWindows = new VMInternalFrame[0];
 211         int separatorPosition;
 212 
 213         // The width value of viewR is used to truncate long menu items.
 214         // The rest are placeholders and are ignored for this purpose.
 215         Rectangle viewR = new Rectangle(0, 0, 400, 20);
 216         Rectangle textR = new Rectangle(0, 0, 0, 0);
 217         Rectangle iconR = new Rectangle(0, 0, 0, 0);
 218 
 219         WindowMenu(String text) {
 220             super(text);
 221 
 222             cascadeMI = new JMenuItem(Resources.getText("Cascade"));
 223             cascadeMI.setMnemonic(getMnemonicInt("Cascade"));
 224             cascadeMI.addActionListener(JConsole.this);
 225             add(cascadeMI);
 226 
 227             tileMI = new JMenuItem(Resources.getText("Tile"));
 228             tileMI.setMnemonic(getMnemonicInt("Tile"));
 229             tileMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T,
 230                                                          InputEvent.CTRL_MASK));
 231             tileMI.addActionListener(JConsole.this);
 232             add(tileMI);
 233 
 234             minimizeAllMI = new JMenuItem(Resources.getText("Minimize All"));
 235             minimizeAllMI.setMnemonic(getMnemonicInt("Minimize All"));
 236             minimizeAllMI.addActionListener(JConsole.this);
 237             add(minimizeAllMI);
 238 
 239             restoreAllMI = new JMenuItem(Resources.getText("Restore All"));
 240             restoreAllMI.setMnemonic(getMnemonicInt("Restore All"));
 241             restoreAllMI.addActionListener(JConsole.this);
 242             add(restoreAllMI);
 243 
 244             separatorPosition = getMenuComponentCount();
 245         }
 246 
 247         private void add(VMInternalFrame vmIF) {
 248             if (separatorPosition == getMenuComponentCount()) {
 249                 addSeparator();
 250             }
 251 
 252             int index = -1;
 253             int position = separatorPosition + 1;
 254             int n = windowMenuWindows.length;
 255 
 256             for (int i = 0; i < n; i++) {
 257                 if (windowMenuWindows[i] != null) {
 258                     // Slot is in use, try next
 259                     position++;
 260                 } else {


 704                     }
 705                 } else {
 706                     String[] s = txt.split(":");
 707                     if (s.length == 2) {
 708                         try {
 709                             int port = Integer.parseInt(s[1]);
 710                             if (port >= 0 && port <= 0xFFFF) {
 711                                 valid = true;
 712                             }
 713                         } catch (NumberFormatException ex) {
 714                             valid = false;
 715                         }
 716                     }
 717                 }
 718             }
 719         }
 720         return valid;
 721     }
 722 
 723     private String errorMessage(Exception ex) {
 724        String msg = Resources.getText("Connection failed");
 725        if (ex instanceof IOException || ex instanceof SecurityException) {
 726            Throwable cause = null;
 727            Throwable c = ex.getCause();
 728            while (c != null) {
 729                cause = c;
 730                c = c.getCause();
 731            }
 732            if (cause instanceof ConnectException) {
 733                return msg + ": " + cause.getMessage();
 734            } else if (cause instanceof UnknownHostException) {
 735                return Resources.getText("Unknown Host", cause.getMessage());
 736            } else if (cause instanceof NoRouteToHostException) {
 737                return msg + ": " + cause.getMessage();
 738            } else if (cause instanceof FailedLoginException) {
 739                return msg + ": " + cause.getMessage();
 740            } else if (cause instanceof SSLHandshakeException) {
 741                return msg + ": "+ cause.getMessage();
 742            }
 743         } else if (ex instanceof MalformedURLException) {
 744            return Resources.getText("Invalid URL", ex.getMessage());
 745         }
 746         return msg + ": " + ex.getMessage();
 747     }
 748 
 749 
 750     // InternalFrameListener interface
 751 
 752     public void internalFrameClosing(InternalFrameEvent e) {
 753         VMInternalFrame vmIF = (VMInternalFrame)e.getInternalFrame();
 754         removeVMInternalFrame(vmIF);
 755         windows.remove(vmIF);
 756         ProxyClient client = vmIF.getVMPanel().getProxyClient(false);
 757         if(!isProxyClientUsed(client))
 758             client.markAsDead();
 759         if (windows.size() == 0) {
 760             showConnectDialog("", "", 0, null, null, null);
 761         }
 762     }
 763 
 764     public void internalFrameOpened(InternalFrameEvent e) {}
 765     public void internalFrameClosed(InternalFrameEvent e) {}
 766     public void internalFrameIconified(InternalFrameEvent e) {}
 767     public void internalFrameDeiconified(InternalFrameEvent e) {}
 768     public void internalFrameActivated(InternalFrameEvent e) {}
 769     public void internalFrameDeactivated(InternalFrameEvent e) {}
 770 
 771 
 772     private static void usage() {
 773         System.err.println(Resources.getText("zz usage text", "jconsole"));
 774     }
 775 
 776     private static void mainInit(final List<String> urls,
 777                                  final List<String> hostNames,
 778                                  final List<Integer> ports,
 779                                  final List<LocalVirtualMachine> vmids,
 780                                  final ProxyClient proxyClient,
 781                                  final boolean noTile,
 782                                  final boolean hotspot) {
 783 
 784 
 785         // Always create Swing GUI on the Event Dispatching Thread
 786         SwingUtilities.invokeLater(new Runnable() {
 787                 public void run() {
 788                     JConsole jConsole = new JConsole(hotspot);
 789 
 790                     // Center the window on screen, taking into account screen
 791                     // size and insets.
 792                     Toolkit toolkit = Toolkit.getDefaultToolkit();
 793                     GraphicsConfiguration gc = jConsole.getGraphicsConfiguration();


 986             plugins.add(p);
 987         }
 988         return plugins;
 989     }
 990 
 991     private static void initPluginService(String pluginPath) {
 992         if (pluginPath.length() > 0) {
 993             try {
 994                 ClassLoader pluginCL = new URLClassLoader(pathToURLs(pluginPath));
 995                 ServiceLoader<JConsolePlugin> plugins =
 996                     ServiceLoader.load(JConsolePlugin.class, pluginCL);
 997                 // validate all plugins
 998             for (JConsolePlugin p : plugins) {
 999                     if (isDebug()) {
1000                         System.out.println("Plugin " + p.getClass() + " loaded.");
1001                     }
1002                 }
1003                 pluginService = plugins;
1004             } catch (ServiceConfigurationError e) {
1005                 // Error occurs during initialization of plugin
1006                 System.out.println(Resources.getText("Fail to load plugin",
1007                                    e.getMessage()));
1008             } catch (MalformedURLException e) {
1009                 if (JConsole.isDebug()) {
1010                     e.printStackTrace();
1011                 }
1012                 System.out.println(Resources.getText("Invalid plugin path",
1013                                    e.getMessage()));
1014             }
1015         }
1016 
1017         if (pluginService == null) {
1018             initEmptyPlugin();
1019         }
1020     }
1021 
1022     private static void initEmptyPlugin() {
1023         ClassLoader pluginCL = new URLClassLoader(new URL[0]);
1024         pluginService = ServiceLoader.load(JConsolePlugin.class, pluginCL);
1025     }
1026 
1027    /**
1028      * Utility method for converting a search path string to an array
1029      * of directory and JAR file URLs.
1030      *
1031      * @param path the search path string
1032      * @return the resulting array of directory and JAR file URLs




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.tools.jconsole;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.beans.*;
  31 import java.io.*;

  32 import java.net.*;
  33 import java.util.*;
  34 import java.util.List;
  35 
  36 import javax.swing.*;
  37 import javax.swing.border.*;
  38 import javax.swing.event.*;
  39 import javax.swing.plaf.*;


  40 import javax.security.auth.login.FailedLoginException;
  41 import javax.net.ssl.SSLHandshakeException;
  42 
  43 import com.sun.tools.jconsole.JConsolePlugin;
  44 
  45 import sun.net.util.IPAddressUtil;
  46 import sun.tools.jconsole.resources.Messages;
  47 

  48 import static sun.tools.jconsole.Utilities.*;
  49 
  50 @SuppressWarnings("serial")
  51 public class JConsole extends JFrame
  52     implements ActionListener, InternalFrameListener {
  53 
  54     static /*final*/ boolean IS_GTK;
  55     static /*final*/ boolean IS_WIN;
  56 
  57     static {
  58         // Apply the system L&F if it is GTK or Windows, and
  59         // the L&F is not specified using a system property.
  60         if (System.getProperty("swing.defaultlaf") == null) {
  61             String systemLaF = UIManager.getSystemLookAndFeelClassName();
  62             if (systemLaF.equals("com.sun.java.swing.plaf.gtk.GTKLookAndFeel") ||
  63                 systemLaF.equals("com.sun.java.swing.plaf.windows.WindowsLookAndFeel")) {
  64 
  65                 try {
  66                     UIManager.setLookAndFeel(systemLaF);
  67                 } catch (Exception e) {
  68                     System.err.println(Resources.format(Messages.JCONSOLE_COLON_, e.getMessage()));
  69                 }
  70             }
  71         }
  72 
  73         updateLafValues();
  74     }
  75 
  76 
  77     static void updateLafValues() {
  78         String lafName = UIManager.getLookAndFeel().getClass().getName();
  79         IS_GTK = lafName.equals("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
  80         IS_WIN = lafName.equals("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
  81 
  82         //BorderedComponent.updateLafValues();
  83     }
  84 
  85 
  86     private final static String title =
  87         Messages.JAVA_MONITORING___MANAGEMENT_CONSOLE;
  88     public final static String ROOT_URL =
  89         "service:jmx:";
  90 
  91     private static int updateInterval = 4000;
  92     private static String pluginPath = "";
  93 
  94     private JMenuBar menuBar;
  95     private JMenuItem hotspotMI, connectMI, exitMI;
  96     private WindowMenu windowMenu;
  97     private JMenuItem tileMI, cascadeMI, minimizeAllMI, restoreAllMI;
  98     private JMenuItem userGuideMI, aboutMI;
  99 
 100     private JButton connectButton;
 101     private JDesktopPane desktop;
 102     private ConnectDialog connectDialog;
 103     private CreateMBeanDialog createDialog;
 104 
 105     private ArrayList<VMInternalFrame> windows =
 106         new ArrayList<VMInternalFrame>();
 107 
 108     private int frameLoc = 5;
 109     static boolean debug;
 110 
 111     public JConsole(boolean hotspot) {
 112         super(title);
 113 
 114         setRootPane(new FixedJRootPane());
 115         setAccessibleDescription(this,
 116                 Messages.JCONSOLE_ACCESSIBLE_DESCRIPTION);
 117         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 118 
 119         menuBar = new JMenuBar();
 120         setJMenuBar(menuBar);
 121 
 122         // TODO: Use Actions !
 123 
 124         JMenu connectionMenu = new JMenu(Messages.CONNECTION);
 125         connectionMenu.setMnemonic(Resources.getMnemonicInt(Messages.CONNECTION));
 126         menuBar.add(connectionMenu);
 127         if(hotspot) {
 128             hotspotMI = new JMenuItem(Messages.HOTSPOT_MBEANS_ELLIPSIS);
 129             hotspotMI.setMnemonic(Resources.getMnemonicInt(Messages.HOTSPOT_MBEANS_ELLIPSIS));
 130             hotspotMI.setAccelerator(KeyStroke.
 131                                      getKeyStroke(KeyEvent.VK_H,
 132                                                   InputEvent.CTRL_MASK));
 133             hotspotMI.addActionListener(this);
 134             connectionMenu.add(hotspotMI);
 135 
 136             connectionMenu.addSeparator();
 137         }
 138 
 139         connectMI = new JMenuItem(Messages.NEW_CONNECTION_ELLIPSIS);
 140         connectMI.setMnemonic(Resources.getMnemonicInt(Messages.NEW_CONNECTION_ELLIPSIS));
 141         connectMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
 142                                                         InputEvent.CTRL_MASK));
 143         connectMI.addActionListener(this);
 144         connectionMenu.add(connectMI);
 145 
 146         connectionMenu.addSeparator();
 147 
 148         exitMI = new JMenuItem(Messages.EXIT);
 149         exitMI.setMnemonic(Resources.getMnemonicInt(Messages.EXIT));
 150         exitMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,
 151                                                      InputEvent.ALT_MASK));
 152         exitMI.addActionListener(this);
 153         connectionMenu.add(exitMI);
 154 
 155 
 156         JMenu helpMenu = new JMenu(Messages.HELP_MENU_TITLE);
 157         helpMenu.setMnemonic(Resources.getMnemonicInt(Messages.HELP_MENU_TITLE));
 158         menuBar.add(helpMenu);
 159 
 160         if (AboutDialog.isBrowseSupported()) {
 161             userGuideMI = new JMenuItem(Messages.HELP_MENU_USER_GUIDE_TITLE);
 162             userGuideMI.setMnemonic(Resources.getMnemonicInt(Messages.HELP_MENU_USER_GUIDE_TITLE));
 163             userGuideMI.addActionListener(this);
 164             helpMenu.add(userGuideMI);
 165             helpMenu.addSeparator();
 166         }
 167         aboutMI = new JMenuItem(Messages.HELP_MENU_ABOUT_TITLE);
 168         aboutMI.setMnemonic(Resources.getMnemonicInt(Messages.HELP_MENU_ABOUT_TITLE));
 169         aboutMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
 170         aboutMI.addActionListener(this);
 171         helpMenu.add(aboutMI);
 172     }
 173 
 174     public JDesktopPane getDesktopPane() {
 175         return desktop;
 176     }
 177 
 178     public List<VMInternalFrame> getInternalFrames() {
 179         return windows;
 180     }
 181 
 182     private void createMDI() {
 183         // Restore title - we now show connection name on internal frames
 184         setTitle(title);
 185 
 186         Container cp = getContentPane();
 187         Component oldCenter =
 188             ((BorderLayout)cp.getLayout()).
 189             getLayoutComponent(BorderLayout.CENTER);
 190 
 191         windowMenu = new WindowMenu(Messages.WINDOW);
 192         windowMenu.setMnemonic(Resources.getMnemonicInt(Messages.WINDOW));
 193         // Add Window menu before Help menu
 194         menuBar.add(windowMenu, menuBar.getComponentCount() - 1);
 195 
 196         desktop = new JDesktopPane();
 197         desktop.setBackground(new Color(235, 245, 255));
 198 
 199         cp.add(desktop, BorderLayout.CENTER);
 200 
 201         if (oldCenter instanceof VMPanel) {
 202             addFrame((VMPanel)oldCenter);
 203         }
 204     }
 205 
 206     private class WindowMenu extends JMenu {
 207         VMInternalFrame[] windowMenuWindows = new VMInternalFrame[0];
 208         int separatorPosition;
 209 
 210         // The width value of viewR is used to truncate long menu items.
 211         // The rest are placeholders and are ignored for this purpose.
 212         Rectangle viewR = new Rectangle(0, 0, 400, 20);
 213         Rectangle textR = new Rectangle(0, 0, 0, 0);
 214         Rectangle iconR = new Rectangle(0, 0, 0, 0);
 215 
 216         WindowMenu(String text) {
 217             super(text);
 218 
 219             cascadeMI = new JMenuItem(Messages.CASCADE);
 220             cascadeMI.setMnemonic(Resources.getMnemonicInt(Messages.CASCADE));
 221             cascadeMI.addActionListener(JConsole.this);
 222             add(cascadeMI);
 223 
 224             tileMI = new JMenuItem(Messages.TILE);
 225             tileMI.setMnemonic(Resources.getMnemonicInt(Messages.TILE));
 226             tileMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T,
 227                                                          InputEvent.CTRL_MASK));
 228             tileMI.addActionListener(JConsole.this);
 229             add(tileMI);
 230 
 231             minimizeAllMI = new JMenuItem(Messages.MINIMIZE_ALL);
 232             minimizeAllMI.setMnemonic(Resources.getMnemonicInt(Messages.MINIMIZE_ALL));
 233             minimizeAllMI.addActionListener(JConsole.this);
 234             add(minimizeAllMI);
 235 
 236             restoreAllMI = new JMenuItem(Messages.RESTORE_ALL);
 237             restoreAllMI.setMnemonic(Resources.getMnemonicInt(Messages.RESTORE_ALL));
 238             restoreAllMI.addActionListener(JConsole.this);
 239             add(restoreAllMI);
 240 
 241             separatorPosition = getMenuComponentCount();
 242         }
 243 
 244         private void add(VMInternalFrame vmIF) {
 245             if (separatorPosition == getMenuComponentCount()) {
 246                 addSeparator();
 247             }
 248 
 249             int index = -1;
 250             int position = separatorPosition + 1;
 251             int n = windowMenuWindows.length;
 252 
 253             for (int i = 0; i < n; i++) {
 254                 if (windowMenuWindows[i] != null) {
 255                     // Slot is in use, try next
 256                     position++;
 257                 } else {


 701                     }
 702                 } else {
 703                     String[] s = txt.split(":");
 704                     if (s.length == 2) {
 705                         try {
 706                             int port = Integer.parseInt(s[1]);
 707                             if (port >= 0 && port <= 0xFFFF) {
 708                                 valid = true;
 709                             }
 710                         } catch (NumberFormatException ex) {
 711                             valid = false;
 712                         }
 713                     }
 714                 }
 715             }
 716         }
 717         return valid;
 718     }
 719 
 720     private String errorMessage(Exception ex) {
 721        String msg = Messages.CONNECTION_FAILED;
 722        if (ex instanceof IOException || ex instanceof SecurityException) {
 723            Throwable cause = null;
 724            Throwable c = ex.getCause();
 725            while (c != null) {
 726                cause = c;
 727                c = c.getCause();
 728            }
 729            if (cause instanceof ConnectException) {
 730                return msg + ": " + cause.getMessage();
 731            } else if (cause instanceof UnknownHostException) {
 732                return Resources.format(Messages.UNKNOWN_HOST, cause.getMessage());
 733            } else if (cause instanceof NoRouteToHostException) {
 734                return msg + ": " + cause.getMessage();
 735            } else if (cause instanceof FailedLoginException) {
 736                return msg + ": " + cause.getMessage();
 737            } else if (cause instanceof SSLHandshakeException) {
 738                return msg + ": "+ cause.getMessage();
 739            }
 740         } else if (ex instanceof MalformedURLException) {
 741            return Resources.format(Messages.INVALID_URL, ex.getMessage());
 742         }
 743         return msg + ": " + ex.getMessage();
 744     }
 745 
 746 
 747     // InternalFrameListener interface
 748 
 749     public void internalFrameClosing(InternalFrameEvent e) {
 750         VMInternalFrame vmIF = (VMInternalFrame)e.getInternalFrame();
 751         removeVMInternalFrame(vmIF);
 752         windows.remove(vmIF);
 753         ProxyClient client = vmIF.getVMPanel().getProxyClient(false);
 754         if(!isProxyClientUsed(client))
 755             client.markAsDead();
 756         if (windows.size() == 0) {
 757             showConnectDialog("", "", 0, null, null, null);
 758         }
 759     }
 760 
 761     public void internalFrameOpened(InternalFrameEvent e) {}
 762     public void internalFrameClosed(InternalFrameEvent e) {}
 763     public void internalFrameIconified(InternalFrameEvent e) {}
 764     public void internalFrameDeiconified(InternalFrameEvent e) {}
 765     public void internalFrameActivated(InternalFrameEvent e) {}
 766     public void internalFrameDeactivated(InternalFrameEvent e) {}
 767 
 768 
 769     private static void usage() {
 770         System.err.println(Resources.format(Messages.ZZ_USAGE_TEXT, "jconsole"));
 771     }
 772 
 773     private static void mainInit(final List<String> urls,
 774                                  final List<String> hostNames,
 775                                  final List<Integer> ports,
 776                                  final List<LocalVirtualMachine> vmids,
 777                                  final ProxyClient proxyClient,
 778                                  final boolean noTile,
 779                                  final boolean hotspot) {
 780 
 781 
 782         // Always create Swing GUI on the Event Dispatching Thread
 783         SwingUtilities.invokeLater(new Runnable() {
 784                 public void run() {
 785                     JConsole jConsole = new JConsole(hotspot);
 786 
 787                     // Center the window on screen, taking into account screen
 788                     // size and insets.
 789                     Toolkit toolkit = Toolkit.getDefaultToolkit();
 790                     GraphicsConfiguration gc = jConsole.getGraphicsConfiguration();


 983             plugins.add(p);
 984         }
 985         return plugins;
 986     }
 987 
 988     private static void initPluginService(String pluginPath) {
 989         if (pluginPath.length() > 0) {
 990             try {
 991                 ClassLoader pluginCL = new URLClassLoader(pathToURLs(pluginPath));
 992                 ServiceLoader<JConsolePlugin> plugins =
 993                     ServiceLoader.load(JConsolePlugin.class, pluginCL);
 994                 // validate all plugins
 995             for (JConsolePlugin p : plugins) {
 996                     if (isDebug()) {
 997                         System.out.println("Plugin " + p.getClass() + " loaded.");
 998                     }
 999                 }
1000                 pluginService = plugins;
1001             } catch (ServiceConfigurationError e) {
1002                 // Error occurs during initialization of plugin
1003                 System.out.println(Resources.format(Messages.FAIL_TO_LOAD_PLUGIN,
1004                                    e.getMessage()));
1005             } catch (MalformedURLException e) {
1006                 if (JConsole.isDebug()) {
1007                     e.printStackTrace();
1008                 }
1009                 System.out.println(Resources.format(Messages.INVALID_PLUGIN_PATH,
1010                                    e.getMessage()));
1011             }
1012         }
1013 
1014         if (pluginService == null) {
1015             initEmptyPlugin();
1016         }
1017     }
1018 
1019     private static void initEmptyPlugin() {
1020         ClassLoader pluginCL = new URLClassLoader(new URL[0]);
1021         pluginService = ServiceLoader.load(JConsolePlugin.class, pluginCL);
1022     }
1023 
1024    /**
1025      * Utility method for converting a search path string to an array
1026      * of directory and JAR file URLs.
1027      *
1028      * @param path the search path string
1029      * @return the resulting array of directory and JAR file URLs