Methods Summary |
---|
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)Get Current Connection from ref parameter or create a new one!
MBeanServerConnection jmxServerConnection = null;
boolean isRef = project != null && refId != null && refId.length() > 0;
if (isRef) {
Object pref = project.getReference(refId);
try {
jmxServerConnection = (MBeanServerConnection) pref;
} catch (ClassCastException cce) {
if (project != null) {
project.log("wrong object reference " + refId + " - "
+ pref.getClass());
}
return null;
}
}
if (jmxServerConnection == null) {
jmxServerConnection = createJMXConnection(url, host, port,
username, password);
}
if (isRef && jmxServerConnection != null) {
project.addReference(refId, jmxServerConnection);
}
return jmxServerConnection;
|
protected java.lang.Object | convertStringToType(java.lang.String value, java.lang.String valueType)Convert string to datatype FIXME How we can transfer values from ant
project reference store (ref)?
if ("java.lang.String".equals(valueType))
return value;
Object convertValue = value;
if ("java.lang.Integer".equals(valueType) || "int".equals(valueType)) {
try {
convertValue = new Integer(value);
} catch (NumberFormatException ex) {
if (isEcho())
handleErrorOutput("Unable to convert to integer:" + value);
}
} else if ("java.lang.Long".equals(valueType)
|| "long".equals(valueType)) {
try {
convertValue = new Long(value);
} catch (NumberFormatException ex) {
if (isEcho())
handleErrorOutput("Unable to convert to long:" + value);
}
} else if ("java.lang.Boolean".equals(valueType)
|| "boolean".equals(valueType)) {
convertValue = new Boolean(value);
} else if ("java.lang.Float".equals(valueType)
|| "float".equals(valueType)) {
try {
convertValue = new Float(value);
} catch (NumberFormatException ex) {
if (isEcho())
handleErrorOutput("Unable to convert to float:" + value);
}
} else if ("java.lang.Double".equals(valueType)
|| "double".equals(valueType)) {
try {
convertValue = new Double(value);
} catch (NumberFormatException ex) {
if (isEcho())
handleErrorOutput("Unable to convert to double:" + value);
}
} else if ("javax.management.ObjectName".equals(valueType)
|| "name".equals(valueType)) {
try {
convertValue = new ObjectName(value);
} catch (MalformedObjectNameException e) {
if (isEcho())
handleErrorOutput("Unable to convert to ObjectName:"
+ value);
}
} else if ("java.net.InetAddress".equals(valueType)) {
try {
convertValue = InetAddress.getByName(value);
} catch (UnknownHostException exc) {
if (isEcho())
handleErrorOutput("Unable to resolve host name:" + value);
}
}
return convertValue;
|
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)create a new JMX Connection with auth when username and password is set.
String urlForJMX;
if (url != null)
urlForJMX = url;
else
urlForJMX = JMX_SERVICE_PREFIX + host + ":" + port
+ JMX_SERVICE_SUFFIX;
Map environment = null;
if (username != null && password != null) {
String[] credentials = new String[2];
credentials[0] = username;
credentials[1] = password;
environment = new HashMap();
environment.put(JMXConnector.CREDENTIALS, credentials);
}
return JMXConnectorFactory.connect(new JMXServiceURL(urlForJMX),
environment).getMBeanServerConnection();
|
protected void | createProperty(java.lang.Object result)create result as property with name from attribute resultproperty
if (resultproperty != null) {
createProperty(resultproperty, result);
}
|
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.length and store the
result array length at resultproperty.length . Other
option is that you delemit your result with a delimiter
(java.util.StringTokenizer is used).
if (propertyPrefix == null)
propertyPrefix = "";
if (result instanceof CompositeDataSupport) {
CompositeDataSupport data = (CompositeDataSupport) result;
CompositeType compositeType = data.getCompositeType();
Set keys = compositeType.keySet();
for (Iterator iter = keys.iterator(); iter.hasNext();) {
String key = (String) iter.next();
Object value = data.get(key);
OpenType type = compositeType.getType(key);
if (type instanceof SimpleType) {
setProperty(propertyPrefix + "." + key, value);
} else {
createProperty(propertyPrefix + "." + key, value);
}
}
} else if (result instanceof TabularDataSupport) {
TabularDataSupport data = (TabularDataSupport) result;
for (Iterator iter = data.keySet().iterator(); iter.hasNext();) {
Object key = iter.next();
for (Iterator iter1 = ((List) key).iterator(); iter1.hasNext();) {
Object key1 = iter1.next();
CompositeData valuedata = data.get(new Object[] { key1 });
Object value = valuedata.get("value");
OpenType type = valuedata.getCompositeType().getType(
"value");
if (type instanceof SimpleType) {
setProperty(propertyPrefix + "." + key1, value);
} else {
createProperty(propertyPrefix + "." + key1, value);
}
}
}
} else if (result.getClass().isArray()) {
if (isSeparatearrayresults()) {
int size = 0;
for (int i = 0; i < Array.getLength(result); i++) {
if (setProperty(propertyPrefix + "." + size, Array.get(
result, i))) {
size++;
}
}
if (size > 0) {
setProperty(propertyPrefix + ".Length", Integer
.toString(size));
}
}
} else {
String delim = getDelimiter();
if (delim != null) {
StringTokenizer tokenizer = new StringTokenizer(result
.toString(), delim);
int size = 0;
for (; tokenizer.hasMoreTokens();) {
String token = tokenizer.nextToken();
if (setProperty(propertyPrefix + "." + size, token)) {
size++;
}
}
if (size > 0)
setProperty(propertyPrefix + ".Length", Integer
.toString(size));
} else {
setProperty(propertyPrefix, result.toString());
}
}
|
protected void | echoResult(java.lang.String name, java.lang.Object result)
if (isEcho()) {
if (result.getClass().isArray()) {
for (int i = 0; i < Array.getLength(result); i++) {
handleOutput(name + "." + i + "=" + Array.get(result, i));
}
} else
handleOutput(name + "=" + result);
}
|
public void | execute()Execute the specified command. This logic only performs the common
attribute validation required by all subclasses; it does not perform any
functional logic directly.
if (testIfCondition() && testUnlessCondition()) {
try {
String error = null;
MBeanServerConnection jmxServerConnection = getJMXConnection();
error = jmxExecute(jmxServerConnection);
if (error != null && isFailOnError()) {
// exception should be thrown only if failOnError == true
// or error line will be logged twice
throw new BuildException(error);
}
} catch (Throwable t) {
if (isFailOnError()) {
throw new BuildException(t);
} else {
handleErrorOutput(t.getMessage());
}
} finally {
closeRedirector();
}
}
|
public java.lang.String | getDelimiter()
return delimiter;
|
public java.lang.String | getHost()The Host of the JMX JSR 160 MBeanServer to be used.
return (this.host);
|
public java.lang.String | getIf()
return ifCondition;
|
public java.lang.String | getInfo()Return descriptive information about this implementation and the
corresponding version number, in the format
<description>/<version> .
return (info);
|
protected javax.management.MBeanServerConnection | getJMXConnection()get JMXConnection
MBeanServerConnection jmxServerConnection = null;
if (isUseRef()) {
Object pref = null ;
if(getProject() != null) {
pref = getProject().getReference(getRef());
if (pref != null) {
try {
jmxServerConnection = (MBeanServerConnection) pref;
} catch (ClassCastException cce) {
getProject().log(
"Wrong object reference " + getRef() + " - "
+ pref.getClass());
return null;
}
}
}
if (jmxServerConnection == null) {
jmxServerConnection = accessJMXConnection(getProject(),
getUrl(), getHost(), getPort(), getUsername(),
getPassword(), getRef());
}
} else {
jmxServerConnection = accessJMXConnection(getProject(), getUrl(),
getHost(), getPort(), getUsername(), getPassword(), null);
}
return jmxServerConnection;
|
public java.lang.String | getName()The name used at remote MbeanServer
return (this.name);
|
public java.lang.String | getPassword()The login password for the Manager application.
return (this.password);
|
public java.lang.String | getPort()The Port of the JMX JSR 160 MBeanServer to be used.
return (this.port);
|
public java.util.Map | getProperties()get all properties, when project is there got all project Properties
Project currentProject = getProject();
if (currentProject != null) {
return currentProject.getProperties();
} else {
return properties;
}
|
public java.lang.String | getProperty(java.lang.String property)get all Properties
Project currentProject = getProject();
if (currentProject != null) {
return currentProject.getProperty(property);
} else {
return properties.getProperty(property);
}
|
public java.lang.String | getRef()
return ref;
|
public java.lang.String | getResultproperty()
return resultproperty;
|
public java.lang.String | getUnless()
return unlessCondition;
|
public java.lang.String | getUrl()The URL of the JMX JSR 160 MBeanServer to be used.
return (this.url);
|
public java.lang.String | getUsername()The login username for the JMX MBeanServer.
return (this.username);
|
public boolean | isEcho()
return echo;
|
public boolean | isSeparatearrayresults()
return separatearrayresults;
|
public boolean | isUseRef()
return ref != null && !"".equals(ref);
|
public java.lang.String | jmxExecute(javax.management.MBeanServerConnection jmxServerConnection)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.
if ((jmxServerConnection == null)) {
throw new BuildException("Must open a connection!");
} else if (isEcho()) {
handleOutput("JMX Connection ref=" + ref + " is open!");
}
return null;
|
public void | setDelimiter(java.lang.String separator)
this.delimiter = separator;
|
public void | setEcho(boolean echo)
this.echo = echo;
|
public void | setHost(java.lang.String host)
this.host = host;
|
public void | setIf(java.lang.String c)Only execute if a property of the given name exists in the current
project.
ifCondition = c;
|
public void | setName(java.lang.String objectName)
this.name = objectName;
|
public void | setPassword(java.lang.String password)
this.password = password;
|
public void | setPort(java.lang.String port)
this.port = port;
|
public boolean | setProperty(java.lang.String property, java.lang.Object value)
if (property != null) {
if (value == null)
value = "";
if (isEcho()) {
handleOutput(property + "=" + value.toString());
}
Project currentProject = getProject();
if (currentProject != null) {
currentProject.setNewProperty(property, value.toString());
} else {
properties.setProperty(property, value.toString());
}
return true;
}
return false;
|
public void | setRef(java.lang.String refId)
this.ref = refId;
|
public void | setResultproperty(java.lang.String propertyName)
this.resultproperty = propertyName;
|
public void | setSeparatearrayresults(boolean separateArrayResults)
this.separatearrayresults = separateArrayResults;
|
public void | setUnless(java.lang.String c)Only execute if a property of the given name does not exist in the
current project.
unlessCondition = c;
|
public void | setUrl(java.lang.String url)
this.url = url;
|
public void | setUsername(java.lang.String username)
this.username = username;
|
protected boolean | testIfCondition()test the if condition
if (ifCondition == null || "".equals(ifCondition)) {
return true;
}
return getProperty(ifCondition) != null;
|
protected boolean | testUnlessCondition()test the unless condition
if (unlessCondition == null || "".equals(unlessCondition)) {
return true;
}
return getProperty(unlessCondition) == null;
|