1 Reply Latest reply on Sep 16, 2005 11:13 AM by George Taylor

    Dynamic registration of mbeans

    George Taylor Newbie

      I have some code i am testing for a future application that needs to instantiate new instances of an mbeans and register them with the server.

      my test code runs up the mbean ok, but as soon as i put the registration code to add a new instance to the server it failes.

      Does anyone know what i am doing wrong ????


      Interface:

      package com.flytxt.transport.jmx;
      import org.jboss.annotation.ejb.Management;
      @Management
      public interface TransportServer extends org.jboss.system.Service{
       public void start();
       public void stop();
       public void destroy();
       public void create();
       public boolean pause();
      }
      


      Mbean:
      package com.flytxt.transport.jmx;
      
      import javax.management.InstanceNotFoundException;
      import javax.management.MBeanRegistrationException;
      import javax.management.MBeanServer;
      import javax.management.MalformedObjectNameException;
      import javax.management.ObjectName;
      import org.jboss.annotation.ejb.Service;
      import org.jboss.mx.util.MBeanProxyExt;
      import org.jboss.mx.util.MBeanServerLocator;
      
      @Service (objectName="flytxt:service=transportServer")
      public class TransportServerMBean implements TransportServer {
       private boolean running = false;
       private MBeanServer server = null;
       private TransportServer oi = null;
      
       public TransportServerMBean() {
       System.out.println("TransportServerMbean instanciated");
       }
      
       public void start() {
       if (! running) {
       System.out.println("TransportServerMbean started");
       running = true;
       try {
       oi = (TransportServer) MBeanProxyExt.create(this.getClass(),new ObjectName("flytxt:service=transportServer2"), server);
       } catch (MalformedObjectNameException e) {
       e.printStackTrace();
       running = false;
       } catch (NullPointerException e) {
       e.printStackTrace();
       running = false;
       }
       } else {
       System.out.println("TransportServerMbean already started");
       }
       }
      
       public void stop() {
       if (running) {
       System.out.println("TransportServerMbean stopped");
       running = false;
       try {
       oi.pause();
       server.unregisterMBean(new ObjectName("flytxt:service=transportServer2"));
       } catch (InstanceNotFoundException e) {
       e.printStackTrace();
       running = true;
       } catch (MBeanRegistrationException e) {
       e.printStackTrace();
       running = true;
       } catch (MalformedObjectNameException e) {
       e.printStackTrace();
       running = true;
       } catch (NullPointerException e) {
       e.printStackTrace();
       running = true;
       }
       } else {
       System.out.println("TransportServerMbean not running");
       }
       }
      
       public void destroy() {
       System.out.println("TransportServerMbean destroyed");
       }
      
       public void create() {
       server = MBeanServerLocator.locate();
       System.out.println("TransportServerMbean created");
       }
      
       public boolean pause() {
       System.out.println("TransportServerMbean paused");
       return true;
       }
      
      }
      



      the error i get from this is
      14:36:20,191 WARN [ServiceController] Problem starting service flytxt:service=transportServer
      javax.ejb.EJBException: null; CausedByException is:
       Error creating MBeanProxy: flytxt:service=transportServer2
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:46)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:70)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:134)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:72)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:93)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.service.ServiceContainer.localInvoke(ServiceContainer.java:151)
       at org.jboss.ejb3.service.ServiceContainer.localInvoke(ServiceContainer.java:121)
       at org.jboss.ejb3.service.ServiceMBeanDelegate.invoke(ServiceMBeanDelegate.java:155)
       at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:150)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:967)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:436)
       at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy110.start(Unknown Source)
       at org.jboss.ejb3.service.ServiceMBeanDelegate.register(ServiceMBeanDelegate.java:73)
       at org.jboss.ejb3.service.ServiceContainer.registerManagementInterface(ServiceContainer.java:300)
       at org.jboss.ejb3.service.ServiceContainer.start(ServiceContainer.java:74)
       at org.jboss.ejb3.service.ServiceManager.startService(ServiceManager.java:67)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:267)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:217)
       at sun.reflect.GeneratedMethodAccessor104.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:950)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:436)
       at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy108.start(Unknown Source)
       at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:313)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:267)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:217)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:950)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:436)
       at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy10.start(Unknown Source)
       at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:177)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:118)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
       at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
       at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy11.start(Unknown Source)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:973)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:963)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:774)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:737)
       at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:118)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
       at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy6.deploy(Unknown Source)
       at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:325)
       at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:501)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:204)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:215)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:194)
      


      I tried calling server.create but it kept giving me a javax.management.NotCompliantMBeanException: Class does not expose a management interface: java.lang.Object