Class JMXAccessorTask
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.catalina.ant.BaseRedirectorHelperTask
org.apache.catalina.ant.jmx.JMXAccessorTask
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
JMXAccessorCreateTask, JMXAccessorGetTask, JMXAccessorInvokeTask, JMXAccessorQueryTask, JMXAccessorSetTask, JMXAccessorUnregisterTask
Access JMX JSR 160 MBeans Server.
NOTE : These tasks require Ant 1.6 or later interface.
- open more then one JSR 160 rmi connection
- Get/Set Mbeans attributes
- Call Mbean Operation with arguments
- Argument values can be converted from string to int,long,float,double,boolean,ObjectName or InetAddress
- Query Mbeans
- Show Get, Call, Query result at Ant console log
- Bind Get, Call, Query result at Ant properties
<jmxOpen
host="127.0.0.1"
port="9014"
username="monitorRole"
password="mysecret"
ref="jmx.myserver"
/>
All calls after opening with same refid reuse the connection.
First call to a remote MBeanserver save the JMXConnection a referenz jmx.server
All JMXAccessorXXXTask support the attribute if and unless. With if the task is only execute when property exist and with unless when property not exists.NOTE : These tasks require Ant 1.6 or later interface.
- Since:
- 5.5.10
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringJMX service URL prefix.static final StringJMX service URL suffix.Fields inherited from class BaseRedirectorHelperTask
alwaysLog, failOnError, redirectErrStream, redirector, redirectorConfigured, redirectorElement, redirectOutput, redirectOutStreamFields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapperFields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MBeanServerConnectionaccessJMXConnection(org.apache.tools.ant.Project project, String url, String host, String port, String username, String password, String refId) Get Current Connection from ref parameter or create a new one!protected ObjectconvertStringToType(String value, String valueType) Convert string to datatype.static MBeanServerConnectionCreate a new JMX Connection with auth when username and password is set.protected voidcreateProperty(Object result) create result as property with name from attribute resultpropertyprotected voidcreateProperty(String propertyPrefix, Object result) create result as property with name from property prefix When result is an array and isSeparateArrayResults is true, resultproperty used as prefix (resultproperty.0-array.lengthand store the result array length atresultproperty.length.protected voidechoResult(String name, Object result) Echo the result to the output.voidexecute()Execute the specified command.Get the delimiter for array results.getHost()Get the JMX MBeanServer host.getIf()Get the if condition property name.protected MBeanServerConnectionget JMXConnectiongetName()Get the name used at remote MbeanServer.Get the login password.getPort()Get the JMX MBeanServer port.getProperty(String property) Get PropertygetRef()Get the reference ID for the JMX connection.Get the result property name.Get the unless condition property name.getUrl()Get the JMX MBeanServer URL.Get the login username.booleanisEcho()Get the echo flag.booleanGet the separate array results flag.booleanisUseRef()Check if a reference is being used.jmxExecute(MBeanServerConnection jmxServerConnection) Execute the specified command, based on the configured properties.voidsetDelimiter(String separator) Set the delimiter for array results.voidsetEcho(boolean echo) Set the echo flag.voidSet the JMX MBeanServer host.voidOnly execute if a property of the given name exists in the current project.voidSet the name used at remote MbeanServer.voidsetPassword(String password) Set the login password.voidSet the JMX MBeanServer port.booleansetProperty(String property, Object value) Set a property value.voidSet the reference ID for the JMX connection.voidsetResultproperty(String propertyName) Set the result property name.voidsetSeparatearrayresults(boolean separateArrayResults) Set the separate array results flag.voidOnly execute if a property of the given name does not exist in the current project.voidSet the JMX MBeanServer URL.voidsetUsername(String username) Set the login username.protected booleantest the if conditionprotected booleantest the unless conditionMethods inherited from class BaseRedirectorHelperTask
addConfiguredRedirector, closeRedirector, handleErrorFlush, handleErrorOutput, handleFlush, handleOutput, handleOutput, isFailOnError, openRedirector, setAlwaysLog, setAppend, setCreateEmptyFiles, setError, setErrorProperty, setFailonerror, setLogError, setOutput, setOutputpropertyMethods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleInput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeMethods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
-
Field Details
-
JMX_SERVICE_PREFIX
-
JMX_SERVICE_SUFFIX
-
-
Constructor Details
-
JMXAccessorTask
public JMXAccessorTask()Constructs a new JMXAccessorTask.
-
-
Method Details
-
getName
Get the name used at remote MbeanServer.- Returns:
- the name used at remote MbeanServer
-
setName
Set the name used at remote MbeanServer.- Parameters:
objectName- the MBean object name
-
getResultproperty
-
setResultproperty
Set the result property name.- Parameters:
propertyName- the property name to set
-
getDelimiter
-
setDelimiter
Set the delimiter for array results.- Parameters:
separator- the delimiter to set
-
isEcho
public boolean isEcho()Get the echo flag.- Returns:
- the echo flag
-
setEcho
public void setEcho(boolean echo) Set the echo flag.- Parameters:
echo- the echo flag to set
-
isSeparatearrayresults
public boolean isSeparatearrayresults()Get the separate array results flag.- Returns:
- the separate array results flag
-
setSeparatearrayresults
public void setSeparatearrayresults(boolean separateArrayResults) Set the separate array results flag.- Parameters:
separateArrayResults- the flag to set
-
getPassword
-
setPassword
Set the login password.- Parameters:
password- the password to set
-
getUsername
-
setUsername
Set the login username.- Parameters:
username- the username to set
-
getUrl
-
setUrl
-
getHost
-
setHost
-
getPort
-
setPort
-
isUseRef
public boolean isUseRef()Check if a reference is being used.- Returns:
trueif a reference is set
-
getRef
-
setRef
Set the reference ID for the JMX connection.- Parameters:
refId- the reference ID to set
-
getIf
-
setIf
Only execute if a property of the given name exists in the current project.- Parameters:
c- property name
-
getUnless
Get the unless condition property name.- Returns:
- the unless condition property name
-
setUnless
Only execute if a property of the given name does not exist in the current project.- Parameters:
c- property name
-
execute
public void execute() throws org.apache.tools.ant.BuildExceptionExecute the specified command. This logic only performs the common attribute validation required by all subclasses; it does not perform any functional logic directly.- Overrides:
executein classorg.apache.tools.ant.Task- Throws:
org.apache.tools.ant.BuildException- if a validation error occurs
-
createJMXConnection
public static MBeanServerConnection createJMXConnection(String url, String host, String port, String username, String password) throws MalformedURLException, IOException Create a new JMX Connection with auth when username and password is set.- Parameters:
url- URL to be used for the JMX connection (if specified, it is a complete URL so host and port will not be used)host- Host name of the JMX serverport- Port number for the JMX serverusername- User name for the connectionpassword- Credentials corresponding to the specified user- Returns:
- the JMX connection
- Throws:
MalformedURLException- Invalid URL specifiedIOException- Other connection error
-
testIfCondition
protected boolean testIfCondition()test the if condition- Returns:
- true if there is no if condition, or the named property exists
-
testUnlessCondition
protected boolean testUnlessCondition()test the unless condition- Returns:
- true if there is no unless condition, or there is a named property but it doesn't exist
-
accessJMXConnection
public static MBeanServerConnection accessJMXConnection(org.apache.tools.ant.Project project, String url, String host, String port, String username, String password, String refId) throws MalformedURLException, IOException Get Current Connection from ref parameter or create a new one!- Parameters:
project- The Ant projecturl- URL to be used for the JMX connection (if specified, it is a complete URL so host and port will not be used)host- Host name of the JMX serverport- Port number for the JMX serverusername- User name for the connectionpassword- Credentials corresponding to the specified userrefId- The Id of the reference to retrieve in the project- Returns:
- the JMX connection
- Throws:
MalformedURLException- Invalid URL specifiedIOException- Other connection error
-
getJMXConnection
get JMXConnection- Returns:
- the JMX connection
- Throws:
MalformedURLException- Invalid URL specifiedIOException- Other connection error
-
jmxExecute
Execute the specified command, based on the configured properties. The input stream will be closed upon completion of this task, whether it was executed successfully or not.- Parameters:
jmxServerConnection- The JMX connection that should be used- Returns:
- An error message string in some situations
- Throws:
Exception- if an error occurs
-
convertStringToType
-
echoResult
-
createProperty
create result as property with name from attribute resultproperty- Parameters:
result- The result- See Also:
-
createProperty
create result as property with name from property prefix When result is an array and isSeparateArrayResults is true, resultproperty used as prefix (resultproperty.0-array.lengthand store the result array length atresultproperty.length. Other option is that you delimit your result with a delimiter (java.util.StringTokenizer is used).- Parameters:
propertyPrefix- Prefix for the propertyresult- The result
-
getProperty
-
setProperty
-