Browse Prior Art Database

JMX Convenience Method to call an MBean method via JMX MBeanServer

IP.com Disclosure Number: IPCOM000035585D
Original Publication Date: 2005-Jan-25
Included in the Prior Art Database: 2005-Jan-25
Document File: 4 page(s) / 47K

Publishing Venue

IBM

Abstract

Endusers seeking to invoke a method on a JMX managed bean must do so via the JMX MBeanServer interface. This requires several lines of java code to construct an argument list and an associated argument datatype list. A process that is prone to error not discovered until runtime.

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 55% of the total text.

Page 1 of 4

JMX Convenience Method to call an MBean method via JMX MBeanServer

End users seeking to invoke a method on a JMX managed bean must do so via the JMX MBeanServer interface. This requires several lines of java code to construct an argument list and an associated argument datatype list. A process that is prone to error not discovered until runtime.

An example is shown below:

public String getAdminConnection() {

Object[] args;

String[] sigs;

if (connectionID == null ) { args = new Object[7]; sigs = new String[7];

args[0] = jdbcDriver; sigs[0] = "java.lang.String" ; args[1] = jdbcType; sigs[1] = "java.lang.String" ; args[2] = serverName; sigs[2] = "java.lang.String" ; args[3] = portNumber + "" ; sigs[3] = "java.lang.String" ; args[4] = databaseAlias; sigs[4] = "java.lang.String" ; args[5] = userName; sigs[5] = "java.lang.String" ; args[6] = userPswd; sigs[6] = "java.lang.String" ;

    mbeanMethod = "makeConnection" ; } else { args = new String[4]; sigs = new String[4];

args[0] = serverName; sigs[0] = "java.lang.String" ; args[1] = portNumber + "" ; sigs[1] = "java.lang.String" ; args[2] = databaseAlias; sigs[2] = "java.lang.String" ; args[3] = userName; sigs[3] = "java.lang.String" ;

1

Page 2 of 4

    mbeanMethod = "getConnection" ; }

connectionID = (String) mbsInvoke(mbeanMethod, args, sigs);

     return connectionID; }

In this example, one can see that the sigs array contains the class name of the associated args array element and that it is prone to typing errors or simply forgetting that the user must provide the full class name qualifier eg java.lang.String for String...

The core of this idea is to provide a JMX convenience method which constructs the datatype siganture list using Java reflection on the arguments list.

private Object mbsInvoke( String mbeanMethod, Object[] args ) {

String sigs[] = new String[args.length];

// populate the sigs array with datatypes of associated args elements for(int i...