DataSource Mbean in websphere liberty - getting instance not found exception

865 views Asked by At

I am trying to migrate WAS7 application to Liberty profile. And now I am trying to get Datasource Mbean which is part of the existing code.I tried multiple options but I am always getting 'javax.management.InstanceNotFoundException'.

I am giving the sample code below. Please let me know if I miss something.

DataSource in Server.xml:

<library id="oracle-lib">
    <fileset dir="lib" includes="ojdbc6.jar"/>
</library>

<dataSource jndiName="jdbc/db" id="oracleDB" type="javax.sql.DataSource">
    <jdbcDriver javax.sql.DataSource="oracle.jdbc.pool.OracleConnectionPoolDataSource" libraryRef="oracle-lib" />
    <connectionManager agedTimeout="10" maxIdleTime="1800" connectionTimeout="180"  minPoolSize="10" maxPoolSize="1" reapTime="180"/>
    <properties.oracle user="user" password="password"
                url="jdbc:oracle:thin:@//db-server:1521/db"/>
</dataSource>

Java Code:

MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName jvmQuery = new ObjectName("WebSphere:type=ConnectionPoolStats,name=dataSource[oracleDB]/ConnectionManager[default-0]")
Set mBeans = mbeanServer.queryMbeans(jvmQuery,null);
MBeanInfo beanInfo = mbeanServer.getMBeanInfo(jvmQuery);

I am not sure about the code, I am trying to keep the old code as much as possible.

Thank you, Biju

1

There are 1 answers

1
Andy Guibert On BEST ANSWER

In your object name there is a minor case mismatch. The C on connectionManager should be lowercase, not uppercase.

WebSphere:type=ConnectionPoolStats,name=dataSource[oracleDB]/connectionManager[default-0]

A few other things to check:

  1. Make sure you have the monitor-1.0 feature enabled
  2. Note that since Connection Managers are created lazily (not initialized until first use) there will be no ConnectionPoolStats MBean until there has been at least 1 connection obtained from your Connection Manager.
  3. You can verify the presence of your MBean by checking jconsole, which is a Java utility that comes with any JDK. After a request has been made to your data source / connection manager, you should see an MBean like this:

enter image description here

To use jconsole you will need to enable the localConnector-1.0 feature. You can find more info on using JConsole with Liberty here:
Connecting to Liberty by using JMX