Как получить Mbean с сервера JMX


Привет я пытаюсь получить Mbean уже зарегистрирован в MbeanServer и пытается вызвать метод и получить IllegalArgumentException: тип аргумента несоответствие не уверен, почему . Любая помощь будет высоко оценена

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 
//ObjectName name = new ObjectName("org.ihc.perf.monitor:type=HelloWorld");
ObjectName name = new ObjectName(beanName);
if (mbs.isRegistered(name)) {
        PerfMonitorMBean mbean =
           (PerfMonitorMBean)MBeanServerInvocationHandler.newProxyInstance(
                mbs,name,PerfMonitorMBean.class,true);
        perfMonHash.put(beanName, mbean);
        return;
}
PerfMonitor mbean = new PerfMonitor();
//PerfMonitor mbean = new PerfMonitor();
mbs.registerMBean(mbean, name);
perfMonHash.put(beanName, mbean);
//isMBeanRegistered = true;

И когда я пытаюсь получить доступ к методу на Mbean, используя

perfMonHash.get(Constants.JMXMBEANNAME).addServiceData(serviceData);

Я получаю:

java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:111)
    at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:45)
    at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:235)
    at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:138)
    at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:250)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:791)
    at javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:305)
    at $Proxy244.addServiceData(Unknown Source)
    at org.ihc.esm.service.publisher.JmxNotificationPublisher.notifyListeners(JmxNotificationPublisher.java:22)
    at org.ihc.esm.service.model.EnterpriseServiceMonitoringModel.notifyStats(EnterpriseServiceMonitoringModel.java:34)
    at org.ihc.esm.service.impl.EnterpriseServiceMonitoringServiceImpl.runtimeStatistic(EnterpriseServiceMonitoringServiceImpl.java:36)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:173)
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:89)
    at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:64)
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:75)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:123)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:193)
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:128)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:108)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:751)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:164)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:216)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:132)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:338)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:221)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3284)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3254)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
    at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2163)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2089)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2074)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1513)
    at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)

Моя реализация Mbean:

public class PerfMonitor extends NotificationBroadcasterSupport implements PerfMonitorMBean {

    private static final Logger logger = LoggerFactory.getLogger(PerfMonitor.class);
    private long sequenceNumber = 1;

    private ConcurrentHashMap<String, ServiceData> perfData=new ConcurrentHashMap<String, ServiceData>();



    public ConcurrentHashMap<String, ServiceData> getPerfData() {
        return perfData;
    }

    public void setPerfData(ConcurrentHashMap<String, ServiceData> perfData) {
        this.perfData = perfData;
    }

    public ServiceData getServiceData(String key){
    return perfData.get(key);
    }

    public void addServiceData(ServiceData serviceData){
    if(serviceData.getServiceName()!=null){
    String key=(serviceData.getServiceName()+"_"+serviceData.getRuntimeEnv()).toLowerCase().trim();
    logger.debug("Adding data for key:{}",key);
    perfData.put(key, serviceData);
    Notification n = new AttributeChangeNotification(this,
        sequenceNumber++, System.currentTimeMillis(),
        "ServiceData got added", "serviceData", "ServiceData",
        null, null);
    n.setUserData(serviceData);
    logger.debug("Sending Notification...");
    sendNotification(n);
    }
    }

//    private  ServiceData serviceData;
//
//    public ServiceData getServiceData() {
//  return serviceData;
//    }
//
//    public void setServiceData(ServiceData serviceData) {
//  this.serviceData=serviceData;
//  Notification n = new AttributeChangeNotification(this,
//      sequenceNumber++, System.currentTimeMillis(),
//      "ServiceData got added", "serviceData", "ServiceData",
//      null, null);
//  n.setUserData(serviceData);
//  sendNotification(n);
//    }

    //private static PerfMonitor mbean = new PerfMonitor();


    // private static boolean isMBeanRegistered = false;



    @Override
    public MBeanNotificationInfo[] getNotificationInfo() {
    String[] types = new String[]{
        AttributeChangeNotification.ATTRIBUTE_CHANGE
    };

    String name = AttributeChangeNotification.class.getName();
    String description = "An attribute of this MBean has changed";
    MBeanNotificationInfo info = 
        new MBeanNotificationInfo(types, name, description);
    return new MBeanNotificationInfo[]{info};
    }





}

Класс ServiceData:

Импортировать Java.Ио.Сериализуемый; импорт java.математика.BigDecimal;

public class ServiceData implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private String runtimeEnv;
    private String applicationID;
    private String serviceName; // ~ Endpoint
    private String userID;
    private String guid;
    private String requestPayload;
    private String responsePayload;
    private BigDecimal requestTime;
    private BigDecimal responseTime;

    public String getRuntimeEnv() {
        return runtimeEnv;
    }
    public void setRuntimeEnv(String runtimeEnv) {
        this.runtimeEnv = runtimeEnv;
    }
    public String getApplicationID() {
        return applicationID;
    }
    public void setApplicationID(String applicationID) {
        this.applicationID = applicationID;
    }
    public String getServiceName() {
        return serviceName;
    }
    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }
    public String getUserID() {
        return userID;
    }
    public void setUserID(String userID) {
        this.userID = userID;
    }
    public String getGuid() {
        return guid;
    }
    public void setGuid(String guid) {
        this.guid = guid;
    }
    public String getRequestPayload() {
        return requestPayload;
    }
    public void setRequestPayload(String requestPayload) {
        this.requestPayload = requestPayload;
    }
    public String getResponsePayload() {
        return responsePayload;
    }
    public void setResponsePayload(String responsePayload) {
        this.responsePayload = responsePayload;
    }
    public BigDecimal getRequestTime() {
        return requestTime;
    }
    public void setRequestTime(BigDecimal requestTime) {
        this.requestTime = requestTime;
    }
    public BigDecimal getResponseTime() {
        return responseTime;
    }
    public void setResponseTime(BigDecimal responseTime) {
        this.responseTime = responseTime;
    }




}
1 3

1 ответ:

Вместо использования :

if (mbs.isRegistered(name)) {
        PerfMonitorMBean mbean =
           (PerfMonitorMBean)MBeanServerInvocationHandler.newProxyInstance(
                mbs,name,PerfMonitorMBean.class,true);
        perfMonHash.put(beanName, mbean);
        return;
}

Использование:

if (mbs.isRegistered(name)) {
        PerfMonitorMBean mbean =null;
        port=System.getProperty("com.sun.management.jmxremote.port");
            JMXServiceURL url =
                    new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:"+port+"/jmxrmi");
                JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
                MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
                mbean = JMX.newMBeanProxy(mbsc, name, PerfMonitorMBean.class, true);


        perfMonHash.put(beanName, mbean);

        return;

        }