public class VirtualMachineHandler extends Object
VirtualMachine
without directly referencing internally
the class type. All lookup is done via reflection.Constructor and Description |
---|
VirtualMachineHandler(OptionsAndArgs pOptions)
Constructor with options
|
Modifier and Type | Method and Description |
---|---|
Object |
attachVirtualMachine()
Lookup and create a
com.sun.tools.attach.VirtualMachine via reflection. |
void |
detachAgent(Object pVm)
Detach from the virtual machine
|
ProcessDescription |
findProcess(Pattern pPattern)
Filter the process list for a regular expression and returns the description.
|
List<ProcessDescription> |
listProcesses()
Return a list of all Java processes
|
public VirtualMachineHandler(OptionsAndArgs pOptions)
pOptions
- options for getting e.g. the process id to attach topublic Object attachVirtualMachine()
com.sun.tools.attach.VirtualMachine
via reflection. First, a direct
lookup via Class.forName(String)
is done, which will succeed for JVM on OS X, since tools.jar
is bundled there together with classes.zip. Next, tools.jar is tried to be found (by examine java.home
)
and an own classloader is created for looking up the VirtualMachine.
If lookup fails, a message is printed out (except when '--quiet' is provided)null
if none could be createdpublic void detachAgent(Object pVm)
pVm
- the virtual machine to detach frompublic List<ProcessDescription> listProcesses() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
NoSuchMethodException
- reflection errorInvocationTargetException
- reflection errorIllegalAccessException
- reflection errorpublic ProcessDescription findProcess(Pattern pPattern) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException
pPattern
- regular expression to matchIllegalArgumentException
- if more than one or no process has been found.InvocationTargetException
NoSuchMethodException
IllegalAccessException
Copyright © 2019. All rights reserved.