javajmxmbeans

JMX Update TabularData values


My scenario is similar to the following - bear with me here:

I have an mbean that contains one Attribute called "Information". This Attribute's value is represented by an instance of the TabularDataSupport class called "data". "Data" is composed of instances of the CompositeData class.

Each instance of CompositeData obviously requires a CompositeType. This is where I define my "table", which has three pieces of data: name, duration, and id.

Basically, I have 10 uniquely-named processes that occur at a particular interval. I want each of these processes to be represented by a CompositeData object, stored in "data". Everytime the process finishes running, I want to update the duration and id associated with it.

Here's a diagram of my scenario:

Attributes
Name                            Value

Information                     Name        Value
                                name        processA
                                duration    109
                                id          1

Currently, when I want to update the values, I am simply putting a new CompositeData object (with the name, duration, and id) into my "data" object. This works the first time processA, processB, etc. run, but doesn't work after that.

I am using "name" as my index, so I don't know how to simply update the duration and id associated with an existing name. Any help would be appreciated!


Solution

  • Ah, I ended up figuring out a work around. Basically, I have a method that is responsible for updating the CompositeData (which stores the name, process, and id) within my "data" object. I want to check if "data" already contains a CompositeData object whose value for the key that I'm using as the index (in my case, the value for the key "name") matches the value of the key of the CompositeData I'm trying to update. (ex. if I want to update info for "processA", does the value "processA" for the key that matches my index, "name", exist?) If that is the case, I remove that object.

    Then, I go ahead and put my new CompositeData object into the list.

    So basically, you're deleting and re-adding a CompositeData object each time you want to update it, which isn't ideal. Pretty simple though.

    The part that was confusing here is that you need to pass in an array that contains the key(s) you used as your index, even if it's only one key like in my example.