1 /*
2 * Copyright (c) 2004, 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
60
61 // get the set active JVMs on the specified host.
62 Set jvms = monitoredHost.activeVms();
63
64 for (Iterator j = jvms.iterator(); j.hasNext(); /* empty */ ) {
65 StringBuilder output = new StringBuilder();
66 Throwable lastError = null;
67
68 int lvmid = ((Integer)j.next()).intValue();
69
70 output.append(String.valueOf(lvmid));
71
72 if (arguments.isQuiet()) {
73 System.out.println(output);
74 continue;
75 }
76
77 MonitoredVm vm = null;
78 String vmidString = "//" + lvmid + "?mode=r";
79
80 try {
81 VmIdentifier id = new VmIdentifier(vmidString);
82 vm = monitoredHost.getMonitoredVm(id, 0);
83 } catch (URISyntaxException e) {
84 // unexpected as vmidString is based on a validated hostid
85 lastError = e;
86 assert false;
87 } catch (Exception e) {
88 lastError = e;
89 } finally {
90 if (vm == null) {
91 /*
92 * we ignore most exceptions, as there are race
93 * conditions where a JVM in 'jvms' may terminate
94 * before we get a chance to list its information.
95 * Other errors, such as access and I/O exceptions
96 * should stop us from iterating over the complete set.
97 */
98 output.append(" -- process information unavailable");
99 if (arguments.isDebug()) {
100 if ((lastError != null)
101 && (lastError.getMessage() != null)) {
102 output.append("\n\t");
103 output.append(lastError.getMessage());
104 }
105 }
106 System.out.println(output);
107 if (arguments.printStackTrace()) {
108 lastError.printStackTrace();
109 }
110 continue;
111 }
112 }
113
114 output.append(" ");
115 output.append(MonitoredVmUtil.mainClass(vm,
116 arguments.showLongPaths()));
117
118 if (arguments.showMainArgs()) {
119 String mainArgs = MonitoredVmUtil.mainArgs(vm);
120 if (mainArgs != null && mainArgs.length() > 0) {
121 output.append(" ").append(mainArgs);
122 }
123 }
124 if (arguments.showVmArgs()) {
125 String jvmArgs = MonitoredVmUtil.jvmArgs(vm);
126 if (jvmArgs != null && jvmArgs.length() > 0) {
127 output.append(" ").append(jvmArgs);
128 }
129 }
130 if (arguments.showVmFlags()) {
131 String jvmFlags = MonitoredVmUtil.jvmFlags(vm);
132 if (jvmFlags != null && jvmFlags.length() > 0) {
133 output.append(" ").append(jvmFlags);
134 }
135 }
136
137 System.out.println(output);
138
139 monitoredHost.detach(vm);
140 }
141 } catch (MonitorException e) {
142 if (e.getMessage() != null) {
143 System.err.println(e.getMessage());
144 } else {
145 Throwable cause = e.getCause();
146 if ((cause != null) && (cause.getMessage() != null)) {
147 System.err.println(cause.getMessage());
148 } else {
149 e.printStackTrace();
150 }
151 }
152 }
153 }
154 }
|
1 /*
2 * Copyright (c) 2004, 2011, 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
60
61 // get the set active JVMs on the specified host.
62 Set jvms = monitoredHost.activeVms();
63
64 for (Iterator j = jvms.iterator(); j.hasNext(); /* empty */ ) {
65 StringBuilder output = new StringBuilder();
66 Throwable lastError = null;
67
68 int lvmid = ((Integer)j.next()).intValue();
69
70 output.append(String.valueOf(lvmid));
71
72 if (arguments.isQuiet()) {
73 System.out.println(output);
74 continue;
75 }
76
77 MonitoredVm vm = null;
78 String vmidString = "//" + lvmid + "?mode=r";
79
80 String errorString = null;
81
82 try {
83 // Note: The VM associated with the current VM id may
84 // no longer be running so these queries may fail. We
85 // already added the VM id to the output stream above.
86 // If one of the queries fails, then we try to add a
87 // reasonable message to indicate that the requested
88 // info is not available.
89
90 errorString = " -- process information unavailable";
91 VmIdentifier id = new VmIdentifier(vmidString);
92 vm = monitoredHost.getMonitoredVm(id, 0);
93
94 // leading blank not needed here because of the
95 // next append() call
96 errorString = "-- main class information unavailable";
97 output.append(" ");
98 output.append(MonitoredVmUtil.mainClass(vm,
99 arguments.showLongPaths()));
100
101 if (arguments.showMainArgs()) {
102 errorString = " -- main args information unavailable";
103 String mainArgs = MonitoredVmUtil.mainArgs(vm);
104 if (mainArgs != null && mainArgs.length() > 0) {
105 output.append(" ").append(mainArgs);
106 }
107 }
108 if (arguments.showVmArgs()) {
109 errorString = " -- jvm args information unavailable";
110 String jvmArgs = MonitoredVmUtil.jvmArgs(vm);
111 if (jvmArgs != null && jvmArgs.length() > 0) {
112 output.append(" ").append(jvmArgs);
113 }
114 }
115 if (arguments.showVmFlags()) {
116 errorString = " -- jvm flags information unavailable";
117 String jvmFlags = MonitoredVmUtil.jvmFlags(vm);
118 if (jvmFlags != null && jvmFlags.length() > 0) {
119 output.append(" ").append(jvmFlags);
120 }
121 }
122
123 errorString = " -- detach failed";
124 monitoredHost.detach(vm);
125
126 System.out.println(output);
127
128 errorString = null;
129 } catch (URISyntaxException e) {
130 // unexpected as vmidString is based on a validated hostid
131 lastError = e;
132 assert false;
133 } catch (Exception e) {
134 lastError = e;
135 } finally {
136 if (errorString != null) {
137 /*
138 * we ignore most exceptions, as there are race
139 * conditions where a JVM in 'jvms' may terminate
140 * before we get a chance to list its information.
141 * Other errors, such as access and I/O exceptions
142 * should stop us from iterating over the complete set.
143 */
144 output.append(errorString);
145 if (arguments.isDebug()) {
146 if ((lastError != null)
147 && (lastError.getMessage() != null)) {
148 output.append("\n\t");
149 output.append(lastError.getMessage());
150 }
151 }
152 System.out.println(output);
153 if (arguments.printStackTrace()) {
154 lastError.printStackTrace();
155 }
156 continue;
157 }
158 }
159 }
160 } catch (MonitorException e) {
161 if (e.getMessage() != null) {
162 System.err.println(e.getMessage());
163 } else {
164 Throwable cause = e.getCause();
165 if ((cause != null) && (cause.getMessage() != null)) {
166 System.err.println(cause.getMessage());
167 } else {
168 e.printStackTrace();
169 }
170 }
171 }
172 }
173 }
|