3 Replies Latest reply: Mar 18, 2013 9:55 AM by Jonathan.Knight RSS

    Accessing Backing Map From ValueExtractor


      Any suggestions/possible ways to access backing map from ValueExtractor without passing InvocableMap.Entry object to it or alike? Is ValueExtractor in any way able to make itself aware about the cluster/cache it is executed in?

      Ultimately trying to make this get() work (just like in EntryProcessor, where entry is on hand):

                          BackingMapManagerContext ctx = ((BinaryEntry) entry).getContext();
                          BackingMapManagerContext ctx2 = ctx.getBackingMapContext("SomeCache").getManagerContext();
                          Binary MyObject = (Binary) childCache.get(ctx2.getKeyToInternalConverter().convert("SomeObject"));
        • 1. Re: Accessing Backing Map From ValueExtractor

          If you make your ValueExtractor extend com.tangosol.util.extractor.EntryExtractor then you can override the extractFromEntry() method that will be passed the entry for you to extract data from. As this is likely to be a BinaryEntry for a distributed cache you can use the code you have posted inside that extractor.

          I assume you are using some form of Key Association to make sure that the Binary key returned by ctx2.getKeyToInternalConverter().convert("SomeObject") is actually located in the same partition as the key of the entry being extracted - otherwise the code will not work.

          • 2. Re: Accessing Backing Map From ValueExtractor
            Thanks, Jonathan.

            Yes, those objects are guaranteed to be on the same node.

            Would extending EntryExtractor (your way) make more sense (work faster) then something like this in regular ValueExtractor:

                      BackingMapManagerContext ctx = ((com.tangosol.net.DistributedCacheService)CacheFactory.getService("")).getBackingMapManager().getContext();
                      Map childCache = ctx.getBackingMapContext(RflxCaches.RflxRiskCache).getBackingMap();
                      Binary MyObject = (Binary) childCache.get(ctx.getKeyToInternalConverter().convert("SomeObject"));
            • 3. Re: Accessing Backing Map From ValueExtractor

              Yes, it would make more sense to extend EntryExtractor as you are given a BinaryEntry so you can access backing maps etc very easily. Personally I think calling the static CacheFactory methods should be avoided as much as possible. For example, how would you unit test your code that uses CacheFactory.get*() methods? Assuming you do unit testing of course. And yes, I know there are mock frameworks that allow you to mock statics but they are the spawn of the devil and also best avoided.