public class JMXAccessorTask extends BaseRedirectorHelperTask
<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.Modifier and Type | Field and Description |
---|---|
static String |
JMX_SERVICE_PREFIX |
static String |
JMX_SERVICE_SUFFIX |
alwaysLog, failOnError, redirectErrStream, redirector, redirectorConfigured, redirectorElement, redirectOutput, redirectOutStream
Constructor and Description |
---|
JMXAccessorTask() |
Modifier and Type | Method and Description |
---|---|
static MBeanServerConnection |
accessJMXConnection(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 Object |
convertStringToType(String value,
String valueType)
Convert string to datatype FIXME How we can transfer values from ant
project reference store (ref)?
|
static MBeanServerConnection |
createJMXConnection(String url,
String host,
String port,
String username,
String password)
Create a new JMX Connection with auth when username and password is set.
|
protected void |
createProperty(Object result)
create result as property with name from attribute resultproperty
|
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 . |
protected void |
echoResult(String name,
Object result) |
void |
execute()
Execute the specified command.
|
String |
getDelimiter() |
String |
getHost() |
String |
getIf() |
protected MBeanServerConnection |
getJMXConnection()
get JMXConnection
|
String |
getName()
Get the name used at remote MbeanServer.
|
String |
getPassword() |
String |
getPort() |
String |
getProperty(String property)
Get Property
|
String |
getRef() |
String |
getResultproperty() |
String |
getUnless() |
String |
getUrl() |
String |
getUsername() |
boolean |
isEcho() |
boolean |
isSeparatearrayresults() |
boolean |
isUseRef() |
String |
jmxExecute(MBeanServerConnection jmxServerConnection)
Execute the specified command, based on the configured properties.
|
void |
setDelimiter(String separator) |
void |
setEcho(boolean echo) |
void |
setHost(String host) |
void |
setIf(String c)
Only execute if a property of the given name exists in the current
project.
|
void |
setName(String objectName) |
void |
setPassword(String password) |
void |
setPort(String port) |
boolean |
setProperty(String property,
Object value) |
void |
setRef(String refId) |
void |
setResultproperty(String propertyName) |
void |
setSeparatearrayresults(boolean separateArrayResults) |
void |
setUnless(String c)
Only execute if a property of the given name does not exist in the
current project.
|
void |
setUrl(String url) |
void |
setUsername(String username) |
protected boolean |
testIfCondition()
test the if condition
|
protected boolean |
testUnlessCondition()
test the unless condition
|
addConfiguredRedirector, closeRedirector, handleErrorFlush, handleErrorOutput, handleFlush, handleOutput, handleOutput, isFailOnError, openRedirector, setAlwaysLog, setAppend, setCreateEmptyFiles, setError, setErrorProperty, setFailonerror, setLogError, setOutput, setOutputproperty
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleInput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
public static final String JMX_SERVICE_PREFIX
public static final String JMX_SERVICE_SUFFIX
public String getName()
public void setName(String objectName)
public String getResultproperty()
public void setResultproperty(String propertyName)
propertyName
- The resultproperty to set.public String getDelimiter()
public void setDelimiter(String separator)
separator
- The delimiter to set.public boolean isEcho()
public void setEcho(boolean echo)
echo
- The echo to set.public boolean isSeparatearrayresults()
public void setSeparatearrayresults(boolean separateArrayResults)
separateArrayResults
- The separatearrayresults to set.public String getPassword()
Manager
application.public void setPassword(String password)
public String getUsername()
JMX
MBeanServer.public void setUsername(String username)
public String getUrl()
JMX JSR 160
MBeanServer to be used.public void setUrl(String url)
public String getHost()
JMX JSR 160
MBeanServer to be used.public void setHost(String host)
public String getPort()
JMX JSR 160
MBeanServer to be used.public void setPort(String port)
public boolean isUseRef()
public String getRef()
public void setRef(String refId)
refId
- The ref to set.public String getIf()
public void setIf(String c)
c
- property namepublic String getUnless()
public void setUnless(String c)
c
- property namepublic void execute() throws org.apache.tools.ant.BuildException
execute
in class org.apache.tools.ant.Task
org.apache.tools.ant.BuildException
- if a validation error occurspublic static MBeanServerConnection createJMXConnection(String url, String host, String port, String username, String password) throws MalformedURLException, IOException
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 userMalformedURLException
- Invalid URL specifiedIOException
- Other connection errorprotected boolean testIfCondition()
protected boolean testUnlessCondition()
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
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 projectMalformedURLException
- Invalid URL specifiedIOException
- Other connection errorprotected MBeanServerConnection getJMXConnection() throws MalformedURLException, IOException
MalformedURLException
- Invalid URL specifiedIOException
- Other connection errorpublic String jmxExecute(MBeanServerConnection jmxServerConnection) throws Exception
jmxServerConnection
- The JMX connection that should be usedException
- if an error occursprotected Object convertStringToType(String value, String valueType)
value
- The valuevalueType
- The typeprotected void echoResult(String name, Object result)
name
- context of resultresult
- The resultprotected void createProperty(Object result)
result
- The resultcreateProperty(String, Object)
protected void createProperty(String propertyPrefix, Object result)
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).propertyPrefix
- Prefix for the propertyresult
- The resultpublic String getProperty(String property)
property
- nameCopyright © 2000-2016 Apache Software Foundation. All Rights Reserved.