4 Replies Latest reply on Jan 5, 2005 2:00 PM by luispera

    EJB - MBean communication

    pbowker

      Hi,

      I haven't used JMX and MBeans before so please bear with me if my questions are rather naive.

      I want to instrument three apps that run in the same JBoss instance for SNMP. Regardless of whether I use the JBoss adaptor or a 3rd party product, if I understand the architecture correctly, an EJB that encounters a situation for which an alarm is to be raised (eg DB not available) must communicate this to a managing MBean. The MBean then raises a JMX notification which in the JBoss world is mapped to an SNMP trap through the notifications.xml in the SNMP adaptor configuration.

      My questions are;

      What is the recommended method of communication between an EJB and an MBean? Must an MBean poll an EJB or can an EJB directly invoke a method on an MBean? If the latter, how is this done? Can an EJB look up an MBean through JNDI, or is some other comms model (JMS?) preferred?

      Many thanks for any help offered.

      Phil Bowker

        • 1. Re: EJB - MBean communication
          raja05

          One option that immediately comes to mind is calling the MBean method from ur EJB and the MBean emitting the notifications. You can look the MBean using the MBeanServer thats available all over the jboss vm.
          This is one way
          Properties p = new Properties();
          p.put"java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
          p.put("java.naming.provider.url", "localhost:1099");
          InitialContext jndiContext = new InitialContext(p);
          RMIAdaptor server = (RMIAdaptor) jndiContext.lookup("jmx/rmi/RMIAdaptor");
          javax.management.ObjectName name = new javax.management.ObjectName("<your MBean object name>");
          server.invoke(name, "ur operation", args, args);

          Your MBean on receipt of this call can do the notifications.


          • 2. Re: EJB - MBean communication
            pbowker

            Thanks for the info Raja. In combination with some help I got from Sun's JMX forum I now have everything I need.

            Cheers,

            Phil

            • 3. Re: EJB - MBean communication
              ant

              Invoking MBean methods through the RMIAdaptor works fine for MBeans. But how can I communicate with an embedded class of a MBean? This situtation occurs using org.jboss.varia.scheduler.Scheduler. The Scheduler MBean needs to be configured with a class that implements the interface org.jboss.varia.scheduler.Schedulable.

              I think the only way to communicate with this class is through JMS. Is there another way to accomplish this?

              Using JMS works fine for my requirements. But there is one flaw to report: when shutting down JBoss, destroying the JMS destination throws an JMSException because it's already beeing used. How can I gracefully shutdown (closing queues and connections) all self-written components and services (such as the implementation class of Schedulabel) within JBoss?

              Thanks in advance.

              • 4. Re: EJB - MBean communication
                luispera

                 

                "pbowker" wrote:
                Thanks for the info Raja. In combination with some help I got from Sun's JMX forum I now have everything I need.

                Cheers,

                Phil

                Could you share the solution that you've got ?

                Regards,
                LP