Package org.jboss.byteman.agent.submit
Class Submit
java.lang.Object
org.jboss.byteman.agent.submit.Submit
A Java API that can be used to submit requests to a remote Byteman agent.
This also includes a main routine for use as a command-line utility.
This object provides a means by which you communicate with the Byteman agent at runtime allowing loading,
reloading, unloading of rules and listing of the current rule set and any successful or failed attempts
to inject, parse and typecheck the rules.
Note that this class is completely standalone and has no dependencies on any other Byteman class.
It can be shipped alone in a client jar to be used as a very small app.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String
static final String
static final int
private PrintStream
private final int
-
Constructor Summary
ConstructorsConstructorDescriptionSubmit()
Create a client that will connect to a Byteman agent on the default host and port and writing output to System.out.Create a client that will connect to a Byteman agent on the given host and port and writing output to System.out.Submit
(String address, int port, PrintStream out) Create a client that will connect to a Byteman agent on the given host and port and writing output to System.out. -
Method Summary
Modifier and TypeMethodDescriptionaddJarsToBootClassloader
(List<String> jarPaths) This adds the given list of files to the Byteman agent's boot classloader.addJarsToSystemClassloader
(List<String> jarPaths) This adds the given list of files to the Byteman agent's system classloader.Deprecated.addRulesFromFiles
(List<String> filePaths) Deploys rules into Byteman, where the rule definitions are found in the local files found at the given paths.addRulesFromResources
(List<InputStream> resourceStreams) Deploys rules into Byteman, where the rule definitions are found in the given streams.addScripts
(List<ScriptText> scripts) Deploys rule scripts into Bytemanprivate boolean
Tells the Byteman agent to delete all rules.deleteRules
(Map<String, String> rules) Deprecated.deleteRulesFromFiles
(List<String> filePaths) Deletes rules from Byteman, where the rule definitions are found in the local files found at the given paths.deleteRulesFromResources
(List<InputStream> resourceStreams) Deletes rules from Byteman, where the rule definitions are found in the given streams.deleteScripts
(List<ScriptText> scripts) Deletes rules from Byteman.determineRuleName
(String ruleDefinition) Given the content of an individual rule definition, this will return the name of that rule.Returns the version of the remote Byteman agent.Deprecated.Gets all deployed rules from the agent just aslistAllRules()
, but will return the rules organized by script (i.e.Returns the version of this Byteman submit client.Returns a list of jars that were added to the Byteman agent's boot classloader.Returns a list of jars that were added to the Byteman agent's system classloader.int
getPort()
private List
<ScriptText> getRulesFromRuleFiles
(List<String> filePaths) private List
<ScriptText> getRulesFromRuleStreams
(List<InputStream> streams) Tells the Byteman agent to list all deployed rules.Returns the system properties set in the Byteman agent VM.static void
A main routine which submits requests to the Byteman agent utilizing the Java API.private ScriptText
readScriptText
(String filePath, InputStreamReader reader) setSystemProperties
(Properties propsToSet) Sets system properties in the Byteman agent VM.splitAllRulesFromScript
(String scriptContent) Given the content of a script (which will be one or more rule definitions), this will return each rule definition as an individual string within the returned list.submitRequest
(String request) Submits the generic request string to the Byteman agent for processing.private static void
usage
(PrintStream out, int exitCode)
-
Field Details
-
DEFAULT_ADDRESS
- See Also:
-
DEFAULT_PORT
public static final int DEFAULT_PORT- See Also:
-
port
private final int port -
address
-
out
-
-
Constructor Details
-
Submit
public Submit()Create a client that will connect to a Byteman agent on the default host and port and writing output to System.out. -
Submit
Create a client that will connect to a Byteman agent on the given host and port and writing output to System.out.- Parameters:
address
- the hostname or IP address of the machine where Byteman agent is located. Ifnull
, the default host is used.port
- the port that the Byteman agent is listening to. If 0 or less, the default port is used.
-
Submit
Create a client that will connect to a Byteman agent on the given host and port and writing output to System.out.- Parameters:
address
- the hostname or IP address of the machine where Byteman agent is located. Ifnull
, the default host is used.port
- the port that the Byteman agent is listening to. If 0 or less, the default port is used.out
- the print stream used for writing output
-
-
Method Details
-
getAddress
- Returns:
- identifies the host where this client expects a Byteman agent to be running.
-
getPort
public int getPort()- Returns:
- the port that this client expects a Byteman agent to be listening
to on the given
host
.
-
getAgentVersion
Returns the version of the remote Byteman agent.- Returns:
- the version of the remote Byteman agent
- Throws:
Exception
- if the request failed
-
getClientVersion
Returns the version of this Byteman submit client.- Returns:
- the version of the submit client, or
null
if unknown - Throws:
Exception
- if the request failed
-
deleteAllRules
Tells the Byteman agent to delete all rules. This will effectively revert the Byteman's VM to its original state; that is, no Byteman injected byte-code will be invoked.- Returns:
- the results of the delete-all request to the Byteman agent
- Throws:
Exception
- if the request failed
-
listAllRules
Tells the Byteman agent to list all deployed rules.- Returns:
- all the rules deployed in the Byteman agent
- Throws:
Exception
- if the request failed
-
getAllScripts
Gets all deployed rules from the agent just aslistAllRules()
, but will return the rules organized by script (i.e. rule file). Each "script", or rule file, has a set of rules associated with it.- Returns:
- all the scripts deployed in the Byteman agent the keys are the script names (typically this is the filenames where the rule definitions were found); the values are the rule definitions in the scripts
- Throws:
Exception
- if the request failed
-
getAllRules
Deprecated.old version which returns a map rather than a list of scripts- Returns:
- as above but as a map
- Throws:
Exception
- if the request failed
-
splitAllRulesFromScript
Given the content of a script (which will be one or more rule definitions), this will return each rule definition as an individual string within the returned list. The returned list will be ordered - that is, the first rule in the list is the first rule encountered in the script. One usage of this method is to pass in map values from the results ofgetAllScripts()
in case you need the scripts' individual rules.- Parameters:
scriptContent
- the actual content of a script (i.e. the rule definitions)- Returns:
- all the rule definitions found in the given script
- Throws:
Exception
- if an string processing error occurs
-
determineRuleName
Given the content of an individual rule definition, this will return the name of that rule.- Parameters:
ruleDefinition
- the actual content of an individual rule- Returns:
- the name of the given rule, or
null
if it could not be determined - Throws:
Exception
- if the name cannot be determined
-
addJarsToBootClassloader
This adds the given list of files to the Byteman agent's boot classloader. Note that if the Byteman agent is running on a remote machine, the paths must resolve on that remote host (i.e. the file must exist on the remote machine at the paths given to this method).- Parameters:
jarPaths
- the paths to the library .jar files that will be loaded- Returns:
- the result of the load as reported by Byteman
- Throws:
Exception
- if the request failed
-
addJarsToSystemClassloader
This adds the given list of files to the Byteman agent's system classloader. Note that if the Byteman agent is running on a remote machine, the paths must resolve on that remote host (i.e. the file must exist on the remote machine at the paths given to this method).- Parameters:
jarPaths
- the paths to the library .jar files that will be loaded- Returns:
- the result of the load as reported by Byteman
- Throws:
Exception
- if the request failed
-
getLoadedBootClassloaderJars
Returns a list of jars that were added to the Byteman agent's boot classloader.- Returns:
- list of jars that were added to the boot classloader
- Throws:
Exception
- if the request failed
-
getLoadedSystemClassloaderJars
Returns a list of jars that were added to the Byteman agent's system classloader.- Returns:
- list of jars that were added to the system classloader
- Throws:
Exception
- if the request failed
-
addRulesFromFiles
Deploys rules into Byteman, where the rule definitions are found in the local files found at the given paths. The rule definitions found in the files are actually passed down directly to Byteman, not the file paths themselves. Therefore, these files must exist on the machine where this client is running (i.e. the files are not loaded directly by the Byteman agent).- Parameters:
filePaths
- the local files containing the rule definitions to be deployed to Byteman- Returns:
- the results of the deployment
- Throws:
Exception
- if the request failed
-
addRulesFromResources
Deploys rules into Byteman, where the rule definitions are found in the given streams. Rule definitions are read from the streams and the rule text uploaded directly to the Byteman agent. This method is useful for using rules files from the classpath.- Parameters:
resourceStreams
- input streams containing the rule definitions to be deployed to Byteman- Returns:
- the results of the deployment
- Throws:
Exception
- if the request failed
-
addScripts
Deploys rule scripts into Byteman- Parameters:
scripts
- scripts to be deployed to Byteman- Returns:
- the results of the deployment
- Throws:
Exception
- if the request failed
-
addRules
Deprecated.old version which uses a Map- Parameters:
rules
- the rules to be added- Returns:
- the results of the deployment
- Throws:
Exception
- if the request failed
-
deleteRulesFromFiles
Deletes rules from Byteman, where the rule definitions are found in the local files found at the given paths. After this method is done, the given rules will no longer be processed by Byteman. The rule definitions found in the files are actually passed down directly to Byteman, not the file paths themselves. Therefore, these files must exist on the machine where this client is running (i.e. the files are not read directly by the Byteman agent).- Parameters:
filePaths
- the local files containing the rule definitions to be deleted from Byteman- Returns:
- the results of the deletion
- Throws:
Exception
- if the request failed
-
deleteRulesFromResources
Deletes rules from Byteman, where the rule definitions are found in the given streams. Rule definitions are read from the streams so that details of which rules to unload can be uploaded directly to the Byteman agent. This method is useful for using rules files from the classpath.- Parameters:
resourceStreams
- the URLS to files containing the rule definitions to be deleted from Byteman- Returns:
- the results of the deletion
- Throws:
Exception
- if the request failed
-
deleteScripts
Deletes rules from Byteman.- Parameters:
scripts
- rule scripts to be deleted from Byteman- Returns:
- the results of the deletion
- Throws:
Exception
- if the request failed
-
deleteRules
Deprecated.old version which uses a Map- Parameters:
rules
- the rules to be deleted- Returns:
- the results of the deletion
- Throws:
Exception
- if the request failed
-
setSystemProperties
Sets system properties in the Byteman agent VM. If Byteman was configured for strict mode, only Byteman related system properties will be allowed to be set.- Parameters:
propsToSet
- system properties to set in the Byteman agent VM- Returns:
- response from the Byteman agent
- Throws:
Exception
- if the request failed
-
listSystemProperties
Returns the system properties set in the Byteman agent VM. If Byteman was configured for strict mode, only Byteman related system properties will be returned.- Returns:
- system properties defined in the Byteman agent VM
- Throws:
Exception
- if the request failed
-
submitRequest
Submits the generic request string to the Byteman agent for processing.- Parameters:
request
- the request to submit- Returns:
- the response that the Byteman agent replied with
- Throws:
Exception
- if the request failed
-
getRulesFromRuleStreams
- Throws:
Exception
-
getRulesFromRuleFiles
- Throws:
Exception
-
readScriptText
- Throws:
Exception
-
confirmRuleFileValidity
-
main
A main routine which submits requests to the Byteman agent utilizing the Java API.- Parameters:
args
- seeusage(PrintStream, int)
for a description of the allowed arguments
-
usage
-