mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
1) make JMX port configuration in deverloper build, 2) Add property map based dynamic bean
This commit is contained in:
parent
5129df106b
commit
a5c21dc130
@ -20,6 +20,10 @@
|
|||||||
<property name="unittest.dir" location="${base.dir}/unittest"/>
|
<property name="unittest.dir" location="${base.dir}/unittest"/>
|
||||||
<property name="unittest.target.dir" location="${unittest.dir}/classes"/>
|
<property name="unittest.target.dir" location="${unittest.dir}/classes"/>
|
||||||
<property name="unittest.jar.dir" location="${unittest.dir}/jar"/>
|
<property name="unittest.jar.dir" location="${unittest.dir}/jar"/>
|
||||||
|
|
||||||
|
<condition property="jmxport" value="${jmxport.override}" else="45219">
|
||||||
|
<isset property="jmxport.override" />
|
||||||
|
</condition>
|
||||||
|
|
||||||
<macrodef name="compile-test">
|
<macrodef name="compile-test">
|
||||||
<attribute name="top.dir" description="Top Directory of the source. We will add src to this to get the source code."/>
|
<attribute name="top.dir" description="Top Directory of the source. We will add src to this to get the source code."/>
|
||||||
@ -69,7 +73,7 @@
|
|||||||
<target name="debug-suspend">
|
<target name="debug-suspend">
|
||||||
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
|
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
|
||||||
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
|
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
|
||||||
<jvmarg value="-Dcom.sun.management.jmxremote.port=20400"/>
|
<jvmarg value="-Dcom.sun.management.jmxremote.port=${jmxport}"/>
|
||||||
<jvmarg value="-Dcom.sun.management.jmxremote.authenticate=false"/>
|
<jvmarg value="-Dcom.sun.management.jmxremote.authenticate=false"/>
|
||||||
<jvmarg value="-Dcom.sun.management.jmxremote.ssl=false"/>
|
<jvmarg value="-Dcom.sun.management.jmxremote.ssl=false"/>
|
||||||
<jvmarg value="-Xdebug"/>
|
<jvmarg value="-Xdebug"/>
|
||||||
@ -90,7 +94,7 @@
|
|||||||
<echo message="Start Tomcat" />
|
<echo message="Start Tomcat" />
|
||||||
<java dir="${tomcat.home}/bin/" jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
|
<java dir="${tomcat.home}/bin/" jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
|
||||||
<jvmarg value="${assertion}"/>
|
<jvmarg value="${assertion}"/>
|
||||||
<jvmarg value="-Dcom.sun.management.jmxremote.port=20400"/>
|
<jvmarg value="-Dcom.sun.management.jmxremote.port=${jmxport}"/>
|
||||||
<jvmarg value="-Dcom.sun.management.jmxremote.authenticate=false"/>
|
<jvmarg value="-Dcom.sun.management.jmxremote.authenticate=false"/>
|
||||||
<jvmarg value="-Dcom.sun.management.jmxremote.ssl=false"/>
|
<jvmarg value="-Dcom.sun.management.jmxremote.ssl=false"/>
|
||||||
<jvmarg value="-Xms256m"/>
|
<jvmarg value="-Xms256m"/>
|
||||||
@ -103,7 +107,7 @@
|
|||||||
<target name="debug-tomcat">
|
<target name="debug-tomcat">
|
||||||
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
|
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
|
||||||
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
|
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
|
||||||
<jvmarg value="-Dcom.sun.management.jmxremote.port=20400"/>
|
<jvmarg value="-Dcom.sun.management.jmxremote.port=${jmxport}"/>
|
||||||
<jvmarg value="-Dcom.sun.management.jmxremote.authenticate=false"/>
|
<jvmarg value="-Dcom.sun.management.jmxremote.authenticate=false"/>
|
||||||
<jvmarg value="-Dcom.sun.management.jmxremote.ssl=false"/>
|
<jvmarg value="-Dcom.sun.management.jmxremote.ssl=false"/>
|
||||||
<jvmarg value="-Xdebug"/>
|
<jvmarg value="-Xdebug"/>
|
||||||
|
|||||||
111
utils/src/com/cloud/utils/mgmt/PropertyMapDynamicBean.java
Normal file
111
utils/src/com/cloud/utils/mgmt/PropertyMapDynamicBean.java
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
package com.cloud.utils.mgmt;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import javax.management.Attribute;
|
||||||
|
import javax.management.AttributeList;
|
||||||
|
import javax.management.AttributeNotFoundException;
|
||||||
|
import javax.management.DynamicMBean;
|
||||||
|
import javax.management.InvalidAttributeValueException;
|
||||||
|
import javax.management.MBeanAttributeInfo;
|
||||||
|
import javax.management.MBeanException;
|
||||||
|
import javax.management.MBeanInfo;
|
||||||
|
import javax.management.ReflectionException;
|
||||||
|
|
||||||
|
public class PropertyMapDynamicBean implements DynamicMBean {
|
||||||
|
|
||||||
|
private Map<String, Object> _propMap = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
public PropertyMapDynamicBean() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public PropertyMapDynamicBean(Map<String, Object> propMap) {
|
||||||
|
_propMap = propMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
|
||||||
|
if(_propMap != null) {
|
||||||
|
return _propMap.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new AttributeNotFoundException("No such property " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized AttributeList getAttributes(String[] names) {
|
||||||
|
AttributeList list = new AttributeList();
|
||||||
|
for (String name : names) {
|
||||||
|
Object value = _propMap.get(name);
|
||||||
|
if (value != null)
|
||||||
|
list.add(new Attribute(name, value));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized MBeanInfo getMBeanInfo() {
|
||||||
|
SortedSet<String> names = new TreeSet<String>();
|
||||||
|
|
||||||
|
for (String name : _propMap.keySet())
|
||||||
|
names.add(name);
|
||||||
|
|
||||||
|
MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[names.size()];
|
||||||
|
Iterator<String> it = names.iterator();
|
||||||
|
for (int i = 0; i < attrs.length; i++) {
|
||||||
|
String name = it.next();
|
||||||
|
attrs[i] = new MBeanAttributeInfo(
|
||||||
|
name,
|
||||||
|
"java.lang.String",
|
||||||
|
name,
|
||||||
|
true, // isReadable
|
||||||
|
true, // isWritable
|
||||||
|
false); // isIs
|
||||||
|
}
|
||||||
|
|
||||||
|
return new MBeanInfo(
|
||||||
|
this.getClass().getName(),
|
||||||
|
"Dynamic MBean",
|
||||||
|
attrs,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized Object invoke(String name, Object[] args, String[] sig) throws MBeanException, ReflectionException {
|
||||||
|
throw new ReflectionException(new NoSuchMethodException(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void setAttribute(Attribute attr) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
|
||||||
|
String name = attr.getName();
|
||||||
|
if(name != null)
|
||||||
|
_propMap.put(name, attr.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized AttributeList setAttributes(AttributeList list) {
|
||||||
|
Attribute[] attrs = (Attribute[]) list.toArray(new Attribute[0]);
|
||||||
|
AttributeList retList = new AttributeList();
|
||||||
|
for (Attribute attr : attrs) {
|
||||||
|
String name = attr.getName();
|
||||||
|
Object value = attr.getValue();
|
||||||
|
_propMap.put(name, value);
|
||||||
|
retList.add(new Attribute(name, value));
|
||||||
|
}
|
||||||
|
return retList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void addProp(String name, Object value) {
|
||||||
|
_propMap.put(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized Object getProp(String name) {
|
||||||
|
return _propMap.get(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user