7 Replies Latest reply on Sep 24, 2011 11:19 AM by Daniel Straub

    How do I put an MBean in JNDI?

    Matt Drees Master

      Hi all,

       

      I'm trying to get a SAR deployed to AS7.

       

      One of my MBeans is trying to bind itself into JNDI using NonSerializableFactory.rebind(name, this, true).  This apparently works fine on older jboss releases, but on AS7 I get this:

       

       

      13:30:22,405 WARN  [org.ccci.ha.HighAvailabilityDataSource] (MSC service thread 1-4) Starting up HighAvailabilityDataSource ccpDatasource in PRIMARY mode
      13:30:22,406 INFO  [stdout] (MSC service thread 1-4) fullName=jdbc/ccpDatasource
      13:30:22,406 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.mbean.service."jboss.jca:name=jdbc/ccpDatasource,service=DataSourceBinding".start: org.jboss.msc.service.StartException in service jboss.mbean.service."jboss.jca:name=jdbc/ccpDatasource,service=DataSourceBinding".start: Failed to execute legacy service start() method
          at org.jboss.as.service.StartStopService.start(StartStopService.java:51)
          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1675)
          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_24]
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_24]
          at java.lang.Thread.run(Thread.java:680) [:1.6.0_24]
      Caused by: java.lang.reflect.InvocationTargetException
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_24]
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_24]
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_24]
          at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_24]
          at org.jboss.as.service.AbstractService.invokeLifecycleMethod(AbstractService.java:59)
          at org.jboss.as.service.StartStopService.start(StartStopService.java:49)
          ... 4 more
      Caused by: java.lang.UnsupportedOperationException: Naming context is read-only
          at org.jboss.as.naming.NamingContext.rebind(NamingContext.java:227)
          at javax.naming.InitialContext.rebind(InitialContext.java:408) [:1.6.0_24]
          at org.jboss.util.naming.NonSerializableFactory.rebind(NonSerializableFactory.java:185)
          at org.jboss.util.naming.NonSerializableFactory.rebind(NonSerializableFactory.java:250)
          at org.ccci.ha.HighAvailabilityDataSource.rebind(HighAvailabilityDataSource.java:53)
          at org.ccci.ha.HighAvailabilityDataSource.start(HighAvailabilityDataSource.java:34)
          ... 10 more
      

       

      So, it looks like JNDI is read-only now.  What is the recommended approach for making an MBean available in JNDI?

       

       

      Or, perhaps I'm just going about this all the wrong way.  What I really need is to make a custom javax.sql.Datasource available in JNDI, and I need to be able to do some logic on start-up.  (I don't want to use JCA for this, since this datasource simply delegates to one of two other standard (JCA) datasources.)  I'm sure I don't need this object to be an MBean, but that seemed the simplest thing at the time.  Is there a better way to do this?

       

      Thanks!