4 Replies Latest reply on Mar 19, 2012 4:43 AM by michael_gronau

    How to close remote ejb/jndi connections

    michael_gronau

      Hello,

      during my very somewhat painful journey to migrate our app to jboss7 (coming from 5.x) I found another little problem. What i want to achieve is like this:

      1. create a normal jndi context (for non-ejb lookups) and an ejb context.

      2. do somethings.

      3. close the two connections.

      4. do all this again and again.

       

      My problem is I dont know how to close the connections. The only way I know, is close the jvm, but this is no solution for the described test case.

      Imagine a remote web app that wants to call our app with hundreds or thousands of users (which is 2 connections per user in this test case). If a user signs off, we should be able to close the connection immediately.

       

      With best regards

      Michael

        • 1. Re: How to close remote ejb/jndi connections
          ropalka

          Hello, the following solution works for us:

           

          InitialContext ctx = new InitialContext(remoteEjbProperties);
          try {
             ...
             // do something with ctx, e.g. lookup & use EJBs via ejb: remote protocol
             ...
          } finally {
             ctx.close();
          }

           

          But I see your requirement is different

          It seems you want to have the control over the specific remoting connection, right?

          • 2. Re: How to close remote ejb/jndi connections
            jaikiran

            How are you creating the EJB client context and registering the receivers?

            • 3. Re: How to close remote ejb/jndi connections
              michael_gronau

              Hi jaikiran,

              I'm just doing it like this:

               

                  this.ejbClientProperties.setProperty("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
                  this.ejbClientProperties.setProperty("remote.connections", "default");
                  this.ejbClientProperties.setProperty("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
              //    this.ejbClientProperties.setProperty("remote.connection.default.connect.options.org.xnio.Options.SASL_MECHANISMS", "PLAIN");
                  this.ejbClientProperties.setProperty("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
                  this.ejbClientProperties.setProperty("remote.connection.default.host" , this.host);
                  this.ejbClientProperties.setProperty("remote.connection.default.port", Integer.toString(this.port));
                  this.ejbClientProperties.setProperty("callback.handler.class", AnonymousSaslClientCallbackHandler.class.getName());

               

                  Hashtable jndiProperties = new Hashtable();
                 
                  jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

              //

               

                  this.ejbNamingContext = new InitialContext(jndiProperties);

               

              then i simply look up the ejb's via this.ejbNamingContext.lookup(...)

               

              I debugged a little bit around and when i close the ejbNamingContext there is no special code executed to close the underlying connections, because the context is an instance of javax.naming.InitialContext, which does nearly nothing in its close() method.

              • 4. Re: How to close remote ejb/jndi connections
                michael_gronau

                Oh, and there is a little bit more:

                after creating the ejb context with new InitialContext I create a new connection using the member variable this.ejbClientProperties like this:

                 

                new PropertiesBasedEJBClientConfiguration(this.ejbClientProperties);