skip to main content
About the Driver : Using the driver : Statement Pool Monitor : Accessing the Statement Pool Monitor : Using JMX
  

Try DataDirect Drivers Now
Using JMX
The driver registers a single Statement Pool Monitor for each statement pool with the default MBean server of the JVM. The registered MBean name has the following form, where monitor_name is the string returned by the ExtStatementPoolMonitor.getName() method:
com.ddtek.jdbc.type=StatementPoolMonitor,name=monitor_name
To return information about the statement pool, retrieve the names of all MBeans that are registered with the com.ddtek.jdbc domain and search through the list for the StatementPoolMonitor type attribute. The following code shows how to use the standard JMX API calls to return the state of all active statement pools in the JVM:
private void run(String[] args) {
   if (args.length < 2) {
      System.out.println("Not enough arguments supplied");
      System.out.println("Usage: " + "ShowStatementPoolInfo hostname port");
   }
   String hostname = args[0];
   String port = args[1];
   JMXServiceURL          url = null;
   JMXConnector            connector = null;
   MBeanServerConnection   server = null;
   try {
      url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" +
                              hostname +":" + port + "/jmxrmi");
      connector = JMXConnectorFactory.connect(url);
      server = connector.getMBeanServerConnection();
      System.out.println("Connected to JMX MBean Server at " +
                        args[0] + ":" + args[1]);
      // Get the MBeans that have been registered with the
      // com.ddtek.jdbc domain.
      ObjectName ddBMeans = new ObjectName("com.ddtek.jdbc:*");
      Set<ObjectName> mbeans = server.queryNames(ddBMeans, null);
      // For each statement pool monitor MBean, display statistics and
      // contents of the statement pool monitored by that MBean
      for (ObjectName name: mbeans) {
         if (name.getDomain().equals("com.ddtek.jdbc") &&
             name.getKeyProperty("type")
                .equals("StatementPoolMonitor")) {
            System.out.println("Statement Pool - " +
               server.getAttribute(name, "Name"));
            System.out.println("Max Size:    " +
               server.getAttribute(name, "MaxSize"));
            System.out.println("Current Size: " +
               server.getAttribute(name, "CurrentSize"));
            System.out.println("Hit Count:    " +
               server.getAttribute(name, "HitCount"));
            System.out.println("Miss Count:   " +
               server.getAttribute(name, "MissCount"));
            System.out.println("Statements:");
            Object[] params = new Object[3];
            params[0] = new Integer(-1);
            params[1] = new Integer(-1);
            params[2] = new Integer(-1);
            String[] types = new String[3];
            types[0] = "int";
            types[1] = "int";
            types[2] = "int";
            ArrayList<String>statements = (ArrayList<String>)
               server.invoke(name,
                            "poolEntries",
                            params,
                            types);
            for (String stmt : statements) {
               int index = stmt.indexOf(";");
               System.out.println("   " + stmt.substring(0, index));
            }
         }
      }
   }   
   catch (Throwable except) {
      System.out.println("ERROR: " + except);
   }
}