13 Replies Latest reply on Apr 20, 2005 11:37 PM by bensonfungjava

    how to get the managed jms connectionfactory outside the ejb

      Hello,

      Is it possible to get the jms managed connection factory (JCA) outside the ejbs (e.g., JMX beans)?

      What i want to do is:

      (1) my application get the managed connection factory (mcf) through jndi lookup
      (2)I expect that mcf provides a API like getConnection() to get the managed connection from the connection manager (providing pool function etc).

      Reason: I cannot preconfigure the ejb-jar.xml file because when i deploy the application, not all the connection destination is known.

      In other words, can i use managed connection(factory) in JMX bean (outside of the ejbs)?

      Regards

      yang

        • 1. Re: how to get the managed jms connectionfactory outside the

          Hello,

          In my JMX bean, i did the following testing:

          Object o1 = ctx.lookup("java:/ConnectionFactory");
          Object o2 = ctx.lookup("java:/Jms");
          log.debug("" + (o1 instanceof QueueConnectionFactory));
          log.debug("" + (o2 instanceof QueueConnectionFactory));


          The results show that both o1 and o2 are instanceof QueueConnectionFactory. But i cannot use o2 to create QueueConnection:

          ((QueueConnectionFactory)o1).createQueueConnection();
          ((QueueConnectionFactory)o2).createQueueConnection();

          The second creation throws exception :

          java.lang.IllegalStateException: This method is not a
          pplicatable in JMS resource adapter

          How to use pooled connection outside the ejb?

          Please help!

          Thanks a lot

          yang

          • 2. Re: how to get the managed jms connectionfactory outside the

            As per the FAQ:
            cf = (QueueConnectionFactory) ctx.lookup("java:/JmsXA");

            • 3. Re: how to get the managed jms connectionfactory outside the

              Hi,

              Thanks for andrian. I read through the FAQ for several times, i still cannot find which is directly related my question :(.

              The QueueConnectionFactory got by ctx.lookup("java:/Jms") cannot be used to createQueueConnection:

              ((QueueConnectionFactory)ctx.lookup(""java:/Jms")).createQueueConnection();

              Becaue an IlleagleStateException will be thrown.

              Why? Please help.

              To understand the reason, i read somthing about JCA architecture.

              (1) I guess that the ConnectionFactory (result of ctx.lookup("java:/Jms")) should be the ConnectionFactory refered to by application instead of ManagedConnectionFactory. Am i right?

              (2) If yes, then according to the JCA requirement: "When a resource adapter creates a connection factory, it must associate the connection factory object to a ConnectionManager.". I am wondering whether the connectionfactory i got through this JNDI lookup is not assocated with a connection manager (which should be implemented by application server)?

              (3) If yes, then how can i associate the connectionfactory got through JNDI looking up with a Connection Manager?


              (4) Or i am totally wrong?

              Please help.


              best regards

              yang


              • 4. Re: how to get the managed jms connectionfactory outside the

                (4) read Adrian's post one more time. The name is java:/JmsXA not java:/Jms ...

                Regards,

                Stephane

                • 5. Re: how to get the managed jms connectionfactory outside the

                  Also, the Wiki contains code that shows how to use java:/JmsXA with XDoclet in a Session Bean.

                  http://www.jboss.org/wiki/Wiki.jsp?page=JmsSenderBean

                  • 6. Re: how to get the managed jms connectionfactory outside the

                    hi

                    I think StephaneNicoll misunderstand my question.
                    It is not the issue of java:/JmsXA or java:/Jms.


                    I also know how to use resource adapter in ejb by define entries in ejb-jar.xml file etc.

                    My question is how to use resource adapter outside of ejb? e.g., like JMX bean.

                    Andrian, can you give me help?

                    thanks a lot

                    yang

                    • 7. Re: how to get the managed jms connectionfactory outside the

                      Well I might misunderstand your question, true, but back to your first post:

                      QueueConnectionFactory qf = (QueueConnectionFactory) ctx.lookup("java:/JmsXA");
                      qf.createQueueConnection();

                      will work in your Mbean. Then you can do whatever you want with the connection (returns it to the caller for instance eventhough I don't really get the point)

                      Regards,

                      Stephane

                      • 8. Re: how to get the managed jms connectionfactory outside the

                        In my previous post, it is clearly written that it will throws

                        IllegalStateException


                        This is the reason why i post here.


                        Regards

                        yang

                        • 9. Re: how to get the managed jms connectionfactory outside the

                          Hi

                          This is my codes:

                          QueueConnectionFactory qcf = (QueueConnectionFactory)ctx.lookup("java:/JmsXA");
                          QueueConnection qc = qcf.createQueueConnection();
                          qc.setExceptionListener(this);

                          ERROR [STDERR] (ScannerThread:com.test:service=C2SConnector C2SConnectorService) java.lang.IllegalStateException: This method is not applicatable in JMS resource adapter
                          ERROR [STDERR] (ScannerThread:com.test:service=C2SConnector C2SConnectorService) at org.jboss.resource.adapter.jms.JmsSessionFactoryImpl.setExceptionListener(JmsSessionFactoryImpl.java:213)


                          I read the source code of JmsSessionFactoryImpl.java

                          The code at line 213 is:

                          public void setExceptionListener(ExceptionListener listener)
                          throws JMSException
                          {
                          throw new IllegalStateException(ISE);
                          }


                          I don't know how to solve this problem.

                          Andrian, please give me help.

                          Thanks a lot

                          yang

                          • 10. Re: how to get the managed jms connectionfactory outside the
                            darranl

                             

                            "yxyang" wrote:
                            In my previous post, it is clearly written that it will throws

                            IllegalStateException



                            No it isn't your posts you never say that you used 'java:/JmsXA'

                            • 11. Re: how to get the managed jms connectionfactory outside the

                              It is ok, it is the problem of java:/JmsXA or java:/Jms.
                              Because i just change the name JmsXA to Jms. Ok, you just assume that it java:/JmsXA.

                              Actually, i just modified the jndi name to java:/Jms and also modify other place e.g., login....xml etc. It is not related to this.

                              I tested both java:/Jms and java:/JmsXA.

                              Within EJB, it works fine. But outside EJB(in my case, it is a JMX bean), the IllegalStateException is thrown.


                              regards
                              yang

                              • 12. Re: how to get the managed jms connectionfactory outside the

                                You cannot set an ExceptionListener on a JCA managed JMS connection.
                                The ExceptionListener is handled internally by the JMS resource adapter.

                                Using a JCA JMS pool, you never deal with a single connection, the connection is
                                pooled.

                                • 13. Re: how to get the managed jms connectionfactory outside the
                                  bensonfungjava

                                  Hi Adrian,

                                  I still don't understand your answer. I am sorry. :~(


                                  Benson