當前位置: 首頁>>代碼示例>>Java>>正文


Java AttachNotSupportedException類代碼示例

本文整理匯總了Java中com.sun.tools.attach.AttachNotSupportedException的典型用法代碼示例。如果您正苦於以下問題:Java AttachNotSupportedException類的具體用法?Java AttachNotSupportedException怎麽用?Java AttachNotSupportedException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AttachNotSupportedException類屬於com.sun.tools.attach包,在下文中一共展示了AttachNotSupportedException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public static void main(String[] args) throws IOException,
		AttachNotSupportedException, AgentLoadException,
		AgentInitializationException, InterruptedException {
	// 獲取當前jvm的進程pid
	String pid = ManagementFactory.getRuntimeMXBean().getName();
	int indexOf = pid.indexOf('@');
	if (indexOf > 0) {
		pid = pid.substring(0, indexOf);
	}
	System.out.println("當前JVM Process ID: " + pid);
	// 獲取當前jvm
	VirtualMachine vm = VirtualMachine.attach(pid);
	// 當前jvm加載代理jar包,參數1是jar包路徑地址,參數2是給jar包代理類傳遞的參數
	vm.loadAgent("D:/123.jar", "my agent:123.jar");
	Thread.sleep(1000);
	vm.detach();
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:18,代碼來源:AgentLoad.java

示例2: main

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public static void main(String[] args) throws AttachNotSupportedException,
		IOException, AgentLoadException, AgentInitializationException,
		InterruptedException {
	VirtualMachine vm=AgentUtil.getCurrentVm();
	//先載入agent
	vm.loadAgent("d:/springloaded-1.2.1.RELEASE.jar","myagent");
	System.out.println("加載agent成功");
	vm.detach();
	TestSpringLoacedClass t1=new TestSpringLoacedClass();
	for(int i=0;i<10000;i++)
	{
		TestSpringLoacedClass t2=new TestSpringLoacedClass();
		t1.say2();
		t2.say2();
		Thread.sleep(1000);
	}
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:18,代碼來源:TestSpringLoaded.java

示例3: attach

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
private static VirtualMachine attach(String pid) {
    try {
        return VirtualMachine.attach(pid);
    } catch (Exception x) {
        String msg = x.getMessage();
        if (msg != null) {
            System.err.println(pid + ": " + msg);
        } else {
            x.printStackTrace();
        }
        if ((x instanceof AttachNotSupportedException) && haveSA()) {
            System.err.println("The -F option can be used when the " +
              "target process is not responding");
        }
        System.exit(1);
        return null; // keep compiler happy
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:JMap.java

示例4: loadManagementAgent

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
private void loadManagementAgent() throws IOException {
    VirtualMachine vm = null;
    String name = String.valueOf(vmid);
    try {
        vm = VirtualMachine.attach(name);
    } catch (AttachNotSupportedException x) {
        IOException ioe = new IOException(x.getMessage());
        ioe.initCause(x);
        throw ioe;
    }

    vm.startLocalManagementAgent();

    // get the connector address
    Properties agentProps = vm.getAgentProperties();
    address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);

    vm.detach();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:LocalVirtualMachine.java

示例5: attachVirtualMachine

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
    throws AttachNotSupportedException, IOException
{
    if (vmd.provider() != this) {
        throw new AttachNotSupportedException("provider mismatch");
    }
    // To avoid re-checking if the VM if attachable, we check if the descriptor
    // is for a hotspot VM - these descriptors are created by the listVirtualMachines
    // implementation which only returns a list of attachable VMs.
    if (vmd instanceof HotSpotVirtualMachineDescriptor) {
        assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
        checkAttachPermission();
        return new SolarisVirtualMachine(this, vmd.id());
    } else {
        return attachVirtualMachine(vmd.id());
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:SolarisAttachProvider.java

示例6: attachVirtualMachine

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
    throws AttachNotSupportedException, IOException
{
    if (vmd.provider() != this) {
        throw new AttachNotSupportedException("provider mismatch");
    }
    // To avoid re-checking if the VM if attachable, we check if the descriptor
    // is for a hotspot VM - these descriptors are created by the listVirtualMachines
    // implementation which only returns a list of attachable VMs.
    if (vmd instanceof HotSpotVirtualMachineDescriptor) {
        assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
        checkAttachPermission();
        return new BsdVirtualMachine(this, vmd.id());
    } else {
        return attachVirtualMachine(vmd.id());
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:BsdAttachProvider.java

示例7: attachVirtualMachine

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
    throws AttachNotSupportedException, IOException
{
    if (vmd.provider() != this) {
        throw new AttachNotSupportedException("provider mismatch");
    }
    // To avoid re-checking if the VM if attachable, we check if the descriptor
    // is for a hotspot VM - these descriptors are created by the listVirtualMachines
    // implementation which only returns a list of attachable VMs.
    if (vmd instanceof HotSpotVirtualMachineDescriptor) {
        assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
        checkAttachPermission();
        return new LinuxVirtualMachine(this, vmd.id());
    } else {
        return attachVirtualMachine(vmd.id());
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:LinuxAttachProvider.java

示例8: attachVirtualMachine

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
    throws AttachNotSupportedException, IOException
{
    if (vmd.provider() != this) {
        throw new AttachNotSupportedException("provider mismatch");
    }
    // To avoid re-checking if the VM if attachable, we check if the descriptor
    // is for a hotspot VM - these descriptors are created by the listVirtualMachines
    // implementation which only returns a list of attachable VMs.
    if (vmd instanceof HotSpotVirtualMachineDescriptor) {
        assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
        checkAttachPermission();
        return new AixVirtualMachine(this, vmd.id());
    } else {
        return attachVirtualMachine(vmd.id());
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:AixAttachProvider.java

示例9: main

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public static void main(String args[]) throws Exception {
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        throw new RuntimeException("Test configuration error - no security manager set");
    }

    String pid = args[0];
    boolean shouldFail = Boolean.parseBoolean(args[1]);

    try {
        VirtualMachine.attach(pid).detach();
        if (shouldFail) {
            throw new RuntimeException("SecurityException should be thrown");
        }
        System.out.println(" - attached to target VM as expected.");
    } catch (Exception x) {
        // AttachNotSupportedException thrown when no providers can be loaded
        if (shouldFail && ((x instanceof AttachNotSupportedException) ||
            (x instanceof SecurityException))) {
            System.out.println(" - exception thrown as expected.");
        } else {
            throw x;
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:PermissionTest.java

示例10: attach

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public static void attach(Class<? extends Agent> agentClass, List<Class<?>> classes, File... libs) throws AgentInstantiationException, AttachNotSupportedException, AgentLoadException, AgentInitializationException, NotFoundException, CannotCompileException, IOException {
    try {
        Agent agent = agentClass.newInstance();
        VirtualMachine vm;
        switch (agent.type()) {
            case MAIN:
                vm = get1(agent.target());
                break;
            case PID:
                vm = get2(agent.target());
                break;
            default:
                vm = null;
                break;
        }
        load(vm, agent, classes, libs);
    } catch (IllegalAccessException | InstantiationException e) {
        throw new AgentInstantiationException();
    }
}
 
開發者ID:ZeroMemes,項目名稱:Agent-Lib,代碼行數:21,代碼來源:AgentLoader.java

示例11: executeCommandForPid

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
private static void executeCommandForPid(String pid, String command, Object ... args)
    throws AttachNotSupportedException, IOException,
           UnsupportedEncodingException {
    VirtualMachine vm = VirtualMachine.attach(pid);

    // Cast to HotSpotVirtualMachine as this is an
    // implementation specific method.
    HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm;
    try (InputStream in = hvm.executeCommand(command, args)) {
      // read to EOF and just print output
      byte b[] = new byte[256];
      int n;
      do {
          n = in.read(b);
          if (n > 0) {
              String s = new String(b, 0, n, "UTF-8");
              System.out.print(s);
          }
      } while (n > 0);
    }
    vm.detach();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:JMap.java

示例12: histo

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
private static void histo(String pid, String options)
    throws AttachNotSupportedException, IOException,
           UnsupportedEncodingException {
    String liveopt = "-all";
    if (options.equals("") || options.equals("all")) {
        //  pass
    }
    else if (options.equals("live")) {
        liveopt = "-live";
    }
    else {
        usage(1);
    }

    // inspectHeap is not the same as jcmd GC.class_histogram
    executeCommandForPid(pid, "inspectheap", liveopt);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:JMap.java

示例13: HotSpotVirtualMachine

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
HotSpotVirtualMachine(AttachProvider provider, String id)
    throws AttachNotSupportedException, IOException
{
    super(provider, id);

    int pid;
    try {
        pid = Integer.parseInt(id);
    } catch (NumberFormatException e) {
        throw new AttachNotSupportedException("Invalid process identifier");
    }

    // The tool should be a different VM to the target. This check will
    // eventually be enforced by the target VM.
    if (!ALLOW_ATTACH_SELF && (pid == 0 || pid == CURRENT_PID)) {
        throw new IOException("Can not attach to current VM");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:HotSpotVirtualMachine.java

示例14: attachVirtualMachine

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
    throws AttachNotSupportedException, IOException
{
    if (vmd.provider() != this) {
        throw new AttachNotSupportedException("provider mismatch");
    }
    // To avoid re-checking if the VM if attachable, we check if the descriptor
    // is for a hotspot VM - these descriptors are created by the listVirtualMachines
    // implementation which only returns a list of attachable VMs.
    if (vmd instanceof HotSpotVirtualMachineDescriptor) {
        assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
        checkAttachPermission();
        return new VirtualMachineImpl(this, vmd.id());
    } else {
        return attachVirtualMachine(vmd.id());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:AttachProviderImpl.java

示例15: getTaskPort

import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
@Override
public int getTaskPort(BTraceTask task) {
    VirtualMachine vm = null;
    try {
        vm = attach(valueOf(task.getPid()));
        String portStr = vm.getSystemProperties().getProperty(PORT_PROPERTY);
        return portStr != null ? parseInt(portStr) : findFreePort();
    } catch (AttachNotSupportedException | IOException ex) {
        getLogger(PortLocatorImpl.class.getName()).log(SEVERE, null, ex);
    } finally {
        if (vm != null) {
            try {
                vm.detach();
            } catch (IOException e) {
                LOGGER.log(SEVERE, null, e);
            }
        }
    }
    return findFreePort();
}
 
開發者ID:btraceio,項目名稱:btrace.nb,代碼行數:21,代碼來源:PortLocatorImpl.java


注:本文中的com.sun.tools.attach.AttachNotSupportedException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。