4 Replies Latest reply on Jan 28, 2012 9:29 AM by jaikiran

    Remote EJB access and initialContext?

    markus78

      Hello,

       

      We use the Jboss API to dynamically select wich server to lookup remote EJB's from , but we have problems.

       

      Imagine the following case

       

       

      pseudo code:

       

                EJBClientContext.setSelector(SelectorA);

                ctx = new InitialContext(propsA);

       

                EJBClientContext.setSelector(SelectorB);

                context = new InitialContext(probsB);

       

               ctx.lookup(bean_on_serverA);

               context.lookup(bean_on_serverB);

       

      Will this work?

      Wont the "ctx" context still use SelectorB (the last set selector) to search for EJB's and thus searching on the wrong server? In all previous JBoss versions one would specify in the initialContext which server to work with and that context

      would keep track of this, it is a real pain if we have to implement this ourselves and keep track of the singleton EJBClientContext class in all cituations.....

       

      Our real application is lots more complicated with spring lookup of slsb's mixed with manual lookups wich makes it very very hard to keep track of these things ourselves.

       

      /Markus        

        • 1. Re: Remote EJB access and initialContext?
          prasad.deshpande

          Any context that you create using new InitialContext(props) is very much local to the remote client. context has no information about the remote connections. Your selectors will have it (SelectorA/SelectorB). The only information that Initial context will consider is java.naming.factory.url.pkgs property. So as long as your SelectorB knows about serverA, it should work. By calling EJBClientContext.setSelector(SelectorB); you are ultimately replacing all receivers/connection information. So whether ctx.lookup(bean_on_serverA); & context.lookup(bean_on_serverB); would work or not is all depends on whether SelectorB knows about ServerA & ServerB.

          1 of 1 people found this helpful
          • 2. Re: Remote EJB access and initialContext?
            markus78

            Ok thanks! But what if we have servers with the same beans deployed on them? Is it possible to lookup on specifik server even though the selector knows about 2 servers?

            • 3. Re: Remote EJB access and initialContext?
              prasad.deshpande

              Is it possible to lookup on specifik server even though the selector knows about 2 servers?

              At the moment using remoting API, I don't think so.

               

              As a workaround you may want to try separating out selectors for two servers & try setting them just before you want to do a lookup:

               

              EJBClientContext.setSelector(SelectorA);

              ctx = new InitialContext(propsA);

              ctx.lookup(bean_on_serverA);

               

              SelectorA = EJBClientContext.setSelector(SelectorB); // when you set SelectorB, this call will return previously set selector, if any, which in this case will be SelectorA

              ctx.lookup(bean_on_serverB);

               

              // if needed set SelectorA back

              SelectorB = EJBClientContext.setSelector(SelectorA);

              //do the stuff with SelectorA

              I haven't tried this myself, but would be worth to give a try.

               

              Here is another user Bernd Koecke asking same thing https://community.jboss.org/message/647202#647202#647202  Will be worth to see what architects responds.

              • 4. Re: Remote EJB access and initialContext?
                jaikiran

                I replied to a similar post here https://community.jboss.org/message/649243#649243