< prev index next >

src/jdk.jcmd/share/classes/sun/tools/jcmd/JCmd.java

Print this page
rev 48074 : 8189102: All tools should support -?, -h and --help
Reviewed-by: kvn, jjg, weijun, alanb, rfield, ksrini
   1 /*
   2  * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  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


  45 import sun.jvmstat.monitor.Monitor;
  46 import sun.jvmstat.monitor.MonitoredHost;
  47 import sun.jvmstat.monitor.MonitoredVm;
  48 import sun.jvmstat.monitor.MonitorException;
  49 import sun.jvmstat.monitor.VmIdentifier;
  50 
  51 public class JCmd {
  52     public static void main(String[] args) {
  53         Arguments arg = null;
  54         try {
  55             arg = new Arguments(args);
  56         } catch (IllegalArgumentException ex) {
  57             System.err.println("Error parsing arguments: " + ex.getMessage()
  58                                + "\n");
  59             Arguments.usage();
  60             System.exit(1);
  61         }
  62 
  63         if (arg.isShowUsage()) {
  64             Arguments.usage();
  65             System.exit(1);
  66         }
  67 
  68         ProcessArgumentMatcher ap = null;
  69         try {
  70             ap = new ProcessArgumentMatcher(arg.getProcessString());
  71         } catch (IllegalArgumentException iae) {
  72             System.err.println("Invalid pid '" + arg.getProcessString()  + "' specified");
  73             System.exit(1);
  74         }
  75 
  76         if (arg.isListProcesses()) {
  77             for (VirtualMachineDescriptor vmd : ap.getVirtualMachineDescriptors(/* include jcmd in listing */)) {
  78                 System.out.println(vmd.id() + " " + vmd.displayName());
  79             }
  80             System.exit(0);
  81         }
  82 
  83         Collection<String> pids = ap.getVirtualMachinePids(JCmd.class);
  84 
  85         if (pids.isEmpty()) {


   1 /*
   2  * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  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


  45 import sun.jvmstat.monitor.Monitor;
  46 import sun.jvmstat.monitor.MonitoredHost;
  47 import sun.jvmstat.monitor.MonitoredVm;
  48 import sun.jvmstat.monitor.MonitorException;
  49 import sun.jvmstat.monitor.VmIdentifier;
  50 
  51 public class JCmd {
  52     public static void main(String[] args) {
  53         Arguments arg = null;
  54         try {
  55             arg = new Arguments(args);
  56         } catch (IllegalArgumentException ex) {
  57             System.err.println("Error parsing arguments: " + ex.getMessage()
  58                                + "\n");
  59             Arguments.usage();
  60             System.exit(1);
  61         }
  62 
  63         if (arg.isShowUsage()) {
  64             Arguments.usage();
  65             System.exit(0);
  66         }
  67 
  68         ProcessArgumentMatcher ap = null;
  69         try {
  70             ap = new ProcessArgumentMatcher(arg.getProcessString());
  71         } catch (IllegalArgumentException iae) {
  72             System.err.println("Invalid pid '" + arg.getProcessString()  + "' specified");
  73             System.exit(1);
  74         }
  75 
  76         if (arg.isListProcesses()) {
  77             for (VirtualMachineDescriptor vmd : ap.getVirtualMachineDescriptors(/* include jcmd in listing */)) {
  78                 System.out.println(vmd.id() + " " + vmd.displayName());
  79             }
  80             System.exit(0);
  81         }
  82 
  83         Collection<String> pids = ap.getVirtualMachinePids(JCmd.class);
  84 
  85         if (pids.isEmpty()) {


< prev index next >