Keiichi,

On Thu, Jan 25, 2018 at 1:48 AM, Keiichi Fujino <kfuj...@apache.org> wrote:
>
> Hi
>
> The Docs of jdbc-pool describe like this.
> ==
> If you're running outside of a container, you can register the DataSource
> yourself under any object name you specify, and it propagates the
> registration to the underlying pool. To do this you would call
> mBeanServer.registerMBean(dataSource.getPool().getJmxPool(),objectname).
> Prior to this call, ensure that the pool has been created by calling
> dataSource.createPool().
> ==
> http://tomcat.apache.org/tomcat-9.0-doc/jdbc-pool.html#JMX
>
> Thus you must register the DataSource as MBean.

Thank you. I dug around more after your pointers.
I am using 8.0.x (I should have said that). I found a few things
problematic with JMX around data sources.

I ended up calling MBeanRegistration.preRegister() on the data source.
This way I don't have to cast it to Tomcat classes. It does the job,
but not in a right way. I looked around and I noticed these facts:

- DataSource.createPool() is always called anyway when the data source
is created, by DataSourceFactory.createDataSource()
- Pool object is not supposed to be registered JMX object, there is a
special JMX object that is created is jmxEnabled is true.
- DataSource implementation looks like a JMX bean, it implements
MBeanRegistration and ConnectionPoolMBean, but trying to register it
directly throws a non-compliant JMX bean exception
- MBeanRegistration implementation of the DataSource violates API
contract. It doesn't return the ObjectName that is being used, and it
actually registers the bean with JMX (it shouldn't)

I had problems with that last fact, because if I register the bean, I
need to clean it up on shutdown, but I can't get the actual name that
the bean is registered as (except for copying the code that
preRegister ends up calling). I ended up fishing the bean out by
querying it before unregistering it.

I hope things are, in fact, better in 9.

Thank you,
  Pawel.

> 2018-01-24 10:48 GMT+09:00 Pawel Veselov <pawel.vese...@gmail.com>:
>
> > Hello.
> >
> > I'd like to get some JMX stats out of the JDBC connection pools. But
> > they don't seem to register
> > in JMX, even though they are based on ConnectionPoolMBean.
> >
> > I do create the pools programmatically, by binding the factory into
> > the JNDI, the creation snippet is
> > copied below. When I search for JMX objects, I don't see anything that
> > looks like the pool info,
> > but I'm also not sure what the object name is supposed to be. I expect
> > it to be in "Catalina"
> > domain, though some of the code I saw suggests it may be in
> > "tomcat.jdbc" domain instead... I
> > don't have any "tomcat." domains at all.
> >
> > Any clues are appreciated.
> >
> > --------------------------
> > Properties p = new Properties();
> >
> > p.setProperty("type", "javax.sql.Datasource");
> > p.setProperty("defaultAutoCommit", "false");
> > // <...> set some other properties here
> > // enable JMX
> > p.setProperty("jmxEnabled", String.valueOf(Boolean.TRUE));
> > // JNDI of the actual data source
> > p.setProperty("dataSourceJNDI", pooledDSName);
> > Class<?> dsfClass =
> >         Class.forName("org.apache.tomcat.jdbc.pool.DataSourceFactory");
> > Object dsf = dsfClass.newInstance();
> > Method m = dsfClass.getDeclaredMethod("createDataSource",
> >         Properties.class);
> > return m.invoke(dsf, p);
> > // the result is bound into JNDI
> > --------------------------
> >
> > Thank you!

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to