pero 2005/07/01 04:46:51
Modified: catalina/src/share/org/apache/catalina/ant/jmx
JMXAccessorCondition.java JMXAccessorTask.java
Log:
Add if and unless
Fix docs
Revision Changes Path
1.2 +103 -37
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorCondition.java
Index: JMXAccessorCondition.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorCondition.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JMXAccessorCondition.java 30 Jun 2005 13:01:27 -0000 1.1
+++ JMXAccessorCondition.java 1 Jul 2005 11:46:51 -0000 1.2
@@ -88,7 +88,9 @@
private String operation = "==" ;
private String type = "long" ;
private String ref = "jmx.server";
-
+ private String unlessCondition;
+ private String ifCondition;
+
// ----------------------------------------------------- Instance Info
/**
@@ -240,7 +242,41 @@
public void setRef(String refId) {
this.ref = refId;
}
-
+ /**
+ * @return Returns the ifCondition.
+ */
+ public String getIf() {
+ return ifCondition;
+ }
+ /**
+ * Only fail if a property of the given name exists in the current
project.
+ * @param c property name
+ */
+ public void setIf(String c) {
+ ifCondition = c;
+ }
+ /**
+ * @return Returns the unlessCondition.
+ */
+ public String getUnless() {
+ return unlessCondition;
+ }
+
+ /**
+ * Only fail if a property of the given name does not
+ * exist in the current project.
+ * @param c property name
+ */
+ public void setUnless(String c) {
+ unlessCondition = c;
+ }
+
+ /**
+ * Get JMXConnection (default look at <em>jmx.server</em> project
reference from jmxOpen Task)
+ * @return active JMXConnection
+ * @throws MalformedURLException
+ * @throws IOException
+ */
protected MBeanServerConnection getJMXConnection()
throws MalformedURLException, IOException {
return JMXAccessorTask.accessJMXConnection(
@@ -250,6 +286,7 @@
}
/**
+ * Get value from MBeans attribute
* @return
*/
protected String accessJMXValue() {
@@ -264,7 +301,34 @@
return null;
}
- // This method evaluates the condition
+ /**
+ * test the if condition
+ * @return true if there is no if condition, or the named property exists
+ */
+ protected boolean testIfCondition() {
+ if (ifCondition == null || "".equals(ifCondition)) {
+ return true;
+ }
+ return getProject().getProperty(ifCondition) != null;
+ }
+
+ /**
+ * test the unless condition
+ * @return true if there is no unless condition,
+ * or there is a named property but it doesn't exist
+ */
+ protected boolean testUnlessCondition() {
+ if (unlessCondition == null || "".equals(unlessCondition)) {
+ return true;
+ }
+ return getProject().getProperty(unlessCondition) == null;
+ }
+
+ /**
+ * This method evaluates the condition
+ * It support for operation ">,>=,<,<=" the types <code>long</code> and
<code>double</code>.
+ * @return expression <em>jmxValue</em> <em>operation</em> <em>value</em>
+ */
public boolean eval() {
if (operation == null) {
throw new BuildException("operation attribute is not set");
@@ -276,43 +340,45 @@
throw new BuildException(
"Must specify a 'attribute', name for equals condition");
}
- //FIXME check url or host/parameter
- String jmxValue = accessJMXValue();
- String op = getOperation() ;
- if(jmxValue != null) {
- 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;
+ 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 false;
+ return true;
}
}
1.3 +1 -7
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorTask.java
Index: JMXAccessorTask.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorTask.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JMXAccessorTask.java 30 Jun 2005 13:01:27 -0000 1.2
+++ JMXAccessorTask.java 1 Jul 2005 11:46:51 -0000 1.3
@@ -285,12 +285,6 @@
public String getUnless() {
return unlessCondition;
}
- /**
- * @param unlessCondition The unlessCondition to set.
- */
- public void setUnlessCondition(String unlessCondition) {
- this.unlessCondition = unlessCondition;
- }
/**
* Only fail if a property of the given name does not
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]