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

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

      
    
Rootfs path

      
    
Size
5835 (5.7 KB)
MD5
d0630a36263a326adf87254b02a53746
SHA1
ae2ae4766e4eb8fea9db17326319f8094425e1e5
SHA256
6d5e49f53513a8cdf9d181c8fccef44a4868b6ee7c2d64e93d381fbab0a14343
SHA512

      
    
SHA1_git
471a328f5dd87e9b688de28ba3543f5252406e74
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
JMXAccessorSetTask.java | 5.7 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 javax.management.Attribute; import javax.management.MBeanAttributeInfo; import javax.management.MBeanInfo; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import org.apache.tools.ant.BuildException; /** * Access <em>JMX</em> JSR 160 MBeans Server. * <ul> * <li>Get Mbeans attributes</li> * <li>Show Get result as Ant console log</li> * <li>Bind Get result as Ant properties</li> * </ul> * <p> * Examples: Set a Mbean Manager attribute maxActiveSessions. Set this attribute with fresh jmx connection without save * reference * </p> * * <pre> * &lt;jmx:set * host="127.0.0.1" * port="9014" * ref="" * name="Catalina:type=Manager,context="/ClusterTest",host=localhost" * attribute="maxActiveSessions" * value="100" * type="int" * echo="false"&gt; * /&gt; * </pre> * <p> * First call to a remote MBean server save the JMXConnection a reference <em>jmx.server</em> * </p> * These tasks require Ant 1.6 or later interface. * * @since 5.5.10 */ public class JMXAccessorSetTask extends JMXAccessorTask { // ----------------------------------------------------- Instance Variables private String attribute; private String value; private String type; private boolean convert = false; // ------------------------------------------------------------- Properties /** * @return Returns the attribute. */ public String getAttribute() { return attribute; } /** * @param attribute The attribute to set. */ public void setAttribute(String attribute) { this.attribute = attribute; } /** * @return Returns the value. */ public String getValue() { return value; } /** * @param value The value to set. */ public void setValue(String value) { this.value = value; } /** * @return Returns the type. */ public String getType() { return type; } /** * @param valueType The type to set. */ public void setType(String valueType) { this.type = valueType; } /** * @return Returns the convert. */ public boolean isConvert() { return convert; } /** * @param convert The convert to set. */ public void setConvert(boolean convert) { this.convert = convert; } // ------------------------------------------------------ protected Methods @Override public String jmxExecute(MBeanServerConnection jmxServerConnection) throws Exception { if (getName() == null) { throw new BuildException("Must specify a 'name'"); } if ((attribute == null || value == null)) { throw new BuildException("Must specify a 'attribute' and 'value' for set"); } return jmxSet(jmxServerConnection, getName()); } /** * Set property value. * * @param jmxServerConnection Connection to the JMX server * @param name The MBean name * * @return null (no error message to report other than exception) * * @throws Exception An error occurred */ protected String jmxSet(MBeanServerConnection jmxServerConnection, String name) throws Exception { Object realValue; if (type != null) { realValue = convertStringToType(value, type); } else { if (isConvert()) { String mType = getMBeanAttributeType(jmxServerConnection, name, attribute); realValue = convertStringToType(value, mType); } else { realValue = value; } } jmxServerConnection.setAttribute(new ObjectName(name), new Attribute(attribute, realValue)); return null; } /** * Get MBean Attribute from Mbean Server * * @param jmxServerConnection The JMX connection name * @param name The MBean name * @param attribute The attribute name * * @return The type of the attribute * * @throws Exception An error occurred */ protected String getMBeanAttributeType(MBeanServerConnection jmxServerConnection, String name, String attribute) throws Exception { ObjectName oname = new ObjectName(name); String mattrType = null; MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname); MBeanAttributeInfo[] attrs = minfo.getAttributes(); for (int i = 0; mattrType == null && i < attrs.length; i++) { if (attribute.equals(attrs[i].getName())) { mattrType = attrs[i].getType(); } } return mattrType; } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
21.76
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