Package org.apache.catalina.ant.jmx
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:
java.lang.Cloneable
- Direct Known Subclasses:
JMXAccessorCreateTask,JMXAccessorGetTask,JMXAccessorInvokeTask,JMXAccessorQueryTask,JMXAccessorSetTask,JMXAccessorUnregisterTask
public class JMXAccessorTask extends BaseRedirectorHelperTask
Access JMX JSR 160 MBeans Server.- 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
Fields Modifier and Type Field Description static java.lang.StringJMX_SERVICE_PREFIXJMX service URL prefix.static java.lang.StringJMX_SERVICE_SUFFIXJMX service URL suffix.-
Fields inherited from class org.apache.catalina.ant.BaseRedirectorHelperTask
alwaysLog, failOnError, redirectErrStream, redirector, redirectorConfigured, redirectorElement, redirectOutput, redirectOutStream
-
-
Constructor Summary
Constructors Constructor Description JMXAccessorTask()Constructs a new JMXAccessorTask.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static javax.management.MBeanServerConnectionaccessJMXConnection(org.apache.tools.ant.Project project, java.lang.String url, java.lang.String host, java.lang.String port, java.lang.String username, java.lang.String password, java.lang.String refId)Get Current Connection from ref parameter or create a new one!protected java.lang.ObjectconvertStringToType(java.lang.String value, java.lang.String valueType)Convert string to datatype.static javax.management.MBeanServerConnectioncreateJMXConnection(java.lang.String url, java.lang.String host, java.lang.String port, java.lang.String username, java.lang.String password)Create a new JMX Connection with auth when username and password is set.protected voidcreateProperty(java.lang.Object result)create result as property with name from attribute resultpropertyprotected voidcreateProperty(java.lang.String propertyPrefix, java.lang.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(java.lang.String name, java.lang.Object result)Echo the result to the output.voidexecute()Execute the specified command.java.lang.StringgetDelimiter()Get the delimiter for array results.java.lang.StringgetHost()Get the JMX MBeanServer host.java.lang.StringgetIf()Get the if condition property name.protected javax.management.MBeanServerConnectiongetJMXConnection()get JMXConnectionjava.lang.StringgetName()Get the name used at remote MbeanServer.java.lang.StringgetPassword()Get the login password.java.lang.StringgetPort()Get the JMX MBeanServer port.java.lang.StringgetProperty(java.lang.String property)Get Propertyjava.lang.StringgetRef()Get the reference ID for the JMX connection.java.lang.StringgetResultproperty()Get the result property name.java.lang.StringgetUnless()Get the unless condition property name.java.lang.StringgetUrl()Get the JMX MBeanServer URL.java.lang.StringgetUsername()Get the login username.booleanisEcho()Get the echo flag.booleanisSeparatearrayresults()Get the separate array results flag.booleanisUseRef()Check if a reference is being used.java.lang.StringjmxExecute(javax.management.MBeanServerConnection jmxServerConnection)Execute the specified command, based on the configured properties.voidsetDelimiter(java.lang.String separator)Set the delimiter for array results.voidsetEcho(boolean echo)Set the echo flag.voidsetHost(java.lang.String host)Set the JMX MBeanServer host.voidsetIf(java.lang.String c)Only execute if a property of the given name exists in the current project.voidsetName(java.lang.String objectName)Set the name used at remote MbeanServer.voidsetPassword(java.lang.String password)Set the login password.voidsetPort(java.lang.String port)Set the JMX MBeanServer port.booleansetProperty(java.lang.String property, java.lang.Object value)Set a property value.voidsetRef(java.lang.String refId)Set the reference ID for the JMX connection.voidsetResultproperty(java.lang.String propertyName)Set the result property name.voidsetSeparatearrayresults(boolean separateArrayResults)Set the separate array results flag.voidsetUnless(java.lang.String c)Only execute if a property of the given name does not exist in the current project.voidsetUrl(java.lang.String url)Set the JMX MBeanServer URL.voidsetUsername(java.lang.String username)Set the login username.protected booleantestIfCondition()test the if conditionprotected booleantestUnlessCondition()test the unless condition-
Methods inherited from class org.apache.catalina.ant.BaseRedirectorHelperTask
addConfiguredRedirector, closeRedirector, handleErrorFlush, handleErrorOutput, handleFlush, handleOutput, handleOutput, isFailOnError, openRedirector, setAlwaysLog, setAppend, setCreateEmptyFiles, setError, setErrorProperty, setFailonerror, setLogError, setOutput, setOutputproperty
-
Methods 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, setTaskType
-
-
-
-
Field Detail
-
JMX_SERVICE_PREFIX
public static final java.lang.String JMX_SERVICE_PREFIX
JMX service URL prefix.- See Also:
- Constant Field Values
-
JMX_SERVICE_SUFFIX
public static final java.lang.String JMX_SERVICE_SUFFIX
JMX service URL suffix.- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
public java.lang.String getName()
Get the name used at remote MbeanServer.- Returns:
- the name used at remote MbeanServer
-
setName
public void setName(java.lang.String objectName)
Set the name used at remote MbeanServer.- Parameters:
objectName- the MBean object name
-
getResultproperty
public java.lang.String getResultproperty()
Get the result property name.- Returns:
- the result property name
-
setResultproperty
public void setResultproperty(java.lang.String propertyName)
Set the result property name.- Parameters:
propertyName- the property name to set
-
getDelimiter
public java.lang.String getDelimiter()
Get the delimiter for array results.- Returns:
- the delimiter
-
setDelimiter
public void setDelimiter(java.lang.String separator)
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
public java.lang.String getPassword()
Get the login password.- Returns:
- the login password
-
setPassword
public void setPassword(java.lang.String password)
Set the login password.- Parameters:
password- the password to set
-
getUsername
public java.lang.String getUsername()
Get the login username.- Returns:
- the login username
-
setUsername
public void setUsername(java.lang.String username)
Set the login username.- Parameters:
username- the username to set
-
getUrl
public java.lang.String getUrl()
Get the JMX MBeanServer URL.- Returns:
- the JMX URL
-
setUrl
public void setUrl(java.lang.String url)
Set the JMX MBeanServer URL.- Parameters:
url- the URL to set
-
getHost
public java.lang.String getHost()
Get the JMX MBeanServer host.- Returns:
- the host
-
setHost
public void setHost(java.lang.String host)
Set the JMX MBeanServer host.- Parameters:
host- the host to set
-
getPort
public java.lang.String getPort()
Get the JMX MBeanServer port.- Returns:
- the port
-
setPort
public void setPort(java.lang.String port)
Set the JMX MBeanServer port.- Parameters:
port- the port to set
-
isUseRef
public boolean isUseRef()
Check if a reference is being used.- Returns:
trueif a reference is set
-
getRef
public java.lang.String getRef()
Get the reference ID for the JMX connection.- Returns:
- the reference ID
-
setRef
public void setRef(java.lang.String refId)
Set the reference ID for the JMX connection.- Parameters:
refId- the reference ID to set
-
getIf
public java.lang.String getIf()
Get the if condition property name.- Returns:
- the if condition property name
-
setIf
public void setIf(java.lang.String c)
Only execute if a property of the given name exists in the current project.- Parameters:
c- property name
-
getUnless
public java.lang.String getUnless()
Get the unless condition property name.- Returns:
- the unless condition property name
-
setUnless
public void setUnless(java.lang.String c)
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 javax.management.MBeanServerConnection createJMXConnection(java.lang.String url, java.lang.String host, java.lang.String port, java.lang.String username, java.lang.String password) throws java.net.MalformedURLException, java.io.IOExceptionCreate 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:
java.net.MalformedURLException- Invalid URL specifiedjava.io.IOException- 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 javax.management.MBeanServerConnection accessJMXConnection(org.apache.tools.ant.Project project, java.lang.String url, java.lang.String host, java.lang.String port, java.lang.String username, java.lang.String password, java.lang.String refId) throws java.net.MalformedURLException, java.io.IOExceptionGet 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:
java.net.MalformedURLException- Invalid URL specifiedjava.io.IOException- Other connection error
-
getJMXConnection
protected javax.management.MBeanServerConnection getJMXConnection() throws java.net.MalformedURLException, java.io.IOExceptionget JMXConnection- Returns:
- the JMX connection
- Throws:
java.net.MalformedURLException- Invalid URL specifiedjava.io.IOException- Other connection error
-
jmxExecute
public java.lang.String jmxExecute(javax.management.MBeanServerConnection jmxServerConnection) throws java.lang.ExceptionExecute 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:
java.lang.Exception- if an error occurs
-
convertStringToType
protected java.lang.Object convertStringToType(java.lang.String value, java.lang.String valueType)Convert string to datatype.- Parameters:
value- The valuevalueType- The type- Returns:
- The converted object
-
echoResult
protected void echoResult(java.lang.String name, java.lang.Object result)Echo the result to the output.- Parameters:
name- context of resultresult- The result
-
createProperty
protected void createProperty(java.lang.Object result)
create result as property with name from attribute resultproperty- Parameters:
result- The result- See Also:
createProperty(String, Object)
-
createProperty
protected void createProperty(java.lang.String propertyPrefix, java.lang.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. 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
public java.lang.String getProperty(java.lang.String property)
Get Property- Parameters:
property- name- Returns:
- The property value
-
setProperty
public boolean setProperty(java.lang.String property, java.lang.Object value)Set a property value.- Parameters:
property- The property namevalue- The value- Returns:
trueif successful
-
-