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


Java AttachProvider.attachVirtualMachine方法代码示例

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


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

示例1: 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

示例2: attach

import com.sun.tools.attach.spi.AttachProvider; //导入方法依赖的package包/类
/**
 * Attaches to a Java virtual machine.
 *
 * <p> This method obtains the list of attach providers by invoking the
 * {@link com.sun.tools.attach.spi.AttachProvider#providers()
 * AttachProvider.providers()} method. It then iterates overs the list
 * and invokes each provider's {@link
 * com.sun.tools.attach.spi.AttachProvider#attachVirtualMachine(java.lang.String)
 * attachVirtualMachine} method in turn. If a provider successfully
 * attaches then the iteration terminates, and the VirtualMachine created
 * by the provider that successfully attached is returned by this method.
 * If the <code>attachVirtualMachine</code> method of all providers throws
 * {@link com.sun.tools.attach.AttachNotSupportedException AttachNotSupportedException}
 * then this method also throws <code>AttachNotSupportedException</code>.
 * This means that <code>AttachNotSupportedException</code> is thrown when
 * the identifier provided to this method is invalid, or the identifier
 * corresponds to a Java virtual machine that does not exist, or none
 * of the providers can attach to it. This exception is also thrown if
 * {@link com.sun.tools.attach.spi.AttachProvider#providers()
 * AttachProvider.providers()} returns an empty list. </p>
 *
 * @param   id
 *          The abstract identifier that identifies the Java virtual machine.
 *
 * @return  A VirtualMachine representing the target VM.
 *
 * @throws  SecurityException
 *          If a security manager has been installed and it denies
 *          {@link com.sun.tools.attach.AttachPermission AttachPermission}
 *          <tt>("attachVirtualMachine")</tt>, or another permission
 *          required by the implementation.
 *
 * @throws  AttachNotSupportedException
 *          If the <code>attachVirtualmachine</code> method of all installed
 *          providers throws <code>AttachNotSupportedException</code>, or
 *          there aren't any providers installed.
 *
 * @throws  IOException
 *          If an I/O error occurs
 *
 * @throws  NullPointerException
 *          If <code>id</code> is <code>null</code>.
 */
public static VirtualMachine attach(String id)
    throws AttachNotSupportedException, IOException
{
    if (id == null) {
        throw new NullPointerException("id cannot be null");
    }
    List<AttachProvider> providers = AttachProvider.providers();
    if (providers.size() == 0) {
        throw new AttachNotSupportedException("no providers installed");
    }
    AttachNotSupportedException lastExc = null;
    for (AttachProvider provider: providers) {
        try {
            return provider.attachVirtualMachine(id);
        } catch (AttachNotSupportedException x) {
            lastExc = x;
        }
    }
    throw lastExc;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:64,代码来源:VirtualMachine.java

示例3: attach

import com.sun.tools.attach.spi.AttachProvider; //导入方法依赖的package包/类
/**
 * Attaches to a Java virtual machine.
 *
 * <p> This method obtains the list of attach providers by invoking the
 * {@link com.sun.tools.attach.spi.AttachProvider#providers()
 * AttachProvider.providers()} method. It then iterates overs the list
 * and invokes each provider's {@link
 * com.sun.tools.attach.spi.AttachProvider#attachVirtualMachine(java.lang.String)
 * attachVirtualMachine} method in turn. If a provider successfully
 * attaches then the iteration terminates, and the VirtualMachine created
 * by the provider that successfully attached is returned by this method.
 * If the {@code attachVirtualMachine} method of all providers throws
 * {@link com.sun.tools.attach.AttachNotSupportedException AttachNotSupportedException}
 * then this method also throws {@code AttachNotSupportedException}.
 * This means that {@code AttachNotSupportedException} is thrown when
 * the identifier provided to this method is invalid, or the identifier
 * corresponds to a Java virtual machine that does not exist, or none
 * of the providers can attach to it. This exception is also thrown if
 * {@link com.sun.tools.attach.spi.AttachProvider#providers()
 * AttachProvider.providers()} returns an empty list. </p>
 *
 * @param   id
 *          The abstract identifier that identifies the Java virtual machine.
 *
 * @return  A VirtualMachine representing the target VM.
 *
 * @throws  SecurityException
 *          If a security manager has been installed and it denies
 *          {@link com.sun.tools.attach.AttachPermission AttachPermission}
 *          {@code ("attachVirtualMachine")}, or another permission
 *          required by the implementation.
 *
 * @throws  AttachNotSupportedException
 *          If the {@code attachVirtualmachine} method of all installed
 *          providers throws {@code AttachNotSupportedException}, or
 *          there aren't any providers installed.
 *
 * @throws  IOException
 *          If an I/O error occurs
 *
 * @throws  NullPointerException
 *          If {@code id} is {@code null}.
 */
public static VirtualMachine attach(String id)
    throws AttachNotSupportedException, IOException
{
    if (id == null) {
        throw new NullPointerException("id cannot be null");
    }
    List<AttachProvider> providers = AttachProvider.providers();
    if (providers.size() == 0) {
        throw new AttachNotSupportedException("no providers installed");
    }
    AttachNotSupportedException lastExc = null;
    for (AttachProvider provider: providers) {
        try {
            return provider.attachVirtualMachine(id);
        } catch (AttachNotSupportedException x) {
            lastExc = x;
        }
    }
    throw lastExc;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:64,代码来源:VirtualMachine.java

示例4: attach

import com.sun.tools.attach.spi.AttachProvider; //导入方法依赖的package包/类
/**
 * Attaches to a Java virtual machine.
 * <p/>
 * This method obtains the list of attach providers by invoking the
 * {@link com.sun.tools.attach.spi.AttachProvider#providers() AttachProvider.providers()} method.
 * It then iterates overs the list and invokes each provider's {@link
 * com.sun.tools.attach.spi.AttachProvider#attachVirtualMachine(java.lang.String)
 * attachVirtualMachine} method in turn. If a provider successfully
 * attaches then the iteration terminates, and the VirtualMachine created
 * by the provider that successfully attached is returned by this method.
 * If the <code>attachVirtualMachine</code> method of all providers throws
 * {@link com.sun.tools.attach.AttachNotSupportedException AttachNotSupportedException}
 * then this method also throws <code>AttachNotSupportedException</code>.
 * This means that <code>AttachNotSupportedException</code> is thrown when
 * the identifier provided to this method is invalid, or the identifier
 * corresponds to a Java virtual machine that does not exist, or none
 * of the providers can attach to it. This exception is also thrown if
 * {@link com.sun.tools.attach.spi.AttachProvider#providers()
 * AttachProvider.providers()} returns an empty list. </p>
 *
 * @param id The abstract identifier that identifies the Java virtual machine.
 * @return A VirtualMachine representing the target VM.
 * @throws SecurityException           If a security manager has been installed and it denies
 *                                     {@link com.sun.tools.attach.AttachPermission AttachPermission}
 *                                     <tt>("attachVirtualMachine")</tt>, or another permission
 *                                     required by the implementation.
 * @throws IOException                 If an I/O error occurs
 */
public static VirtualMachine attach(String id) throws AttachNotSupportedException, IOException
{
   List<AttachProvider> providers = AttachProvider.providers();
   AttachNotSupportedException lastExc = null;

   for (AttachProvider provider : providers) {
      try {
         return provider.attachVirtualMachine(id);
      }
      catch (AttachNotSupportedException x) {
         lastExc = x;
      }
   }

   throw lastExc;
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:45,代码来源:VirtualMachine.java


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