4

I'm storing some information inside a MbGlobalMap (embedded Global Cache) of the IBM Integration Bus. If the map is called EXAMPLE.MAP I can access the values as follows:

MbGlobalMap map = MbGlobalMap.getGlobalMap("EXAMPLE.MAP");
Object value = map.get(key);

But I want to get all values of the EXAMPLE.MAP, even if I don't know all keys of the map. I can't iterate over the MbGlobalMap and a cast to java.util.Map won't work at all.

This is the documentation of the Class: https://www.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.plugin.doc/com/ibm/broker/plugin/MbGlobalMap.html. There is no method provided, to return all elements inside the Map.

A workaround could be a list with all current keys in it, so that you can get this list and with it you can get all values inside the map. But this is not a clean solution I think.

Vladimir Vagaytsev
  • 2,871
  • 9
  • 33
  • 36
Yannick
  • 663
  • 1
  • 10
  • 33

3 Answers3

5

After some time of research, I want to give an answer to this question by myself:

The solution is the workaround i mentioned in my question. You can put a Java HashMap into the Global Cache and write all your Objects into this Map. An example would look something like the following:

MbGlobalMap globalMap = MbGlobalMap.getGlobalMap("EXAMPLE.MAP");
HashMap<String,Object> map = new HashMap<String,Object>();
// Put some objects into the map
globalMap.put("ALL", map);

Now you have a Java HashMap inside the MbGlobalMap of the Global Cache and you can access the data, without knowing the keys as follows:

MbGlobalMap globalMap = MbGlobalMap.getGlobalMap("EXAMPLE.MAP");
HashMap<String,Object> map = (HashMap<String,Object>)globalMap.get("ALL");
Set<String> allKeys = map.keySet();
Iterator<String> iter = allKeys.iterator();

while(iter.hasNext()) {
    // Do something with map.get(iter.next());
}

First I thought, this solution would not be a clean one, because now the Map has to be locked for every write operation. But it seems, that the Global Cache will lock the Map for every write operation anyway:

As JAMESHART mentioned it at his contribution at IBM developerWorks, the Extreme Scale Grid under the Global Cache is configured with pessimistic locking strategy. According to the entry in the IBM Knowledge Center, this means the following:

Pessimistic locking: Acquires locks on entries, then and holds the locks until commit time. This locking strategy provides good consistency at the expense of throughput.

So the use of the described workaround won't have such a big impact on write access and performance.

Yannick
  • 663
  • 1
  • 10
  • 33
3

There's now an enhancement request on IBM's Community RFE website in order to get this feature:

http://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=94875

Please give your vote for this request if you are interested in this feature, because IBM considers ERs based on their votes.

thorstenhirsch
  • 199
  • 3
  • 14
0

Arcdic , the best way with the API at hand will be to use the putAll that takes in a java.util.Map , then use an EntrySet to get values that you are interested in.

public void putAll(Map m) throws MbException

Ramachandran.A.G
  • 4,788
  • 1
  • 12
  • 24
  • Thanks for the quick answer. The `putAll()` function of `MbGlobalMap` won't store an object of `java.util.Map` to the global cache but all entries of it. "Puts all the entries in the supplied Map into this map."(Source: [link](https://www.ibm.com/support/knowledgecenter/SSKM8N_8.0.0/com.ibm.etools.mft.plugin.doc/com/ibm/broker/plugin/MbGlobalMap.html)) – Yannick Aug 26 '16 at 14:55
  • My bad , i had to re-read the question again. The only way i could think of was to see if there are any MQSI commands available or if there are REST endpoints for it. Both do not exist. So you will have to roll up something custom here i guess. – Ramachandran.A.G Aug 26 '16 at 16:41
  • Yes, a mqsi command for reading even all the global cache content would be great. I will proof if there maybe is a soultion on extreme scale grid level. Otherwise I will build a workaround here. – Yannick Aug 27 '16 at 08:07