i have jmx problems...

J

jill

source code:

package book.jmx.examples;
public class Printer {
public boolean isActive(){
System.out.println("isActive() called ");
return true;
}
}
=============================================================================


package book.jmx.exmaples;
import javax.management.*;
import javax.management.modelmbean.*;

public class ModelExample {
final static boolean READABLE =true;
final static boolean WRITABLE =true;
final static boolean BOOLEAN =true;
public static void main(String [] args){
MBeanServer server = MBeanServerFactory.createMBeanServer();
//build 'RoomName ' read--write attribute
Descriptor descrl =new DescriptorSupport();
descrl.setField("name","Room");
descrl.setField("descriptorType","attrubute");
descrl.setField("displayName","Room Number");
descrl.setField("default","D325");
ModelMBeanAttributeInfo roomNameInfo =
new ModelMBeanAttributeInfo(
"Room", //attribute name
String.class.getName(), //attribute type
"Room name or number.", //description
READABLE,WRITABLE,!BOOLEAN, //read write
descrl //descriptor
);

//build 'Active ' read--only attribute
Descriptor descr2 =new DescriptorSupport();
descr2.setField("name","Active");
descr2.setField("descriptorType","attribute");
descr2.setField("getMethod","isActive");
descr2.setField("currencyTimeLimit","10");
ModelMBeanAttributeInfo activeInfo =
new ModelMBeanAttributeInfo(
"Active",
boolean.class.getName(),
"Printer state.",
READABLE,!WRITABLE,!BOOLEAN,
descr2
);
//build 'isActive ' getter operation
Descriptor descr3 =new DescriptorSupport();
descr3.setField("name","isActive");
descr3.setField("descriptorType","operation");
descr3.setField("role","getter");
ModelMBeanOperationInfo isActiveInfo =
new ModelMBeanOperationInfo(
"isActive", //name &description
"Checks if the printer is currently active.",
null, //signature
boolean.class.getName(), //return type
MBeanOperationInfo.INFO, //impact
descr3 //descriptor
);
//MBean descriptor
Descriptor descr4 =new DescriptorSupport();
descr4.setField("name","Printer");
descr4.setField("descriptorType","mbean");
//create ModelMBeanInfo
ModelMBeanInfo info =new ModelMBeanInfoSupport(
RequiredModelMBean.class.getName(), //class name
"Printer", //description
new ModelMBeanAttributeInfo [] { //attributes
roomNameInfo,
activeInfo
},
null, //constructors
new ModelMBeanOperationInfo [] { //operations
isActiveInfo
},
null, //notifications
descr4 //descriptor
);
try {
//create and configure model mbean
RequiredModelMBean model =new RequiredModelMBean();
model.setManagedResource(new Printer(),"ObjectReference");
model.setModelMBeanInfo(info);
server.registerMBean(model,new ObjectName("example:name=model"));

//create the adaptor

com.sun.jdmk.comm.HtmlAdaptorServer adaptor=new com.sun.jdmk.comm.HtmlAdap
torServer();

//register the adaptor MBean to the agent
server.registerMBean(adaptor,new ObjectName("adaptor:protocol=HTTP"));

//start the adaptor
adaptor.start();

}
catch (Exception e){
e.printStackTrace();
}
}
}
============================================================================
when i type javac ModelMBean.java ==>ok
then i type java ModelMBean ==>i get

C:\examples>java ModelExample
Exception in thread "main" javax.management.RuntimeOperationsException: Exceptio
n occured in ModelMBeanAttributeInfo constructor
at javax.management.modelmbean.ModelMBeanAttributeInfo.<init>(ModelMBean
AttributeInfo.java:291)
at ModelExample.main(ModelExample.java:17)

============================================================================
how could i solve it ?
thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,991
Messages
2,570,212
Members
46,800
Latest member
Tobi1987

Latest Threads

Top