: For numeric expressions the type must be set and use xml entities as operations.
.
| Method from org.apache.catalina.ant.jmx.JMXAccessorCondition Detail: |
protected String accessJMXValue() {
try {
Object result = getJMXConnection().getAttribute(
new ObjectName(name), attribute);
if(result != null)
return result.toString();
} catch (Exception e) {
// ignore access or connection open errors
}
return null;
}
Get value from MBeans attribute |
public boolean eval() {
if (operation == null) {
throw new BuildException("operation attribute is not set");
}
if (value == null) {
throw new BuildException("value attribute is not set");
}
if ((name == null || attribute == null)) {
throw new BuildException(
"Must specify a 'attribute', name for equals condition");
}
if (testIfCondition() && testUnlessCondition()) {
String jmxValue = accessJMXValue();
if (jmxValue != null) {
String op = getOperation();
if ("==".equals(op)) {
return jmxValue.equals(value);
} else if ("!=".equals(op)) {
return !jmxValue.equals(value);
} else {
if ("long".equals(type)) {
long jvalue = Long.parseLong(jmxValue);
long lvalue = Long.parseLong(value);
if (" >".equals(op)) {
return jvalue > lvalue;
} else if (" >=".equals(op)) {
return jvalue >= lvalue;
} else if ("< ".equals(op)) {
return jvalue < lvalue;
} else if ("< =".equals(op)) {
return jvalue < = lvalue;
}
} else if ("double".equals(type)) {
double jvalue = Double.parseDouble(jmxValue);
double dvalue = Double.parseDouble(value);
if (" >".equals(op)) {
return jvalue > dvalue;
} else if (" >=".equals(op)) {
return jvalue >= dvalue;
} else if ("< ".equals(op)) {
return jvalue < dvalue;
} else if ("< =".equals(op)) {
return jvalue < = dvalue;
}
}
}
}
return false;
}
return true;
}
This method evaluates the condition
It support for operation ">,>=,<,<=" the types long and double. |
public String getAttribute() {
return attribute;
}
|
public String getHost() {
return host;
}
|
public String getIf() {
return ifCondition;
}
|
public String getInfo() {
return (info);
}
Return descriptive information about this implementation and the
corresponding version number, in the format
<description>/<version>. |
protected MBeanServerConnection getJMXConnection() throws MalformedURLException, IOException {
return JMXAccessorTask.accessJMXConnection(
getProject(),
getUrl(), getHost(),
getPort(), getUsername(), getPassword(), ref);
}
Get JMXConnection (default look at jmx.server project reference from jmxOpen Task) |
public String getName() {
return name;
}
|
public String getOperation() {
return operation;
}
|
public String getPassword() {
return password;
}
|
public String getPort() {
return port;
}
|
public String getRef() {
return ref;
}
|
public String getType() {
return type;
}
|
public String getUnless() {
return unlessCondition;
}
|
public String getUrl() {
return url;
}
|
public String getUsername() {
return username;
}
|
public String getValue() {
return value;
}
|
public void setAttribute(String attribute) {
this.attribute = attribute;
}
|
public void setHost(String host) {
this.host = host;
}
|
public void setIf(String c) {
ifCondition = c;
}
Only execute if a property of the given name exists in the current project. |
public void setName(String objectName) {
this.name = objectName;
}
|
public void setOperation(String operation) {
this.operation = operation;
}
|
public void setPassword(String password) {
this.password = password;
}
|
public void setPort(String port) {
this.port = port;
}
|
public void setRef(String refId) {
this.ref = refId;
}
|
public void setType(String type) {
this.type = type;
}
|
public void setUnless(String c) {
unlessCondition = c;
}
Only execute if a property of the given name does not
exist in the current project. |
public void setUrl(String url) {
this.url = url;
}
|
public void setUsername(String username) {
this.username = username;
}
|
public void setValue(String value) {
this.value = value;
}
|
protected boolean testIfCondition() {
if (ifCondition == null || "".equals(ifCondition)) {
return true;
}
return getProject().getProperty(ifCondition) != null;
}
|
protected boolean testUnlessCondition() {
if (unlessCondition == null || "".equals(unlessCondition)) {
return true;
}
return getProject().getProperty(unlessCondition) == null;
}
test the unless condition |