Hi All,
getting past a new hurdle in jmx and coming across a new one - every day...but this one seems to be something that I am doing wrong...
I have a class which implements the dynamic mbean interface and I need it to access a properties file and make changes to the attributes in the properties file.
A sample code is given below:
public class ADMWPPropertyManager implements DynamicMBean {
private final
String propertyFileName;
private final Properties properties;
public ADMWPPropertyManager(String propertyFileName) throws IOException {
this.propertyFileName = propertyFileName;
properties = new Properties();
load();
}
public synchronized String getAttribute(String name)
throws AttributeNotFoundException {
String value = properties.getProperty(name);
if (value != null)
return value;
else
throw new AttributeNotFoundException("No such property: " + name);
}
//setAttribute(), setAttributes() and getAttributes() are implemented as well�
public synchronized MBeanInfo getMBeanInfo() {
SortedSet<String> names = new TreeSet<String>();
for (Object name : properties.keySet())
names.add((String) 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",
"Property " + name,
true, // isReadable
true, // isWritable
false); // isIs
}
MBeanOperationInfo[] opers = {
new MBeanOperationInfo(
"reload",
"Reload properties from file",
null, // no parameters
"void",
MBeanOperationInfo.ACTION)
};
return new MBeanInfo(
this.getClass().getName(),
"Property Manager MBean",
attrs,
null, // constructors
opers,
null); // notifications
}
}
I expect the code above to get a properties file from my system on start of the
JBoss app server and I would like to make modifications to the properties file at runtime�.
The jboss-service.xml is given as follows:
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="com.altair.adm.webportal.jmx.Startup" name="ZADMPortal:service=Startup">
</mbean>
<mbean code="com.altair.adm.webportal.jmx.ADMWPPropertyManager" name="ZADMPortal:service=ADMWPPropertyManager">
<attribute name="propertyFileName">C:\\temp\\wpParams.txt</attribute>
</mbean>
</server>
The �Startup� bean works fine�which implements a simple MBean interface�
However when the above dynamic bean is invoked�it gives the following exception�
org.jboss.deployment.DeploymentException: com.altair.adm.webportal.jmx.ADMWPPropertyManager.<init>(); - nested throwable: (java.lang.NoSuchMethodException: com.altair.adm.webportal.jmx.ADMWPPropertyManager.<init>())
I expect it to invoke the constructor with the propertyFileName...but it tries to initialize an default one?
am confused...
Thanks
Preetham