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


Java AttachProvider类代码示例

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


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

示例1: setProviders

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
/**
 * Set java's attach providers programatically since I can't be bothered to
 * do multi-release with maven.
 * 
 * @throws Exception
 */
public static void setProviders() throws Exception {
	Field providers = AttachProvider.class.getDeclaredField("providers");
	providers.setAccessible(true);
	List<AttachProvider> list = new ArrayList<>();
	String os = System.getProperty("os.name").toLowerCase();
	if (os.contains("win")) {
		list.add(new WindowsAttachProvider());
	} else if (os.contains("mac")) {
		list.add(new BsdAttachProvider());
	} else if (os.contains("nux")) {
		list.add(new LinuxAttachProvider());
	} else {
		Recaf.INSTANCE.logging.error(new RuntimeException(
				"Recaf could not select an attach provider, please open an issue on Github. Your OS was: '" + os + "'."));
	}
	providers.set(null, list);
}
 
开发者ID:Col-E,项目名称:Recaf,代码行数:24,代码来源:Attach.java

示例2: HotSpotVirtualMachine

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

示例3: VirtualMachineDescriptor

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
/**
 * Creates a virtual machine descriptor from the given components.
 *
 * @param provider    The AttachProvider to attach to the Java virtual machine.
 * @param id          The virtual machine identifier.
 * @param displayName The display name.
 * @throws NullPointerException If any of the arguments are <code>null</code>
 */
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName)
{
   if (provider == null) {
      throw new NullPointerException("provider cannot be null");
   }

   if (id == null) {
      throw new NullPointerException("identifier cannot be null");
   }

   if (displayName == null) {
      throw new NullPointerException("display name cannot be null");
   }

   this.provider = provider;
   this.id = id;
   this.displayName = displayName;
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:27,代码来源:VirtualMachineDescriptor.java

示例4: attachToVm

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
/**
 * Attaches to the JVM and returns the attaches {@link VirtualMachine}.
 *
 * @return The {@link VirtualMachine} that is attached.
 * @throws AttachNotSupportedException
 *             If attachments are not supported by the currently running
 *             JVM.
 * @throws IOException
 *             If any I/O error occurs.
 */
private VirtualMachine attachToVm() throws AttachNotSupportedException, IOException {
    InterceptionAgent.LOGGER.debug("Attaching to virtual machine.");

    final VirtualMachine virtualMachine;
    if (AttachProvider.providers().isEmpty()) {
        InterceptionAgent.LOGGER.debug("No attachment providers found! Creating one ...");

        final String vmName = System.getProperty("java.vm.name");
        if (!vmName.contains("HotSpot")) {
            InterceptionAgent.LOGGER.warn("Running on a non-HotSpot virtual machine! Trying to attach anyway ...");
        }
        virtualMachine = this.retrieveOsDepentVmImplementation();
    } else {
        virtualMachine = VirtualMachine.attach(this.retrieveJvmId());
    }

    InterceptionAgent.LOGGER.debug("Attached!");

    return virtualMachine;
}
 
开发者ID:Blockhaus2000,项目名称:InternalPluginManager,代码行数:31,代码来源:InterceptionAgent.java

示例5: loadAgent

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
/**
 * Load an agent providing the full file path with parameters.
 *
 * @param jarFilePath jar file path
 * @param params      params
 */
public static void loadAgent(String jarFilePath, String params) {

    logger.info(Messages.get("dev.loading.jvm.angent", jarFilePath));
    try {

        String pid = discoverPid();

        if (AttachProvider.providers().isEmpty()) {
            vm = getVirtualMachineImplementationFromEmbeddedOnes(pid);
        } else {
            vm = VirtualMachine.attach(pid);
        }

        if (vm == null) {
            logger.warn("VirtualMachine or OS Platform not support JVM Agent");
            return;
        }
        vm.loadAgent(jarFilePath, params);
        vm.detach();

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:icode,项目名称:ameba-dev,代码行数:31,代码来源:AgentLoader.java

示例6: VirtualMachineDescriptor

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
/**
 * Creates a virtual machine descriptor from the given components.
 *
 * @param   provider      The AttachProvider to attach to the Java virtual machine.
 * @param   id            The virtual machine identifier.
 * @param   displayName   The display name.
 *
 * @throws  NullPointerException
 *          If any of the arguments are <code>null</code>
 */
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
    if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    if (id == null) {
        throw new NullPointerException("identifier cannot be null");
    }
    if (displayName == null) {
        throw new NullPointerException("display name cannot be null");
    }
    this.provider = provider;
    this.id = id;
    this.displayName = displayName;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:VirtualMachineDescriptor.java

示例7: main

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
    // deal with internal builds where classes are loaded from the
    // 'classes' directory rather than rt.jar
    ClassLoader cl = AttachProvider.class.getClassLoader();
    if (cl != ClassLoader.getSystemClassLoader()) {
        System.out.println("Attach API not loaded by system class loader - test skipped");
        return;
    }
    VirtualMachine.attach("simple:1234").detach();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:ProviderTest.java

示例8: VirtualMachineDescriptor

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
/**
 * Creates a virtual machine descriptor from the given components.
 *
 * @param   provider      The AttachProvider to attach to the Java virtual machine.
 * @param   id            The virtual machine identifier.
 * @param   displayName   The display name.
 *
 * @throws  NullPointerException
 *          If any of the arguments are {@code null}
 */
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
    if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    if (id == null) {
        throw new NullPointerException("identifier cannot be null");
    }
    if (displayName == null) {
        throw new NullPointerException("display name cannot be null");
    }
    this.provider = provider;
    this.id = id;
    this.displayName = displayName;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:VirtualMachineDescriptor.java

示例9: testExecute

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
@Test
public void testExecute() throws IOException, AttachNotSupportedException {
    LocalVirtualMachineTemplate localVirtualMachineTemplate = new LocalVirtualMachineTemplate();

    AttachProvider result = localVirtualMachineTemplate.execute(new HotSpotVirtualMachineCallback<AttachProvider>() {
        @Override
        public AttachProvider doInVirtualMachine(HotSpotVirtualMachine virtualMachine) throws IOException {
            AttachProvider attachProvider = virtualMachine.provider();
            return attachProvider;
        }
    });

    Assert.assertNotNull(result);
}
 
开发者ID:mercyblitz,项目名称:confucius-commons,代码行数:15,代码来源:LocalVirtualMachineTemplateTest.java

示例10: loadAgent

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
/**
 * Load an agent providing the full file path with parameters.
 */
public static void loadAgent(String jarFilePath, String params) {
    try {

        String pid = Env.PID.get();

        VirtualMachine vm;
        if (AttachProvider.providers().isEmpty()) {
            vm = getVirtualMachineImplementationFromEmbeddedOnes(pid);
        } else {
            vm = VirtualMachine.attach(pid);
        }

        final PrintStream ps = System.out;
        try {
            System.setOut(new PrintStream(new FileOutputStream(".ebean_agent.log")));
            vm.loadAgent(jarFilePath, params);
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("javaagent loaded: " + jarFilePath);
            }
        } finally {
            // ensure ebean2 EnhanceContext logout set to dump output
            Act.jobManager().on(AppEventId.CLASS_LOADER_INITIALIZED, new Runnable() {
                @Override
                public void run() {
                    System.setOut(ps);
                }
            });
        }
        vm.detach();

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:actframework,项目名称:act-ebean,代码行数:38,代码来源:EbeanAgentLoader.java

示例11: loadAgent

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
void loadAgent() {
    VirtualMachine vm;

    if (AttachProvider.providers().isEmpty()) {
        vm = getVirtualMachineImplementationFromEmbeddedOnes();
    }
    else {
        vm = attachToThisVM();
    }

    loadAgentAndDetachFromThisVM(vm);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:13,代码来源:JDK6AgentLoader.java

示例12: JmxMemoryUtil

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
public JmxMemoryUtil() throws IOException, AttachNotSupportedException, AgentLoadException,
        AgentInitializationException, AttributeNotFoundException, MBeanException, ReflectionException,
        InstanceNotFoundException, MalformedObjectNameException {
    final AttachProvider attachProvider = AttachProvider.providers().get(0);

    VirtualMachineDescriptor descriptor = null;
    for (VirtualMachineDescriptor virtualMachineDescriptor : attachProvider.listVirtualMachines()) {
        descriptor = virtualMachineDescriptor;
        if (isJettyDescriptor(descriptor)) {
            break;
        }
    }

    if (descriptor == null) {
        throw new RuntimeException("No jetty descriptor found, did you start jetty using mvn jetty:run?");
    }

    final VirtualMachine virtualMachine = attachProvider.attachVirtualMachine(descriptor);
    virtualMachine.loadAgent(System.getProperty("java.home")
                             + "/../jre/lib/management-agent.jar", "com.sun.management.jmxremote");
    final Object
            portObject =
            virtualMachine.getAgentProperties().get("com.sun.management.jmxremote.localConnectorAddress");

    target = new JMXServiceURL(portObject + "");


}
 
开发者ID:datenhahn,项目名称:componentrenderer,代码行数:29,代码来源:JmxMemoryUtil.java

示例13: HotSpotVirtualMachine

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
HotSpotVirtualMachine(AttachProvider provider, String id) {
    super(provider, id);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:HotSpotVirtualMachine.java

示例14: HotSpotVirtualMachineDescriptor

import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
HotSpotVirtualMachineDescriptor(AttachProvider provider,
                                String id,
                                String displayName) {
    super(provider, id, displayName);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:HotSpotAttachProvider.java


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