ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/catalina/ant/jmx/JMXAccessorCondition.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/catalina/ant/jmx/JMXAccessorCondition.java
Status
scanned
Type
file
Name
JMXAccessorCondition.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
8222 (8.0 KB)
MD5
0ef86738e24d6f070b1729e202fe9ad0
SHA1
18f374c25619161c3eb33558a38725e2f54bb3a5
SHA256
9f1d30e3acb1307a934100d171ab80f7e76c9f140d3ee9fed9d219ac414083b9
SHA512

      
    
SHA1_git
12090c0d167dfd6b69b1bb0d89034199871cf82b
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
JMXAccessorCondition.java | 8.0 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.ant.jmx; import org.apache.tools.ant.BuildException; /** * <b>Definition</b>: * * <pre> * &lt;path id="catalina_ant"&gt; * &lt;fileset dir="${catalina.home}/server/lib"&gt; * &lt;include name="catalina-ant.jar"/&gt; * &lt;/fileset&gt; * &lt;/path&gt; * * &lt;typedef * name="jmxCondition" * classname="org.apache.catalina.ant.jmx.JMXAccessorCondition" * classpathref="catalina_ant"/&gt; * &lt;taskdef * name="jmxOpen" * classname="org.apache.catalina.ant.jmx.JMXAccessorTask" * classpathref="catalina_ant"/&gt; * </pre> * * <b>Usage</b>: Wait for start backup node * * <pre> * &lt;target name="wait"&gt; * &lt;jmxOpen * host="${jmx.host}" port="${jmx.port}" username="${jmx.username}" password="${jmx.password}" /&gt; * &lt;waitfor maxwait="${maxwait}" maxwaitunit="second" timeoutproperty="server.timeout" &gt; * &lt;and&gt; * &lt;socket server="${server.name}" port="${server.port}"/&gt; * &lt;http url="${url}"/&gt; * &lt;jmxCondition * name="Catalina:type=IDataSender,host=localhost,senderAddress=192.168.111.1,senderPort=9025" * operation="==" * attribute="connected" value="true" * /&gt; * &lt;jmxCondition * operation="&amp;lt;" * name="Catalina:j2eeType=WebModule,name=//${tomcat.application.host}${tomcat.application.path},J2EEApplication=none,J2EEServer=none" * attribute="startupTime" value="250" * /&gt; * &lt;/and&gt; * &lt;/waitfor&gt; * &lt;fail if="server.timeout" message="Server ${url} don't answer inside ${maxwait} sec" /&gt; * &lt;echo message="Server ${url} alive" /&gt; * &lt;/target&gt; * </pre> * * Allowed operation between jmx attribute and reference value: * <ul> * <li>== equals</li> * <li>!= not equals</li> * <li>&gt; greater than (&amp;gt;)</li> * <li>&gt;= greater than or equals (&amp;gt;=)</li> * <li>&lt; lesser than (&amp;lt;)</li> * <li>&lt;= lesser than or equals (&amp;lt;=)</li> * </ul> * <b>NOTE</b>: For numeric expressions the type must be set and use xml entities as operations.<br> * As type we currently support <em>long</em> and <em>double</em>. * * @since 5.5.10 */ public class JMXAccessorCondition extends JMXAccessorConditionBase { // ----------------------------------------------------- Instance Variables private String operation = "=="; private String type = "long"; private String unlessCondition; private String ifCondition; // ----------------------------------------------------- Properties /** * @return Returns the operation. */ public String getOperation() { return operation; } /** * @param operation The operation to set. */ public void setOperation(String operation) { this.operation = operation; } /** * @return Returns the type. */ public String getType() { return type; } /** * @param type The type to set. */ public void setType(String type) { this.type = type; } /** * @return Returns the ifCondition. */ public String getIf() { return ifCondition; } /** * Only execute 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 execute 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; } /** * test the if condition * * @return true if there is no if condition, or the named property exists */ protected boolean testIfCondition() { if (ifCondition == null || ifCondition.isEmpty()) { 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 || unlessCondition.isEmpty()) { return true; } return getProject().getProperty(unlessCondition) == null; } /** * This method evaluates the condition It support for operation "&gt;,&gt;=,&lt;,&lt;=" the types <code>long</code> * and <code>double</code>. * * @return expression <em>jmxValue</em> <em>operation</em> <em>value</em> */ @Override public boolean eval() { String value = getValue(); if (operation == null) { throw new BuildException("operation attribute is not set"); } if (value == null) { throw new BuildException("value attribute is not set"); } if ((getName() == null || getAttribute() == null)) { throw new BuildException("Must specify an MBean name and attribute for 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; } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
16.55
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9