Class JMXAccessorTask

  • All Implemented Interfaces:
    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
    Examples: open server with reference and authorisation
    
        <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
    • Constructor Detail

      • JMXAccessorTask

        public JMXAccessorTask()
    • Method Detail

      • getName

        public String getName()
        Get the name used at remote MbeanServer.
        Returns:
        the name used at remote MbeanServer
      • setName

        public void setName​(String objectName)
      • getResultproperty

        public String getResultproperty()
        Returns:
        Returns the resultproperty.
      • setResultproperty

        public void setResultproperty​(String propertyName)
        Parameters:
        propertyName - The resultproperty to set.
      • getDelimiter

        public String getDelimiter()
        Returns:
        Returns the delimiter.
      • setDelimiter

        public void setDelimiter​(String separator)
        Parameters:
        separator - The delimiter to set.
      • isEcho

        public boolean isEcho()
        Returns:
        Returns the echo.
      • setEcho

        public void setEcho​(boolean echo)
        Parameters:
        echo - The echo to set.
      • isSeparatearrayresults

        public boolean isSeparatearrayresults()
        Returns:
        Returns the separatearrayresults.
      • setSeparatearrayresults

        public void setSeparatearrayresults​(boolean separateArrayResults)
        Parameters:
        separateArrayResults - The separatearrayresults to set.
      • getPassword

        public String getPassword()
        Returns:
        The login password for the Manager application.
      • setPassword

        public void setPassword​(String password)
      • getUsername

        public String getUsername()
        Returns:
        The login username for the JMX MBeanServer.
      • setUsername

        public void setUsername​(String username)
      • getUrl

        public String getUrl()
        Returns:
        The URL of the JMX JSR 160 MBeanServer to be used.
      • setUrl

        public void setUrl​(String url)
      • getHost

        public String getHost()
        Returns:
        The Host of the JMX JSR 160 MBeanServer to be used.
      • setHost

        public void setHost​(String host)
      • getPort

        public String getPort()
        Returns:
        The Port of the JMX JSR 160 MBeanServer to be used.
      • setPort

        public void setPort​(String port)
      • isUseRef

        public boolean isUseRef()
        Returns:
        Returns the useRef.
      • getRef

        public String getRef()
        Returns:
        Returns the ref.
      • setRef

        public void setRef​(String refId)
        Parameters:
        refId - The ref to set.
      • getIf

        public String getIf()
        Returns:
        Returns the ifCondition.
      • setIf

        public void setIf​(String c)
        Only execute if a property of the given name exists in the current project.
        Parameters:
        c - property name
      • getUnless

        public String getUnless()
        Returns:
        Returns the unlessCondition.
      • setUnless

        public void setUnless​(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.BuildException
        Execute the specified command. This logic only performs the common attribute validation required by all subclasses; it does not perform any functional logic directly.
        Overrides:
        execute in class org.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 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
      • 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 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
      • jmxExecute

        public String jmxExecute​(MBeanServerConnection jmxServerConnection)
                          throws Exception
        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

        protected Object convertStringToType​(String value,
                                             String valueType)
        Convert 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

        protected void echoResult​(String name,
                                  Object result)
        Parameters:
        name - context of result
        result - The result
      • createProperty

        protected void createProperty​(Object result)
        create result as property with name from attribute resultproperty
        Parameters:
        result - The result
        See Also:
        createProperty(String, Object)
      • createProperty

        protected void createProperty​(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.length and store the result array length at resultproperty.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
      • getProperty

        public String getProperty​(String property)
        Get Property
        Parameters:
        property - name
        Returns:
        The property value
      • setProperty

        public boolean setProperty​(String property,
                                   Object value)
        Parameters:
        property - The property
        value - The value
        Returns:
        True if successful