google-code-export / h2database

Automatically exported from code.google.com/p/h2database
0 stars 1 forks source link

JMX MBean #253

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

Attached is a patch that adds a JMX MBean for H2 databases.

Relevant discussion thread:
http://groups.google.com/group/h2-database/browse_thread/thread/2647d453e0ff7939
/6993c530e908e802?lnk=gst&q=jmx&pli=1

Roadmap item:
http://www.h2database.com/html/roadmap.html
'Support JMX: create an MBean for each database and server (support JConsole).'

How to use:
* Connect to a database with ';JMX=TRUE'
* Optionally specify MBean name with ';JMX=mbeanName'; default is the 
database's short name
* To test using jconsole:
   - Enable the MBean as indicated above
   - Start jconsole and connect to the appropriate JVM process
   - Under the MBeans tab, on the left there will be an 'org.h2' folder

Notes:
* The MBean attributes and operations I've added are read-only

Patch is based off of:

$ svn info
Path: .
URL: http://h2database.googlecode.com/svn/trunk
Repository Root: http://h2database.googlecode.com/svn
Repository UUID: e6896862-9d19-0410-bfb3-e9fa5d50e656
Revision: 3093
Node Kind: directory
Schedule: normal
Last Changed Author: thomas.tom.mueller
Last Changed Rev: 3092
Last Changed Date: 2010-11-08 13:27:59 -0800 (Mon, 08 Nov 2010)

Eric

Original issue reported on code.google.com by eric.anl...@gmail.com on 9 Nov 2010 at 11:36

Attachments:

GoogleCodeExporter commented 9 years ago
Correction:

'* Optionally specify MBean name with ';JMX=mbeanName'; default is the 
database's short name'

should instead be

'* Optionally specify MBean name with ';JMX_MBEAN_NAME=mbeanName'; default is 
the database's short name'

Original comment by eric.anl...@gmail.com on 9 Nov 2010 at 11:38

GoogleCodeExporter commented 9 years ago
The MBean attributes and operations I've added are based on the ones that 
appear in INFORMATION_SCHEMA.SETTINGS.

Original comment by eric.anl...@gmail.com on 10 Nov 2010 at 12:07

GoogleCodeExporter commented 9 years ago
I changed your patch, please review it.

Do you really want your email address in the source code? You will get more 
spam this way.

I know this is a bit silly, but could you state that you wrote it yourself? See 
http://h2database.com/html/build.html#providing_patches ("I wrote the 
code...")? It's just for legal reasons. Some companies did ask me about such 
guarantees in the past.

I renamed the interface H2DatabaseMBean to DatabaseInfoMBean and the class 
H2Database to DatabaseInfo.

I renamed the map mbeanObjectNames to MBEANS.

I moved all mbean support to the class DatabaseInfoMBean, so that it's easier 
to remove the functionality (just delete the classes) if not required. The 
Engine class uses reflection to register and unregister.

The constructor is no longer public.

I removed "final" in most declarations. I find them distracting.

The "{@inheritDoc}" is superfluous I believe. I removed those.

The following javadoc is also superfluous:
    /** Database. */
    private final Database database;

The following expression is weird: "command == null ? null : command". Why not 
just "command"?

I couldn't open two connections (that was after I changed your code, maybe it 
was my mistake).

I renamed the "print" methods (printSessions,...) to "list" methods 
(listSessions,...)

The result of the "print" methods is hard to read because it's on one line. I 
use multi-line results instead. I wonder if this works on Windows?

The parameter "boolean includingSystemSession" in the print methods is listed 
as "p1" in the JConsole. That's not user friendly. I believe it's better not to 
use parameters if there is no easy way to provide the name.

The operations no longer synchronized on the database. Otherwise this blocks:
create alias sleep as 'void x() throws Exception { Thread.sleep(1000); }';
create table test(id int primary key) as select 1;
select sleep() from system_range(1, 10), test;

I also want to make sure JMX support is not included in the small jar file 
(build jarSmall).

Also I didn't run the build and didn't test it yet.

Could you create a unit test for this feature?

Original comment by thomas.t...@gmail.com on 13 Nov 2010 at 5:21

Attachments:

GoogleCodeExporter commented 9 years ago
I combined listSessions an listLocks (listSessions now includes information 
about locks)

The bean name now includes the full path (because the short name may not be 
unique, and as additional information to find out where the database is stored).

I added getVersion().

I added getTraceLevel() and setTraceLevel(int level).

I added setCacheMaxSize(), setLogMode().

JMX support is execluded from the small jar file (build jarSmall).

I renamed getFileCacheX to getCacheX.

I added MBean documentation by converting the Javadoc to a resource (as it's 
done for tools).

The settings are now sorted by name.

I removed the JMX_MBEAN_NAME (I think it's not necessary any longer).

Todo:

We need user documentation. 

If possible, there should be some automated test cases.

Original comment by thomas.t...@gmail.com on 14 Nov 2010 at 12:10

GoogleCodeExporter commented 9 years ago
I have committed the changes in the trunk in revision 3126.

Original comment by thomas.t...@gmail.com on 15 Nov 2010 at 8:52

GoogleCodeExporter commented 9 years ago
Enabled in version 1.2.147.

Original comment by thomas.t...@gmail.com on 21 Nov 2010 at 5:53

GoogleCodeExporter commented 9 years ago
Hi, thanks for getting this in!

I wrote the code, it's mine, and I'm contributing it to H2 for distribution 
multiple-licensed under the H2 License, version 1.0, and under the Eclipse 
Public License, version 1.0 (http://h2database.com/html/license.html).

Your changes look good to me. Could you also remove my email address from 
DatabaseInfo and DatabaseInfoMBean? Attached is a small patch for this. Thanks!

Regarding adding test cases, one option is to extract the methods of Database 
referenced in DatabaseInfo into an interface and mock that interface using a 
tool like EasyMock. This would make adding test cases almost trivial.

Original comment by eric.anl...@gmail.com on 13 Dec 2010 at 6:41

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks! I committed the changes. The code coverage is now good at 91%, see also 
http://h2database.com/coverage/overview.html - details at 
http://h2database.com/html/build.html#automated

Original comment by thomas.t...@gmail.com on 13 Dec 2010 at 7:19