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:
- 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
- Author:
- Peter Rossbach
- 
Field SummaryFieldsFields inherited from class org.apache.catalina.ant.BaseRedirectorHelperTaskalwaysLog, failOnError, redirectErrStream, redirector, redirectorConfigured, redirectorElement, redirectOutput, redirectOutStreamFields inherited from class org.apache.tools.ant.Tasktarget, taskName, taskType, wrapperFields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
- 
Constructor SummaryConstructors
- 
Method SummaryModifier 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 FIXME How we can transfer values from ant project reference store (ref)?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) voidexecute()Execute the specified command.getHost()getIf()protected MBeanServerConnectionget JMXConnectiongetName()Get the name used at remote MbeanServer.getPort()getProperty(String property) Get PropertygetRef()getUrl()booleanisEcho()booleanbooleanisUseRef()jmxExecute(MBeanServerConnection jmxServerConnection) Execute the specified command, based on the configured properties.voidsetDelimiter(String separator) voidsetEcho(boolean echo) voidvoidOnly execute if a property of the given name exists in the current project.voidvoidsetPassword(String password) voidbooleansetProperty(String property, Object value) voidvoidsetResultproperty(String propertyName) voidsetSeparatearrayresults(boolean separateArrayResults) voidOnly execute if a property of the given name does not exist in the current project.voidvoidsetUsername(String username) protected booleantest the if conditionprotected booleantest the unless conditionMethods inherited from class org.apache.catalina.ant.BaseRedirectorHelperTaskaddConfiguredRedirector, closeRedirector, handleErrorFlush, handleErrorOutput, handleFlush, handleOutput, handleOutput, isFailOnError, openRedirector, setAlwaysLog, setAppend, setCreateEmptyFiles, setError, setErrorProperty, setFailonerror, setLogError, setOutput, setOutputpropertyMethods inherited from class org.apache.tools.ant.TaskbindToOwner, 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.ProjectComponentclone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
- 
Field Details- 
JMX_SERVICE_PREFIX- See Also:
 
- 
JMX_SERVICE_SUFFIX- See Also:
 
 
- 
- 
Constructor Details- 
JMXAccessorTaskpublic JMXAccessorTask()
 
- 
- 
Method Details- 
getNameGet the name used at remote MbeanServer.- Returns:
- the name used at remote MbeanServer
 
- 
setName
- 
getResultproperty- Returns:
- Returns the resultproperty.
 
- 
setResultproperty- Parameters:
- propertyName- The resultproperty to set.
 
- 
getDelimiter- Returns:
- Returns the delimiter.
 
- 
setDelimiter- Parameters:
- separator- The delimiter to set.
 
- 
isEchopublic boolean isEcho()- Returns:
- Returns the echo.
 
- 
setEchopublic void setEcho(boolean echo) - Parameters:
- echo- The echo to set.
 
- 
isSeparatearrayresultspublic boolean isSeparatearrayresults()- Returns:
- Returns the separatearrayresults.
 
- 
setSeparatearrayresultspublic void setSeparatearrayresults(boolean separateArrayResults) - Parameters:
- separateArrayResults- The separatearrayresults to set.
 
- 
getPassword- Returns:
- The login password for the Managerapplication.
 
- 
setPassword
- 
getUsername- Returns:
- The login username for the JMXMBeanServer.
 
- 
setUsername
- 
getUrl- Returns:
- The URL of the JMX JSR 160MBeanServer to be used.
 
- 
setUrl
- 
getHost- Returns:
- The Host of the JMX JSR 160MBeanServer to be used.
 
- 
setHost
- 
getPort- Returns:
- The Port of the JMX JSR 160MBeanServer to be used.
 
- 
setPort
- 
isUseRefpublic boolean isUseRef()- Returns:
- Returns the useRef.
 
- 
getRef- Returns:
- Returns the ref.
 
- 
setRef- Parameters:
- refId- The ref to set.
 
- 
getIf- Returns:
- Returns the ifCondition.
 
- 
setIfOnly execute if a property of the given name exists in the current project.- Parameters:
- c- property name
 
- 
getUnless- Returns:
- Returns the unlessCondition.
 
- 
setUnlessOnly execute if a property of the given name does not exist in the current project.- Parameters:
- c- property name
 
- 
executepublic 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 class- org.apache.tools.ant.Task
- Throws:
- org.apache.tools.ant.BuildException- if a validation error occurs
 
- 
createJMXConnectionpublic 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 server
- port- Port number for the JMX server
- username- User name for the connection
- password- Credentials corresponding to the specified user
- Returns:
- the JMX connection
- Throws:
- MalformedURLException- Invalid URL specified
- IOException- Other connection error
 
- 
testIfConditionprotected boolean testIfCondition()test the if condition- Returns:
- true if there is no if condition, or the named property exists
 
- 
testUnlessConditionprotected 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
 
- 
accessJMXConnectionpublic 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 project
- 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 server
- port- Port number for the JMX server
- username- User name for the connection
- password- Credentials corresponding to the specified user
- refId- The Id of the reference to retrieve in the project
- Returns:
- the JMX connection
- Throws:
- MalformedURLException- Invalid URL specified
- IOException- Other connection error
 
- 
getJMXConnectionget JMXConnection- Returns:
- the JMX connection
- Throws:
- MalformedURLException- Invalid URL specified
- IOException- Other connection error
 
- 
jmxExecuteExecute 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
 
- 
convertStringToTypeConvert string to datatype FIXME How we can transfer values from ant project reference store (ref)?- Parameters:
- value- The value
- valueType- The type
- Returns:
- The converted object
 
- 
echoResult- Parameters:
- name- context of result
- result- The result
 
- 
createPropertycreate result as property with name from attribute resultproperty- Parameters:
- result- The result
- See Also:
 
- 
createPropertycreate 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 property
- result- The result
 
- 
getPropertyGet Property- Parameters:
- property- name
- Returns:
- The property value
 
- 
setProperty- Parameters:
- property- The property
- value- The value
- Returns:
- True if successful
 
 
-