aspose file tools*
The moose likes JBoss/WildFly and the fly likes another jmx/jboss question - abt dynamic mbeans and accessing properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "another jmx/jboss question - abt dynamic mbeans and accessing properties file" Watch "another jmx/jboss question - abt dynamic mbeans and accessing properties file" New topic
Author

another jmx/jboss question - abt dynamic mbeans and accessing properties file

Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
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


"In theory, there is no difference between theory and practice. But, in practice, there is."<br /> - Jan L.A. van de Snepscheut
jithz jitthzn
Greenhorn

Joined: May 15, 2012
Posts: 1
Hi Prasanth,

ive been trying to load the properties in the jboss conf folder via dynamic mbean and was unsuccessfull. Looks like it has been quite a while since you posted in this thread , have you come across a work around for this problem ?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

"jithz jitthzn" please see your private messages regarding an important administrative matter.

Also, see this: TellTheDetails
It would help if you posted information about your properties and the code you are using to access them. Then we don't have to guess about what you might be doing wrong but can instead offer concrete advice.


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: another jmx/jboss question - abt dynamic mbeans and accessing properties file