Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jolokia Java Client - ReadRequest optional #173

Closed
davsclaus opened this issue Dec 23, 2014 · 4 comments
Closed

Jolokia Java Client - ReadRequest optional #173

davsclaus opened this issue Dec 23, 2014 · 4 comments
Milestone

Comments

@davsclaus
Copy link

@davsclaus davsclaus commented Dec 23, 2014

Hi

Jolokia version used: 1.2.3

I coud not find in the reference manual or java doc whether the java client supports optional reads. And by that I mean, a ReadRequest where the mbean may not exists. And if the mbean does not exists I just want a response back with an indicator that the mbean didnt exists.

Today I had to add a try .. catch hack, or I would need to do a list call first to see if the mbean is there, and then etc. But I would love if there was a read optional. Then I can use that as well in a List call so I can do a bulk operation.

For an example see the source code of Apache Camel where we have a jolokia command module

I have these 3 mbeans I need to get information from
https://github.com/apache/camel/blob/master/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/DefaultJolokiaCamelController.java#L117

And then this 4th mbean is optional, so I need to do a separate call to handle if it does not exists
https://github.com/apache/camel/blob/master/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/DefaultJolokiaCamelController.java#L148

@rhuss
Copy link
Owner

@rhuss rhuss commented Dec 23, 2014

I think it can be easily added client-wise for bulk requests. The plain JSON response already contains all responses, with 404 errors for MBeans which where not found. So all what have to be done is to filter or transform the list accordingly.

To make it more flexible, I consider an addition to the API

public <R extends J4pResponse<T>,T extends J4pRequest> List<R> 
     execute(List<T> pRequests,J4pResponseExtractor pExtractor)

where J4pResponseExtractor is used to convert the individual JSON response object for a request to the corresponding J4pResponse object. By default, in case of an error, an exception is raised, but one could easily provide a J4P_OPTIONAL_RESPONSE_EXTRACTOR constant which converts errors with an status code of 404 to null values, so at the end you get back a list, which contains null elements for missing MBeans (and/or missing attributes).

What do you think ?

@davsclaus
Copy link
Author

@davsclaus davsclaus commented Dec 23, 2014

+1

sounds good. This gives much flexibility with the extractor.

rhuss added a commit that referenced this issue Dec 23, 2014
rhuss added a commit that referenced this issue Dec 23, 2014
@rhuss
Copy link
Owner

@rhuss rhuss commented Dec 23, 2014

Just implemented that thinggy.

It can be used in two ways:

  • Either as an extra argument to j4pclient.execute(...)
  • Or when using the builder to set a default response extractor builder.responseExtractor().

A sample usage looks like:

  J4pClient j4p = J4pClient.url("...")
                           .responseExtractor(ValidatingResponseExtractor.OPTIONAL)
                           .build();

A missing MBean now simply leaves a null in the returned list (instead of throwing an exception).

You can try the code from branch 173-response-extractor or (soon) via using 1.2.4-SNAPSHOT from maven central.

@rhuss rhuss added this to the 1.3.0 milestone Jan 10, 2015
@rhuss
Copy link
Owner

@rhuss rhuss commented Jan 10, 2015

Merged to master.

@rhuss rhuss closed this Jan 10, 2015
@rhuss rhuss modified the milestones: 1.2.4, 1.3.0 May 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.