3 Replies Latest reply on Dec 21, 2012 2:00 AM by nickarls

    How to access JBoss port offset in my application?

    clempinch

      Hello,

      We currently have several JBoss AS 7.1.1.Final servers deployed on the same machine and we are successfully using the offset properties to avoid port collision.

      For example:

       

      <server name="server1" group="server-group1" auto-start="true">

                  <socket-bindings socket-binding-group="full-sockets" port-offset="250"/>

      </server>

       

      The fact is that I would like to retrieve this offset value in my application. There, I indeed define some listening port and I would like to avoid port collision the same way using the JBoss offset.

      My application is packaged as an EAR and I was planning to retrieve this offset value as a system property.

       

      I tried to use ${jboss.socket.binding.port-offset} but this does not work unless we have:

       

      <server name="server1" group="server-group1" auto-start="true">

                  <socket-bindings socket-binding-group="full-sockets" port-offset="${jboss.socket.binding.port-offset:250}"/>

      </server>

       

      and explicitely passing -Djboss.socket.binding.port-offset to the JBoss startup.

      This does not satisfy me.

       

      Does anyone know how I can access the port offset as a property from my application?

        • 1. Re: How to access JBoss port offset in my application?
          nickarls

          If you connect with jboss-cli -c and do a

           

          [standalone@localhost:9999 /] /socket-binding-group=standard-sockets:read-attribute(name="port-offset")

           

          you get a


          {

              "outcome" => "success",

              "result" => expression "${jboss.socket.binding.port-offset:0}"

          }

           

          which leads me to (without testing) believe that absolute values can be read in the same way. And that same attribute could also be read from within the application with a ModelControllerClient...

          1 of 1 people found this helpful
          • 2. Re: How to access JBoss port offset in my application?
            clempinch

            Thank you for your reply.

            It works! Here is the code using ModelControllerClient:

             

            public int getOffset() {

                ModelControllerClient client = null;

                try {

                    ModelNode op = new ModelNode();

                    op.get(ClientConstants.OP).set("read-attribute");

                    op.get("name").set("port-offset");

                    op.get(ClientConstants.OP_ADDR).add("socket-binding-group", "standard-sockets");

                    client = ModelControllerClient.Factory.create("localhost", 9999);

                    ModelNode response = client.execute(new OperationBuilder(op).build());

                    return Integer.parseInt(response.get(ClientConstants.RESULT).toString());

                } catch (UnknownHostException e) {

                    // handle the exception

                    return 0;

                } catch (IOException e) {

                    // handle the exception

                    return 0;

                } finally {

                    if (client != null) {

                    try {

                        client.close();

                    } catch (IOException e) {

                        // handle the exception

                    }

                    }

                }

            }

             

            My concerns now are: how to avoid the remote calls to localhost:9999 and how to integrate this to my application as a system property...

            I think I will try what is proposed there: http://management-platform.blogspot.fr/2012/07/co-located-management-client-for.html

            But this is another debate.

            • 3. Re: How to access JBoss port offset in my application?
              nickarls

              The direct service lookup has the advantage that you don't need to know the management port in advance.