6 Replies Latest reply on Mar 3, 2014 3:13 PM by jrcheenu

    How to register advanced externalizer from app

    kristjan273

      Hi,

       

      this question is not high priority to me but I still wonder how to use the tech as it seems to be available (and is cool). So, in my app I use all infinispan caches with simple externalizers serialization pattern.

      I have tried to upgrade to advanced but don't see the way to register the advanced externalizer to container. Have checked some src on as7 but the usage there is a little to advanced (eq. from AS-4706).

       

      May I ask for some example how to use this (if it is possible to use at all, of course ...)

       

      tnx in advance & brg

        • 1. Re: How to register advanced externalizer from app
          alesj

          So you want to register custom externalizer against your cache?

          How do you get a hold of the cache?

          • 2. Re: How to register advanced externalizer from app
            kristjan273

            Here is how I handle the caches:

             

             

            @Singleton
            public class Resources {
            
                @SuppressWarnings("all")
                @Produces
                @Resource(mappedName = "java:jboss/infinispan/container/msdp-cluster")
                private static EmbeddedCacheManager mecm;
            
                @MsdpClusterCache
                @Produces
                @SuppressWarnings("all")
                public AdvancedCache getMsdpClusterCache() {
            
                    // Configuration c1 = new ConfigurationBuilder().clustering().cacheMode(CacheMode.DIST_SYNC).hash().numOwners(2)
                    // .jmxStatistics().build();
                    //
                    // mecm.defineConfiguration("MsdpClusterCache", c1);
                    
                    
                    GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder();
                    builder.serialization().addAdvancedExternalizer(5001, new MessageNewIndex.MessageNewIndexExternalizer());        
            
                    return mecm.getCache("MsdpClusterCache").getAdvancedCache();
            
                }
            

             

            the commented configuration is currently defined in domain.xml.

            I got the idea that registering of externalizer has something to do with GlobalConfigurationBuilder.

            • 3. Re: How to register advanced externalizer from app
              alesj

              "builder" is never used. ;-)

               

              But the Configuration approach looks in the right direction,

              as that's what I also use in CapeDwarf -- a lot of custom cache configs.

               

              I'll check how to apply externalizers to config, global or per-cache.

              • 4. Re: How to register advanced externalizer from app
                galder.zamarreno

                The problem is that the AS7 Infinispan susbsystem does not yet allow for advanced externalizers to be configured. So, to configure them, you have to skip defining it in the cache container, and create a cache manager instance yourself, and pass the global config builder with the advanced externalizer, and any other parameters, such as transport, if you're clustering it...etc.

                • 5. Re: How to register advanced externalizer from app
                  galder.zamarreno

                  But to be honest, this is probably quite a lot more work that you're expected to do. You can use the user friendly externalizers as explained in https://docs.jboss.org/author/x/PwY5 without problems.

                  • 6. Re: How to register advanced externalizer from app
                    jrcheenu

                    public void registerExternalizer(Map<Integer,Serializable> classnames) throws IllegalArgumentException

                        {

                         boolean hasInvalidArg = false;  

                         StringBuffer invalidclassNames =new StringBuffer();

                         Set<Integer> keys = classnames.keySet();

                        for(Iterator iterator = keys.iterator(); iterator.hasNext();)

                        {

                            Integer key = (Integer)iterator.next();

                            Serializable classname  =classnames.get(key);

                           

                               

                              if(classname instanceof AdvancedExternalizer){

                                

                                GlobalConfiguration gc =  cacheManager.getGlobalComponentRegistry().getGlobalConfiguration();

                                GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder().read(gc).nonClusteredDefault();

                               

                                gcb.serialization().addAdvancedExternalizer(key,(AdvancedExternalizer)classname);

                                gcb.build();

                               }

                              else

                              {

                                  hasInvalidArg = true;

                                  invalidclassNames.append(classname + "  ");

                                 

                              }

                             

                        }

                          if(hasInvalidArg){

                              throw new IllegalArgumentException("The following class is not instance of AdvancedExternalizer.So Cant Register it as Externalizer.  " + invalidclassNames.toString());

                          }

                          

                           

                        }

                    }

                     

                    I used this to register externalizer and exposed the interface to client.