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.common;
27
28 import java.lang.reflect.Module;
29 import java.net.URISyntaxException;
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.List;
33
34 import com.sun.tools.attach.VirtualMachine;
35 import com.sun.tools.attach.VirtualMachineDescriptor;
36
37 import sun.jvmstat.monitor.MonitorException;
38 import sun.jvmstat.monitor.MonitoredHost;
39 import sun.jvmstat.monitor.MonitoredVm;
40 import sun.jvmstat.monitor.MonitoredVmUtil;
41 import sun.jvmstat.monitor.VmIdentifier;
42
43 /**
44 * Class for finding process matching a process argument,
45 * excluding tool it self and returning a list containing
46 * the process identifiers.
47 */
48 public class ProcessArgumentMatcher {
49 private String matchClass;
50 private String singlePid;
51
52 public ProcessArgumentMatcher(String pidArg) {
128 for (VirtualMachineDescriptor vmd : vmds) {
129 if (check(vmd, excludeCls, partialMatch)) {
130 vids.add(vmd);
131 }
132 }
133 return vids;
134 }
135
136 public Collection<VirtualMachineDescriptor> getVirtualMachineDescriptors(Class<?> excludeClass) {
137 if (singlePid != null) {
138 return getSingleVMD(singlePid);
139 } else {
140 return getVMDs(excludeClass, matchClass);
141 }
142 }
143
144 public Collection<VirtualMachineDescriptor> getVirtualMachineDescriptors() {
145 return this.getVirtualMachineDescriptors(null);
146 }
147
148 }
|
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.common;
27
28 import java.lang.reflect.Module;
29 import java.net.URISyntaxException;
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.List;
33 import java.util.stream.Collectors;
34
35 import com.sun.tools.attach.VirtualMachine;
36 import com.sun.tools.attach.VirtualMachineDescriptor;
37
38 import sun.jvmstat.monitor.MonitorException;
39 import sun.jvmstat.monitor.MonitoredHost;
40 import sun.jvmstat.monitor.MonitoredVm;
41 import sun.jvmstat.monitor.MonitoredVmUtil;
42 import sun.jvmstat.monitor.VmIdentifier;
43
44 /**
45 * Class for finding process matching a process argument,
46 * excluding tool it self and returning a list containing
47 * the process identifiers.
48 */
49 public class ProcessArgumentMatcher {
50 private String matchClass;
51 private String singlePid;
52
53 public ProcessArgumentMatcher(String pidArg) {
129 for (VirtualMachineDescriptor vmd : vmds) {
130 if (check(vmd, excludeCls, partialMatch)) {
131 vids.add(vmd);
132 }
133 }
134 return vids;
135 }
136
137 public Collection<VirtualMachineDescriptor> getVirtualMachineDescriptors(Class<?> excludeClass) {
138 if (singlePid != null) {
139 return getSingleVMD(singlePid);
140 } else {
141 return getVMDs(excludeClass, matchClass);
142 }
143 }
144
145 public Collection<VirtualMachineDescriptor> getVirtualMachineDescriptors() {
146 return this.getVirtualMachineDescriptors(null);
147 }
148
149 public Collection<String> getVirtualMachinePids(Class<?> excludeClass) {
150 if (singlePid != null) {
151 // There is a bug in AttachProvider, when VM is debugge-suspened it's not listed by the AttachProvider.
152 // If we are talking about a specific pid, just return it.
153 return List.of(singlePid);
154 } else {
155 return getVMDs(excludeClass, matchClass).stream().map(x -> {return x.id();}).collect(Collectors.toList());
156 }
157 }
158
159 public Collection<String> getVirtualMachinePids() {
160 return this.getVirtualMachinePids(null);
161 }
162 }
|