jolokia / jolokia

JMX on Capsaicin
https://www.jolokia.org
Apache License 2.0
816 stars 223 forks source link

Add support for custom MBean "ifModified" handling #77

Open rhuss opened 11 years ago

rhuss commented 11 years ago

Since the list operation on Jolokia is quite expensive (or can be quite expensive), adding a new query parameter ifModified (or so) should be added. This parameter has a handle which was returned from a previous list call (still to think how to integrate it into the handle into the response, probably an extra field 'handle' in the response itself). The Jolokia agent (or more specific, the ListHandler) listens for notifications about MBeans added or removed and increases the handle/counter internally.

For a request with ifModified parameter it

The same could be implemented for search, too, however this request shouldn't as expensive as list so it is probably not needed here.

rhuss commented 11 years ago

Maybe even better: Use the standard HTTP-Header If-Modified-Since instead of an extra query paramter and use a real HTTP return code.

Advantages:

Disadvantages:

Especially because of bulk requests, a query options / processing parameter is more suitable.

rhuss commented 11 years ago

The parameter should probably called 'ifModifiedSince' and the handle should be the timestamp as it is returned with every response, so there is no need to add an extra key to the response.

rhuss commented 11 years ago

The core functionality for the LIST operation has been implemented (and soon also for SEARCH). BTW, this works for all MBeanServers present in the JVM, not only for a single MBeanServer. However, I wonder whether this feature could be even expanded for other kinds of operations. In fact, I could imagine, that when the parameter ifModifiedSince is given for a READ or EXEC request and the MBean to be called has exposed an operation

boolean hasModifiedSince(long timestamp,String operationType,String name,Object[] args)

then this operation will be called with the timestamp given in the request. If this operation return true nothing changes and the request processing continues as usual. If it returns false then the client gets a 304 - Not Modified response with no value. That way, expensive operation (in time and/or size) can be easily optimized without much extra work.

Then, when using the JavaScript scheduler and using a new option onlyIfChanged when registering the job, the callback functions will only be called when something has changed (this will all be done transparently under the hoods):

jolokia.register({sucess: cbFunc, onlyIfChanged: true}, request);

Is this something useful or is optimizing the list (which is indeed an expensive operation) sufficient and I should avoid the extra complexity for checking MBean freshness ?

rhuss commented 11 years ago

The Javascript Scheduler has been updated, so that the described functionality works now, i.e. that a callback is only called when the servers returns an value-response.

Still open:

rhuss commented 9 years ago

Maybe one should move the open task out of this issue since most of the stuff has been already implemented ?