Package org.jboss.byteman.agent.install
Class Install
java.lang.Object
org.jboss.byteman.agent.install.Install
A program which uses the sun.com.tools.attach.VirtualMachine class to install the Byteman agent into a
running JVM. This provides an alternative to using the -javaagent option to install the agent.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private String
private static final String
Base directory to look for agent jar.private static final String
private static final String
Name of agent jar (without extension).private static final String
environment variable used to idenitfy the location of the installed byteman release.private static final String
System property used to idenitfy the location of the installed byteman release.private static final String
Base directory to look for JBoss modules plugin jar.private static final String
Name of JBoss modules plugin jar (without extension).private static final String
private String
private String
private String
private int
private String
private boolean
private boolean
private VirtualMachine
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
attach()
attach to the Java process identified by the process id supplied on the command linestatic VMInfo[]
private static String
getProperty
(String id, String property) static String
getSystemProperty
(String id, String property) attach to the virtual machine identified by id and return the value of the named property.private void
get the attached process to upload and install the agent jar using whatever agent options were configured on the command linestatic void
install
(String pid, boolean addToBoot, boolean setPolicy, boolean useModuleLoader, String host, int port, String[] properties) compatability modestatic void
install
(String pid, boolean addToBoot, boolean setPolicy, String host, int port, String[] properties) compatability modestatic void
compatability modestatic boolean
attach to the virtual machine identified by id and returntrue
if a Byteman agent has already been attached to it.private void
Check for system property org.jboss.byteman.home in preference to the environment setting BYTEMAN_HOME and use it to identify the location of the byteman agent jar.locateJarFromClasspath
(String libName) locateJarFromHomeDir
(String bmHome, String baseDir, String libName) static void
main routine for use from command line Install [-h host] [-p port] [-b] [-s] [-m] [-Dorg.jboss.Byteman.xxx]* pid see methodusage(int)
for details of the command syntaxprivate void
check the supplied arguments and stash away the relevant dataprivate static void
usage
(int exitValue) print usage information and exit with a specific exit code
-
Field Details
-
agentJar
-
modulePluginJar
-
id
-
port
private int port -
host
-
addToBoot
private boolean addToBoot -
setPolicy
private boolean setPolicy -
useModuleLoader
private boolean useModuleLoader -
props
-
vm
-
BYTEMAN_PREFIX
- See Also:
-
BYTEMAN_AGENT_LOADED_PROPERTY
- See Also:
-
BYTEMAN_HOME_SYSTEM_PROP
System property used to idenitfy the location of the installed byteman release.- See Also:
-
BYTEMAN_HOME_ENV_VAR
environment variable used to idenitfy the location of the installed byteman release.- See Also:
-
BYTEMAN_AGENT_BASE_DIR
Base directory to look for agent jar.- See Also:
-
BYTEMAN_AGENT_NAME
Name of agent jar (without extension).- See Also:
-
BYTEMAN_MODULES_PLUGIN_BASE_DIR
Base directory to look for JBoss modules plugin jar.- See Also:
-
BYTEMAN_MODULES_PLUGIN_NAME
Name of JBoss modules plugin jar (without extension).- See Also:
-
-
Constructor Details
-
Method Details
-
main
main routine for use from command line Install [-h host] [-p port] [-b] [-s] [-m] [-Dorg.jboss.Byteman.xxx]* pid see methodusage(int)
for details of the command syntax- Parameters:
args
- the command options
-
install
public static void install(String pid, boolean addToBoot, String host, int port, String[] properties) throws IllegalArgumentException, FileNotFoundException, IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException compatability mode- Parameters:
pid
- the process id of the JVM into which the agent should be installed or 0 for this JVMaddToBoot
- true if the agent jar should be installed into the bootstrap classpathhost
- the hostname to be used by the agent listener or null for localhostport
- the port to be used by the agent listener or 0 for the default portproperties
- an array of System properties to be installed by the agent with optional values e.g. values such as "org.jboss.byteman.verbose" or "org.jboss.byteman.dump.generated.classes.directory=./dump"- Throws:
IllegalArgumentException
- if any of the arguments is invalidFileNotFoundException
- if the agent jar cannot be found using the environment variable BYTEMAN_HOME or the System property org.jboss.byteman.home and cannot be located in the current classpathIOException
- if the byteman jar cannot be opened or uploaded to the requested JVMAttachNotSupportedException
- if the requested JVM cannot be attached toAgentLoadException
- if an error occurs during upload of the agent into the JVMAgentInitializationException
- if the agent fails to initialize after loading. this almost always indicates that the agent is already loaded into the JVM
-
install
public static void install(String pid, boolean addToBoot, boolean setPolicy, String host, int port, String[] properties) throws IllegalArgumentException, FileNotFoundException, IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException compatability mode- Parameters:
pid
- the process id of the JVM into which the agent should be installed or 0 for this JVMaddToBoot
- true if the agent jar should be installed into the bootstrap classpathsetPolicy
- true if the agent jar should set an access-all-areas securityPolicyhost
- the hostname to be used by the agent listener or null for localhostport
- the port to be used by the agent listener or 0 for the default portproperties
- an array of System properties to be installed by the agent with optional values e.g. values such as "org.jboss.byteman.verbose" or "org.jboss.byteman.dump.generated.classes.directory=./dump"- Throws:
IllegalArgumentException
- if any of the arguments is invalidFileNotFoundException
- if the agent jar cannot be found using the environment variable BYTEMAN_HOME or the System property org.jboss.byteman.home and cannot be located in the current classpathIOException
- if the byteman jar cannot be opened or uploaded to the requested JVMAttachNotSupportedException
- if the requested JVM cannot be attached toAgentLoadException
- if an error occurs during upload of the agent into the JVMAgentInitializationException
- if the agent fails to initialize after loading. this almost always indicates that the agent is already loaded into the JVM
-
install
public static void install(String pid, boolean addToBoot, boolean setPolicy, boolean useModuleLoader, String host, int port, String[] properties) throws IllegalArgumentException, FileNotFoundException, IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException compatability mode- Parameters:
pid
- the process id of the JVM into which the agent should be installed or 0 for this JVMaddToBoot
- true if the agent jar should be installed into the bootstrap classpathsetPolicy
- true if the agent jar should set an access-all-areas securityPolicyuseModuleLoader
- true if the JBoss module loader mode should be configuredhost
- the hostname to be used by the agent listener or null for localhostport
- the port to be used by the agent listener or 0 for the default portproperties
- an array of System properties to be installed by the agent with optional values e.g. values such as "org.jboss.byteman.verbose" or "org.jboss.byteman.dump.generated.classes.directory=./dump"- Throws:
IllegalArgumentException
- if any of the arguments is invalidFileNotFoundException
- if the agent jar cannot be found using the environment variable BYTEMAN_HOME or the System property org.jboss.byteman.home and cannot be located in the current classpathIOException
- if the byteman jar cannot be opened or uploaded to the requested JVMAttachNotSupportedException
- if the requested JVM cannot be attached toAgentLoadException
- if an error occurs during upload of the agent into the JVMAgentInitializationException
- if the agent fails to initialize after loading. this almost always indicates that the agent is already loaded into the JVM
-
availableVMs
-
getSystemProperty
attach to the virtual machine identified by id and return the value of the named property. id must be the id of a virtual machine returned by method availableVMs.- Parameters:
id
- the id of the machine to attach toproperty
- the proeprty to be retrieved- Returns:
- the value of the property or null if it is not set
-
isAgentAttached
attach to the virtual machine identified by id and returntrue
if a Byteman agent has already been attached to it. id must be the id of a virtual machine returned by method availableVMs.- Parameters:
id
- the id of the machine to attach to- Returns:
true
if and only if a Byteman agent has already been attached to the virtual machine.
-
getProperty
-
parseArgs
check the supplied arguments and stash away the relevant data- Parameters:
args
- the value supplied to main
-
locateAgent
Check for system property org.jboss.byteman.home in preference to the environment setting BYTEMAN_HOME and use it to identify the location of the byteman agent jar.- Throws:
IOException
-
locateJarFromHomeDir
public String locateJarFromHomeDir(String bmHome, String baseDir, String libName) throws IOException - Throws:
IOException
-
locateJarFromClasspath
- Throws:
IOException
-
attach
attach to the Java process identified by the process id supplied on the command line -
injectAgent
get the attached process to upload and install the agent jar using whatever agent options were configured on the command line -
usage
private static void usage(int exitValue) print usage information and exit with a specific exit code- Parameters:
exitValue
- the value to be supplied to the exit call
-