3 Replies Latest reply: Aug 20, 2013 11:31 AM by HarveyRaja RSS

    How to extract a field from Binary object

    1028528

      Hi Guys,

       

      I have a Binary object in custom aggregator and I would like to extract a field from the Binary object without de-serializing the Binary object. I know this can be done but figure out how.. Appreciate your help.

       

      Have tried this

      PofValue value = PofValueParser.parse(Binary, (PofContext) BinaryEntry.getSerializer());

       

      PofValue child = value.getChild(1);

       

      Object value = child1.getValue();

       

      but no luck.

       

      Thanks

      D

        • 1. Re: How to extract a field from Binary object
          Jonathan.Knight

          Hi

           

          There are a few ways to do this depending on what values you have at the point you execute the code. Your code above suggests you have a BinaryEntry so, assuming the field you want to extract has the POF ID of 1 then...

           

          PofExtractor extractor = new PofExtractor(null, 1);

          Object value = binaryEntry.extract(extractor);

           

          If you just have a Binary and a POF Context (serializer) and not a BinaryEntry then...

           

          PofValue pofValue = PofValueParser.parse(binary, pofContext);

          PofNavigator path = new SimplePofPath(1);

          PofValue target = path.navigate(pofValue);

          Object value = target != null ? target.getValue() : null;

           

          JK

          • 2. Re: How to extract a field from Binary object
            1028528

            Hi JK,

             

            Thanks..  I have Binary  and tried

            PofValue pofValue = PofValueParser.parse(binary, pofContext);

            PofNavigator path = new SimplePofPath(1);

            PofValue target = path.navigate(pofValue);

            Object value = target != null ? target.getValue() : null;

             

            but no luck.. I must be missing something.

             

            Basically, am trying to do cache joins using aggregator and data affinity. Sample code snippet

            @Override

              public Object aggregate(Set values) {

              List extractedValues = new ArrayList();

              for (Map.Entry entry : (Set<Map.Entry>)values) { 

               try {

                //these are BinaryEntries in TESTCACHE1

                BinaryEntry binaryEntry = (BinaryEntry)entry;  

                Long compId = (Long)binaryEntry.extract(new KeyExtractor("getComponentId")); 

                Long contId = (Long)binaryEntry.extract(new KeyExtractor("getPartyId"));

                  

                BackingMapContext backingMapContext = binaryEntry.getContext().getBackingMapContext("TESTCACHE2");  

                 

                ObservableMap backingMap = backingMapContext.getBackingMap();

                MapIndex mapIndex = backingMapContext.getIndexMap().get(new KeyExtractor("getComponentId"));   

                com.tangosol.util.InflatableSet keySet = (com.tangosol.util.InflatableSet) mapIndex.getIndexContents().get(compId);

               

                Binary object = null;

                for(Object key : keySet ) { 

                 object = (Binary)backingMap.get(key);    

                }

              

                PofNavigator  path  = new SimplePofPath(2);

                PofValue value = PofValueParser.parse(object,  (PofContext) binaryEntry.getSerializer());

                PofValue  target = path.navigate(value);  

                Object extractedValue = target != null ? target.getValue(): null;

                extractedValues.add(extractedValue);

               } catch (Throwable t) {

                log.error("Exception in aggregate method ", t);

                throw new RuntimeException("Exception in aggregate method", t);

               }

              }

              return extractedValues;

               

            }

            • 3. Re: How to extract a field from Binary object
              HarveyRaja

              Hi, Are you witnessing an exception or unexpected behaviour / result? Looking at your code looks like you may want the curly brace moved further down where you iterate the keySet. Thanks, Harvey