Maintaining states or session accross JMX invocations

I am invoking an operation which performs a database query. At each invocation a new resultSet is formed. Is there a way to maintain a session kind of a thing in JMX invocations, so that I can use the same rs for different invocations.

( I am new to JMX terminoloy... I hope I am not absurdly vague)

Thanks

[325 byte] By [lalit_mangala] at [2007-10-3 3:33:08]
# 1

Support for some kind of "sessions" is being considered for the next version of the JMX API (version 2.0); see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6323764 for details.

In the meantime, you could consider defining your MBean's interface something like this:

public interface DatabaseMBean {

public String query(...parameters...);

public Object[] nextRow(String queryId);

public void endQuery(String queryId);

...

}

The idea is that you issue the query, which returns you a String that you can then use with successive nextRow calls to retrieve each row of the result. The MBean will have an internal Map<String,ResultSet> so it can manage this. Or you might copy the values out of the ResultSet and into a local object, to prevent your database query being too long-lived.

Instead of a String you could use a long or whatever -- the point is that this will be a sort of opaque token that the caller can use to indicate what context it is talking about.

The principal difficulty here is making sure you can clean up if the caller goes away without ever calling endQuery. The easiest way to do this is to require the caller to make all its nextRow calls within a certain time, say N seconds. N might be a parameter to the query operation. You can use a java.util.Timer or a java.util.concurrent.ScheduledExectorService to handle this -- after N seconds it will automatically remove the entry from the Map and perform any associated cleanup.

emcmanusa at 2007-7-14 21:27:28 > top of Java-index,Core,Monitoring & Management...