本文整理汇总了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);
}
示例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");
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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 + "");
}
示例13: HotSpotVirtualMachine
import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
HotSpotVirtualMachine(AttachProvider provider, String id) {
super(provider, id);
}
示例14: HotSpotVirtualMachineDescriptor
import com.sun.tools.attach.spi.AttachProvider; //导入依赖的package包/类
HotSpotVirtualMachineDescriptor(AttachProvider provider,
String id,
String displayName) {
super(provider, id, displayName);
}