1 Reply Latest reply on Jun 1, 2010 12:25 PM by peterj

    How to dynamically retrieve datasource names

    tarballa

      I'm wanting to periodiacally query each registered datasource's MBean for connection statistics, using something like:

       

       

      String jmxLocation =
      "jboss.jca:name="+ jndiName + ",service=ManagedConnectionPool";
      
      
      try {
      ObjectName objectName =
      new ObjectName( jmxLocation );
      
      
      double maxConnections = Double.valueOf( String.valueOf( mbs.getAttribute( objectName, "MaxSize" ) ) );
      
      double inUseConnections = Double.valueOf( String.valueOf( mbs.getAttribute( objectName, "InUseConnectionCount" ) ) );
      
      
      System.
      out.println( "In use connections: " + inUseConnections );
      
      }
      catch ( Exception e ) {
      
      }
      
      
      
      
      
      
      
      
      
      
      
      
      

       

      What I'm wondering though, is if it's possible to dynamically retrieve each datasource's JNDI name, so that I can avoid hardcoding our various datasources.  The javadocs for ObjectName seem to indicate that only a valid domain/key/value name (like in the above code) is valid.  Is there another way of dynamically reading these JNDI names?

        • 1. Re: How to dynamically retrieve datasource names
          peterj

          Take a look at javax.management.MBeanAServerConnection.queryMBeans(). The query expression lets you specify the you want to obtain all MBeans with a given prefix ("jboss.jca" in this case) and a given set of attributes ("service=ManagedConnectionPool" in this case), and it returns all such MBeans.