Reputation: 13585
I am trying to register a bean on JMX. I am getting error on line mbs.registerMBean(metadataObj, name);
. Error says
Multiple markers at this line
- Syntax error on token "(", delete
this token
- Syntax error on token ")", delete
this token
I have no idea what it is about.
This bean has basic metadata about request start/end time. Class
package test.performance;
public class RequestPerformanceMetadata implements PerformanceMetadataMBean{
private double startTime;
private double endTime;
private double timeTook;
private String requestType;
private int numOfRequests;
PerformanceMetadataMBean metadataObj = new RequestPerformanceMetadata();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("test.performace:type=PerformanceMetadataMBean");
mbs.registerMBean(metadataObj, name);
public double getTimeTook() {
return timeTook;
}
public void setTimeTook(double timeTook) {
this.timeTook = timeTook;
}
Interface
package test.performance;
public interface PerformanceMetadataMBean {
double getTimeTook();
void setTimeTook(double timeTook);
String getRequestType();
void setRequestType(String requestType);
On
Upvotes: 0
Views: 101
Reputation: 16066
There's a lot of issues here.
Starting with msb = ...., there's no method.... it needs to be in a method. Next, new ObjectName(...) throws an exception, so you need to wrap it in a try/catch block. Also, are you sure you want to create another instance of RequestPerformanceMetadata inside of RequestPerformanceMetadata ? Perhaps you want to simply register the this instance.
Take a look at this code fragment:
class RequestPerformanceMetadata implements PerformanceMetadataMBean {
private double startTime;
private double endTime;
private double timeTook;
private String requestType;
private int numOfRequests;
private MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
private ObjectName name;
public RequestPerformanceMetadata() {
try {
name = new ObjectName("test.performace:type=PerformanceMetadataMBean");
mbs.registerMBean(this, name);
} catch (Exception ex) {
throw new RuntimeException("Yo dog. Bad object name", ex);
}
}
//........... snip ...........
}
Upvotes: 1