当前位置: 首页>>代码示例>>Java>>正文


Java VirtualMachine.list方法代码示例

本文整理汇总了Java中com.sun.tools.attach.VirtualMachine.list方法的典型用法代码示例。如果您正苦于以下问题:Java VirtualMachine.list方法的具体用法?Java VirtualMachine.list怎么用?Java VirtualMachine.list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.tools.attach.VirtualMachine的用法示例。


在下文中一共展示了VirtualMachine.list方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getVmDescByServerName

import com.sun.tools.attach.VirtualMachine; //导入方法依赖的package包/类
/**
 * 获取指定服务名的本地JMX VM 描述对象
 * @param serverName
 * @return
 */
public static List<VirtualMachineDescriptor> getVmDescByServerName(String serverName){
    List<VirtualMachineDescriptor> vmDescList = new ArrayList<>();
    if (StringUtils.isEmpty(serverName)){
        return vmDescList;
    }
    List<VirtualMachineDescriptor> vms = VirtualMachine.list();
    for (VirtualMachineDescriptor desc : vms) {
        //java -jar 形式启动的Java应用
        if(desc.displayName().matches(".*\\.jar(\\s*-*.*)*") && desc.displayName().contains(serverName)){
            vmDescList.add(desc);
        }else if(hasContainsServerName(desc.displayName(),serverName)){
            vmDescList.add(desc);
        }else if (isJSVC(desc.id(),serverName)){
            VirtualMachineDescriptor descriptor = new VirtualMachineDescriptor(desc.provider(),desc.id(),serverName);
            vmDescList.add(descriptor);
        }
    }
    return vmDescList;
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:25,代码来源:JMXUtil.java

示例2: repopulate

import com.sun.tools.attach.VirtualMachine; //导入方法依赖的package包/类
/**
 * Update JVM sub-list.
 */
private final void repopulate() {
	removeAll();
	for (VirtualMachineDescriptor vm : VirtualMachine.list()) {
		add(new ActionMenuItem(vm.displayName(), () -> Attach.attach(vm)));
	}
	revalidate();
}
 
开发者ID:Col-E,项目名称:Recaf,代码行数:11,代码来源:JVMMenu.java

示例3: main

import com.sun.tools.attach.VirtualMachine; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

    if (args.length < 2 || args.length > 3) {
      System.err.println("Usage: java -cp dir/agent.jar:/.../jvm/java-8-jdk/lib/tools.jar " +
          "io.prometheus.jmx.shaded.io.prometheus.jmx.Attach pid [host:]<port>:<yaml configuration file>");
      System.exit(1);
    }


    List<VirtualMachineDescriptor> vms = VirtualMachine.list();
    VirtualMachineDescriptor selectedVM = null;
    for (VirtualMachineDescriptor vmd : vms) {
      if (vmd.id().equals(args[0])) {
        selectedVM = vmd;
      }
    }

    if (selectedVM == null) {
      System.err.println("No such java process with pid=" + args[0]);
      System.exit(-1);
    }

    VirtualMachine attachedVm = VirtualMachine.attach(selectedVM);
    File currentJarFile = new File(Attach.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());

    attachedVm.loadAgent(currentJarFile.getAbsolutePath(), args[1]);
    attachedVm.detach();

  }
 
开发者ID:flokkr,项目名称:jmxpromo,代码行数:30,代码来源:Attach.java

示例4: isProcessAlive

import com.sun.tools.attach.VirtualMachine; //导入方法依赖的package包/类
@Override
public boolean isProcessAlive(final int pid) {
  for (VirtualMachineDescriptor vm : VirtualMachine.list()) {
    if (vm.id().equals(String.valueOf(pid))) {
      return true; // found the vm
    }
  }
  return false;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:10,代码来源:AttachProcessUtils.java

示例5: getSingleVMD

import com.sun.tools.attach.VirtualMachine; //导入方法依赖的package包/类
private static Collection<VirtualMachineDescriptor> getSingleVMD(String pid) {
    Collection<VirtualMachineDescriptor> vids = new ArrayList<>();
    List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
    for (VirtualMachineDescriptor vmd : vmds) {
        if (check(vmd, null, null)) {
            if (pid.equals(vmd.id())) {
                vids.add(vmd);
            }
        }
    }
    return vids;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:ProcessArgumentMatcher.java

示例6: getVMDs

import com.sun.tools.attach.VirtualMachine; //导入方法依赖的package包/类
private static Collection<VirtualMachineDescriptor> getVMDs(Class<?> excludeClass, String partialMatch) {
    String excludeCls = getExcludeStringFrom(excludeClass);
    Collection<VirtualMachineDescriptor> vids = new ArrayList<>();
    List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
    for (VirtualMachineDescriptor vmd : vmds) {
        if (check(vmd, excludeCls, partialMatch)) {
            vids.add(vmd);
        }
    }
    return vids;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ProcessArgumentMatcher.java

示例7: main

import com.sun.tools.attach.VirtualMachine; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	
	if (args.length < 2)
	{
		logOut("Not enough arguments given. This code requires, in this order:");
		logOut("1) The PID of JVM to attach to.");
		logOut("1) The absolute location of the agent jar to be attached.");
		logOut("3) (optional) Any arguments to be passed to the java agent.");
		System.exit(1);
	}
	String vmPidArg = args[0];
	Integer.parseInt(vmPidArg); //Just to make sure it's a number.
	logOut("Will attempt to attach to JVM with pid " + vmPidArg);

	String agentPathString = args[1];

	logOut("Attach will be done using agent jar file: " + agentPathString);
	
	// This may cause a compiler error in eclipse, as it is not a java.* class
	// It can be fixed by editing the access rules for the JRE system library
	// attach to target VM
	
	//First we wait for the target VM to become available
	boolean foundTarget = false;
	while (!foundTarget) {
		List<VirtualMachineDescriptor> allVMs = VirtualMachine.list();
		for (VirtualMachineDescriptor oneVM : allVMs) {
			if (oneVM.id().equals(vmPidArg)) {
				foundTarget = true;
			}
		}
		if (!foundTarget) {
			Thread.sleep(1000);
		}
	}
	
	//Then we attach to it.
	VirtualMachine vm = VirtualMachine.attach(vmPidArg);
	
	// load agent into target VM
	try {
		if (args.length > 2) {
			vm.loadAgent(agentPathString, args[2]);
		} else {
			vm.loadAgent(agentPathString);
		}
	} catch (java.io.IOException e) {
		//This exception is thrown if the test process terminates before the agent does. 
		//We don't mind if this happens.
	}
	
	// detach
	vm.detach();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:55,代码来源:Attacher.java


注:本文中的com.sun.tools.attach.VirtualMachine.list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。