10 Replies Latest reply on Mar 8, 2002 12:19 AM by luckystar_007

    Using XADataSource from remote application

    dlaidlaw

      JBoss 2.4.4
      I was wondering if it would be possible to use the JBoss XADataSource Connection pool from a remote application (a different JVM). It seems likely since the XADataSource service is registered in the DefaultDomain (if you define it).

      The object of this would be to avoid writing my own connection pooling code for a different application running outside of JBoss.

      If anyone has any sample code on how to use this I would greatly appreciate it. Or shoot me down if it does not work!

      Thanks all.

        • 1. Re: Using XADataSource from remote application

          Not sure about your requirement.

          If you want to use the datasource registered in JBoss,
          you can get it using JNDI, just narrow it to a
          DataSource.

          If you are talking about embedding and starting one
          in your own application this is ok too.
          I'm not aware of any docs about it, but I've seen
          people who say they've done it in the persistence forum.

          Regards,
          Adrian

          • 2. Re: Using XADataSource from remote application
            dlaidlaw

            Well, my problem is that the code I want to access the DataSource object with is running in a different JVM. And the DataSource is registered in JNDI under the java: namespace. That means, I believe, that DataSource is not available to JNDI lookups from a different JVM. Correct? At least, I have been unable to lookup the java:HermesPool object (that is its name when I explore the JNDIView).

            What I want is to be able to use the pool from an different JVM than the one running JBoss. My extenal application is using JBoss MBeans to provide services via JMS messaging, so I need JBoss anyway, just wanted to be able to use the pools as well.

            The application I am using is a third-party thing that I cannot get to run inside the JBoss JVM. But I can add functionality to that app using plugin classes. My plugins need a JDBC pool. I can either write or copy some pooling code, but since JBoss is already running, it sure would be nice to just use it!

            Thanks!

            • 3. Re: Using XADataSource from remote application

              I see your problem. It is hard-wired to go into the
              java namespace :-(

              Regards,
              Adrian

              • 4. Re: Using XADataSource from remote application

                You probably wouldn't want to pull a datasource from
                a pool on a different machine? It is much better to
                pool it locally. Isn't that the point?

                Regads,
                Adrian

                • 5. Re: Using XADataSource from remote application
                  dlaidlaw

                  > You probably wouldn't want to pull a datasource from
                  > a pool on a different machine? It is much better to
                  > pool it locally. Isn't that the point?
                  >
                  > Regads,
                  > Adrian

                  Yep. I am actually running them both on the same machine, I just can't run in the same JVM.

                  So I just tried making a copy of the org.jboss.jdbc.JDBCDataSourceLoader and having it bind to /jdbc/myPool. That worked OK. I can look it up, but I always return a null, no exception thrown. JNDIView says it is bound, though.

                  For the following the ctxProps are properties pointing to jnp://localhost:2099 (I am running JNDI on 2099).

                  try {
                  ctx = new InitialContext(ctxProps);
                  Object ref = ctx.lookup("/jdbc/myPool");
                  if (ref == null) {
                  System.out.println("lookup returned null");
                  System.exit(1);
                  }
                  ...

                  Always prints out "lookup returned null". Weird. If I put in a name that is not bound I get a naming exception.

                  Note, I am not using an XA datasource, don't really need that in my app.

                  What I CAN do, I suppose, is write all my queries to JDBC and Entity beans and just access those from my app. That would use the pooling automagically.

                  Thanks for all your help on this!

                  • 6. Re: Using XADataSource from remote application
                    ipozeng

                    I donot think it is hard to export the DataSource to outside world.The apusic server can do it very well(http://www.apusic.com)!

                    Why does jboss register it in glaobal namespace?


                    Regards!

                    • 7. Re: Using XADataSource from remote application

                      You probably want to ask in the persistence forum?

                      Regards,
                      Adrian

                      • 8. Re: Using XADataSource from remote application
                        dlaidlaw

                        >
                        > Why does jboss register it in glaobal namespace?
                        >
                        >
                        Because by default it binds to the java: namespace which is not accessible from a different JVM. The MBean that does this binding is a copy of org.jboss.jdbc.JDBCDataSourceLoader that I modified slightly to change its binding.

                        • 9. Re: Using XADataSource from remote application
                          dlaidlaw

                          > You probably want to ask in the persistence forum?
                          >
                          > Regards,
                          > Adrian


                          Done! Thanks for all your help.
                          -Don

                          • 10. Re: Using XADataSource from remote application
                            luckystar_007

                            How Did you done it, would you please tell me? I am experiencing the same pain now.I will be very appreciated