4 Replies Latest reply: Apr 9, 2013 11:45 AM by Mfalco-Oracle RSS

    Request for C++ ExtractorProcessor code snippets

    JoeHolder
      Hi,

      Does anyone have any C++ code snippets of using the ExtractorProcessor?

      I'm trying to implement an ExtractorProcessor in C++ - I have created a ValueExtractor and I can create the ExtractorProcessor from that, but the compiler gives me an error when I try to invoke it

      Error     6     error C2665: 'coherence::lang::TypedHandle<T>::TypedHandle' : none of the 4 overloads could convert all the argument types     c:\dcs_systems\test\trunk\ThirdParty\Components\coherence_3_7_1_x86\include\coherence\lang\TypedHolder.hpp     205     D3ContextCache

      This is my call

      int CacheD3ContextRepository::getD3ContextState(int call_id) const
      {
           Integer32::View vKey = Integer32::create(call_id);
           ValueExtractor::View vStateExtractor =
                COH_MANAGED_BOX_EXTRACTOR(Integer32::View, CacheD3Context, getState);
           ExtractorProcessor::Handle vStateFetcher = ExtractorProcessor::create(vStateExtractor);
           Integer32::View vState;// = _cache->invoke(vKey, vStateFetcher);
           return *vState;
      }

      Essentially I have CacheD3Context object but I don't want to read back the whole object just the state field.

      I have been told that something called a 'ReducerAggregator' is a better way of doing this but I haven't been able to find this yet.

      Thanks

      Joe

      Edited by: 841803 on 09-Apr-2013 00:55
        • 1. Re: Request for C++ ExtractorProcessor code snippets
          JoeHolder
          I managed to get it working - I was missing the cast on the return value to from Holder::Object to Integer32::View

          int CacheD3ContextRepository::getD3ContextState(int call_id) const
          {     
               Integer32::View vKey = Integer32::create(call_id);

               ValueExtractor::View vStateExtractor =
                    COH_MANAGED_BOX_EXTRACTOR(Integer32::View, CacheD3Context, getState);

               ExtractorProcessor::Handle vStateFetcher = ExtractorProcessor::create(vStateExtractor);

               Integer32::View vState = cast<Integer32::View>(_cache->invoke(     vKey,
                                                                           vStateFetcher));
               
               if (vState != NULL)
               {
                    return *vState;
               }
               else
               {
                    return -1;
               }
          }

          Any C++ code snippets still greatfully received though!
          • 2. Re: Request for C++ ExtractorProcessor code snippets
            Mfalco-Oracle
            Hi Joe,

            The invoke method returns an Object::Holder, which will need to be cast to the extracted type:
            int CacheD3ContextRepository::getD3ContextState(int call_id) const
                {
                Integer32::View              vKey            = Integer32::create(call_id);
                ValueExtractor::View         vStateExtractor = COH_MANAGED_BOX_EXTRACTOR(Integer32::View, CacheD3Context, getState);
                ExtractorProcessor::Handle   vStateFetcher   = ExtractorProcessor::create(vStateExtractor);
                Integer32::View              vState          = cast<Integer32::View>(_cache->invoke(vKey, vStateFetcher));
            
                return *vState;
                }
            Note that when the extraction will be performed server side, the above extractor will be evaluated as a ReflectionExtractor in java, and will invoke the java getState method. This implies you'll need the CacheD3Context (or equivalent) java class in the classpath of your cache servers. If this is not an option then have a look at PofExtractor.

            thanks,

            Mark
            Oracle Coherence
            • 3. Re: Request for C++ ExtractorProcessor code snippets
              JoeHolder
              Hi Mark,

              thanks for that. At present we have a java class and it is working ok I will have to look at POF Extractor too I guess. Is there anyway of determining which approach is best for us? Assuming that the overhead of creating the Java classes is acceptable would I still use this approach (reflectionextractor on server) over PofExtraction?

              Thanks

              Joe
              • 4. Re: Request for C++ ExtractorProcessor code snippets
                Mfalco-Oracle
                Hi Joe,

                There are trade-offs between the two. The primary functional difference is that the PofExtractor can only even be evaluated server side, so it is unsuitable for using as the filter on a C++ ContinuousQueryCache. Assuming server side evaluation and the availability of a java class pof extractor is generally faster for very complex objects hierarchies, and slower (then reflection extractor) for small/simple object hierarchies. So When given the choice between the two performance testing is a good idea. Also and irrespective of which you choose, if there are certain properties you extract regularly it is worth indexing them (NamedCache::addIndex) this will consume more memory server side but will also remove the extraction cost, as the extractor will only be applied on updates.

                thanks,

                Mark
                Oracle Coherence