6 Replies Latest reply on Mar 14, 2007 2:15 PM by rocken7

    Add method to MDB for jmx/mbean?

    rocken7

      How could I add a trigger/method on my MDB so it shows up in the jmx-console?

      I use these annotations:

      @MessageDriven( @ActivationConfigProperty=xx )

      public class myMDB implements MessageListener { ... }

      Is there an annotation to tag a method/operation for the mbean?

      I know I could use attribute, but I really want an operational button ...

      Maybe some xml magic for the mbean descriptor?

      thnx. -j0

        • 1. Re: Add method to MDB for jmx/mbean?
          rocken7

          My MDB class implements MessageListener, which already has default JMX lifecycle methods: the org.jboss.ejb3.ServiceDelegateWrapper.

          There are activation properties well documented here:
          http://wiki.jboss.org/wiki/Wiki.jsp?page=ConfigJMSMessageListener

          I tried adding the @Management tag to the MDB class, which does not affect anything.

          Does the @MessageDriven tag on the MDB class make this impossible?

          I tried forking off the management methods into an abstract class, then in the MDB class specify @Management(MyJMXBase.class) which blows b/c the MDB class needs to implement MessageListener (even tho my abstract class implements MessageListener):

          ExceptioN:
          unable to determine messagingType interface for MDB

          So

          I put @Management(MyJMXBase.class) tag on the MDB class (which extends MyJMXBase), implement MessageListener directly, and this does nothing.

          What is needed to add a JMX operation (method) to an MDB?

          I can't find any docs on @Management anyway, so it feels like i'm fishing ...

          • 2. Re: Add method to MDB for jmx/mbean?
            rocken7

            Ok looks like i'll have to try out this approach:

            http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3978558

            But then why is there a @Management tag, doesn't that eliminate the need for .sars etc. ?

            • 3. Re: Add method to MDB for jmx/mbean?
              rocken7

              And how do I find the MDB instance in jndi? What would the jndi path be? I don't see it in the JNDIView ... How would I specify the jndi path for the MDB instance?

              • 4. Re: Add method to MDB for jmx/mbean?
                rocken7

                Ok I can insert the MDB via the @PostConstruct method, by binding to jndi, but that feels wrong, is there a way to specify the jndi?

                • 5. Re: Add method to MDB for jmx/mbean?
                  rocken7

                  Well the MDB is a SLSB, therefore kind of wrong to bind into jndi. So what I did was use an entity bean (cached) with configuration props and inject that into the MDB in order to manage the message queue. This will work pretty well.

                  And my jmx bean will set props (manage) on the entity configuration as well as evict it from the cache.

                  • 6. Re: Add method to MDB for jmx/mbean?
                    rocken7

                    So I did the JMX Mbean, and had a hell of a time figuring out how to get to an EntityManager from within the MBean. No resource injection works, why I have no idea, is this a bug?

                    @PersistenceContext did nothing, @Resource did nothing. No idea how to get that working. The @Management annotation is a mystery as well (but I digress).

                    Me thinks jboss/redhat need some serious document renewals, the documentation is worse than my GF's sense of direction.

                    Without the UserTransaction, jboss vomits NullPointer exceptions. All attempts to create the EntityManager using the factory failed as well.

                    Here is a related jira report:
                    http://jira.jboss.com/jira/browse/EJBTHREE-665;jsessionid=E296A2B1C1633F424959E377C8838B32?page=all

                    This was how I got it to work:

                    UserTransaction tx = null;
                    
                     try
                     {
                     InitialContext ctx = new InitialContext();
                     tx = (UserTransaction) ctx.lookup("UserTransaction");
                     tx.begin();
                    
                     EntityManager em = (EntityManager) ctx.lookup("java:/Myxdb");
                     Query q = em.createNamedQuery("MyXAdsProp.findByName");
                     q.setParameter("name", name);
                    
                     MyXAdsProp dap = (MyXAdsProp) q.getSingleResult();
                     if( dap.getValue() != null && !dap.getValue().equals(value))
                     {
                     dap.setValue(value);
                     }
                    
                     tx.commit();
                     return "OK";
                     }
                     catch(Exception e)
                     {
                     if( tx.getStatus() == Status.STATUS_ACTIVE )
                     {
                     tx.rollback();
                     }
                    
                     e.printStackTrace();
                     return new String(e.getMessage());
                     }