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


Java AgentLoadException类代码示例

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


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

示例1: main

import com.sun.tools.attach.AgentLoadException; //导入依赖的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.AgentLoadException; //导入依赖的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: loadAgentLibrary

import com.sun.tools.attach.AgentLoadException; //导入依赖的package包/类
private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options)
    throws AgentLoadException, AgentInitializationException, IOException
{
    InputStream in = execute("load",
                             agentLibrary,
                             isAbsolute ? "true" : "false",
                             options);
    try {
        int result = readInt(in);
        if (result != 0) {
            throw new AgentInitializationException("Agent_OnAttach failed", result);
        }
    } finally {
        in.close();

    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:HotSpotVirtualMachine.java

示例4: attach

import com.sun.tools.attach.AgentLoadException; //导入依赖的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

示例5: testBadModification2

import com.sun.tools.attach.AgentLoadException; //导入依赖的package包/类
@Test
public void testBadModification2() throws ClassNotFoundException, AgentLoadException, AgentInitializationException, IOException, AttachNotSupportedException, UnmodifiableClassException, IllegalConnectorArgumentsException {
    // Rewrite method
    DynamicModification badModification = new DynamicModification() {
        public Collection<String> affects() {
            return Lists.newArrayList(TestJDWPAgentDebug.class.getName());
        }
        public void apply(ClassPool arg0) throws NotFoundException, CannotCompileException {
            CtClass cls = arg0.getCtClass(TestJDWPAgentDebug.class.getName());
            cls.getMethods()[0].insertBefore("definitely not code...");
        }
    };
    JDWPAgent dynamic = JDWPAgent.get();
    // Modification should just be ignored since it throws a notfoundexception
    try {
        dynamic.install(badModification);
        fail();
    } catch (CannotCompileException e) {
    }
}
 
开发者ID:brownsys,项目名称:tracing-framework,代码行数:21,代码来源:TestJDWPAgentDebug.java

示例6: testBadModification2

import com.sun.tools.attach.AgentLoadException; //导入依赖的package包/类
@Test
public void testBadModification2() throws ClassNotFoundException, AgentLoadException, AgentInitializationException, IOException, AttachNotSupportedException, UnmodifiableClassException {
    // Rewrite method
    DynamicModification badModification = new DynamicModification() {
        public Collection<String> affects() {
            return Lists.newArrayList(TestJVMAgent.class.getName());
        }
        public void apply(ClassPool arg0) throws NotFoundException, CannotCompileException {
            CtClass cls = arg0.getCtClass(TestJVMAgent.class.getName());
            cls.getMethods()[0].insertBefore("definitely not code...");
        }
    };
    JVMAgent dynamic = JVMAgent.get();
    // Modification should just be ignored since it throws a notfoundexception
    try {
        dynamic.install(badModification);
        fail();
    } catch (CannotCompileException e) {
    }
}
 
开发者ID:brownsys,项目名称:tracing-framework,代码行数:21,代码来源:TestJVMAgent.java

示例7: loadAgentLibrary

import com.sun.tools.attach.AgentLoadException; //导入依赖的package包/类
/**
 * Load agent library.
 * If isAbsolute is true then the agent library is the absolute path to the library and thus
 * will not be expanded in the target VM.
 * If isAbsolute is false then the agent library is just a library name and it will be expended
 * in the target VM.
 */
private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options)
   throws AgentLoadException, AgentInitializationException, IOException
{
   InputStream in = execute("load", agentLibrary, isAbsolute ? "true" : "false", options);

   try {
      int result = readInt(in);

      if (result != 0) {
         throw new AgentInitializationException("Agent_OnAttach failed", result);
      }
   }
   finally {
      in.close();
   }
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:24,代码来源:HotSpotVirtualMachine.java

示例8: init

import com.sun.tools.attach.AgentLoadException; //导入依赖的package包/类
private void init(File agentJar) throws AgentInitializationException, AgentLoadException, AttachNotSupportedException, IOException {
    reloadIntervals = 5;
    classFileInfos = new ArrayList<ClassFileInfo>();

    excludePackages = TObject.asList("java.","sun.","javax.","com.sun","com.oracle");

    if(agentJar == null) {
        agentJar = findAgentJar();
    }

    if(agentJar != null && agentJar.exists()) {
        Logger.info("[HOTSWAP] System choose an agent jar file: "+agentJar.getAbsolutePath());
        agentAttach(agentJar.getPath());
        loadCustomClass();
    } else {
        throw new FileNotFoundException("The agent jar file not found");
    }
}
 
开发者ID:helyho,项目名称:Voovan,代码行数:19,代码来源:Hotswaper.java

示例9: connectorAddress

import com.sun.tools.attach.AgentLoadException; //导入依赖的package包/类
/**
 * Get a connection address for a local management agent. If no such agent exists, one will be
 * started.
 * 
 * @param vm
 *            instance representing a running JVM
 * @return the management agent connection string
 * @throws IOException
 *             if an I/O error occurs while communicating with the VM
 */
private String connectorAddress(VirtualMachine vm) throws IOException {
    String address = vm.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress");
    if (address == null) {
        // No locally connectable agent, install one.
        try {
            String javaHome = vm.getSystemProperties().getProperty("java.home");
            vm.loadAgent(Joiner.on(File.separator).join(javaHome, "lib", "management-agent.jar"));
        }
        catch (AgentLoadException | AgentInitializationException e) {
            throw Throwables.propagate(e);
        }
        address = vm.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress");
    }
    return address;
}
 
开发者ID:wikimedia,项目名称:cassandra-metrics-collector,代码行数:26,代码来源:Discovery.java

示例10: loadJMXAgent

import com.sun.tools.attach.AgentLoadException; //导入依赖的package包/类
public static String loadJMXAgent(int port) throws IOException, AttachNotSupportedException, AgentLoadException,
		AgentInitializationException {
	System.setProperty("com.sun.management.jmxremote.port", Integer.toString(port));
	String name = ManagementFactory.getRuntimeMXBean().getName();
	VirtualMachine vm = VirtualMachine.attach(name.substring(0, name.indexOf('@')));

	String lca = vm.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress");
	if (lca == null) {
		Path p = Paths.get(System.getProperty("java.home")).normalize();
		if (!"jre".equals(p.getName(p.getNameCount() - 1).toString().toLowerCase()))
			p = p.resolve("jre");
		File f = p.resolve("lib").resolve("management-agent.jar").toFile();
		if (!f.exists())
			throw new IOException("Management agent not found");

		vm.loadAgent(f.getCanonicalPath(), "com.sun.management.jmxremote");
		lca = vm.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress");
	}
	vm.detach();
	return lca;
}
 
开发者ID:codessentials,项目名称:felinx,代码行数:22,代码来源:FrameworkRunner.java

示例11: main

import com.sun.tools.attach.AgentLoadException; //导入依赖的package包/类
public static void main(String[] args) throws AgentLoadException, AgentInitializationException, IOException, AttachNotSupportedException {
		VirtualMachine vm=VirtualMachine.attach("7876");
		vm.loadAgent("d:/springloaded-1.2.1.RELEASE.jar");
//		vm.loadAgent("d:/myagent.jar","myagent");
		System.out.println(vm.getAgentProperties().toString());
		System.in.read();
	}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:8,代码来源:AgentUtil.java

示例12: executeCommand

import com.sun.tools.attach.AgentLoadException; //导入依赖的package包/类
private InputStream executeCommand(String cmd, Object ... args) throws IOException {
    try {
        return execute(cmd, args);
    } catch (AgentLoadException x) {
        throw new InternalError("Should not get here", x);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:HotSpotVirtualMachine.java

示例13: main

import com.sun.tools.attach.AgentLoadException; //导入依赖的package包/类
public static void main(String[] args) {
    try {
        AgentLoader.attach(TestAgent.class);
    } catch (AgentInstantiationException | AgentLoadException | AgentInitializationException | AttachNotSupportedException | NotFoundException | CannotCompileException | IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:ZeroMemes,项目名称:Agent-Lib,代码行数:8,代码来源:Main.java

示例14: loadAgent

import com.sun.tools.attach.AgentLoadException; //导入依赖的package包/类
public void loadAgent(String agent, String options)
    throws AgentLoadException, AgentInitializationException, IOException
{
    String args = agent;
    if (options != null) {
        args = args + "=" + options;
    }
    try {
        loadAgentLibrary("instrument", args);
    } catch (AgentInitializationException x) {
        /*
         * Translate interesting errors into the right exception and
         * message (FIXME: create a better interface to the instrument
         * implementation so this isn't necessary)
         */
        int rc = x.returnValue();
        switch (rc) {
            case JNI_ENOMEM:
                throw new AgentLoadException("Insuffient memory");
            case ATTACH_ERROR_BADJAR:
                throw new AgentLoadException(
                    "Agent JAR not found or no Agent-Class attribute");
            case ATTACH_ERROR_NOTONCP:
                throw new AgentLoadException(
                    "Unable to add JAR file to system class path");
            case ATTACH_ERROR_STARTFAIL:
                throw new AgentInitializationException(
                    "Agent JAR loaded but agent failed to initialize");
            default :
                throw new AgentLoadException("" +
                    "Failed to load agent - unknown reason: " + rc);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:HotSpotVirtualMachine.java

示例15: executeCommand

import com.sun.tools.attach.AgentLoadException; //导入依赖的package包/类
public InputStream executeCommand(String cmd, Object ... args) throws IOException {
    try {
        return execute(cmd, args);
    } catch (AgentLoadException x) {
        throw new InternalError("Should not get here", x);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:HotSpotVirtualMachine.java


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