All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.factories.MarshallerFactory Maven / Gradle / Ivy

There is a newer version: 9.1.7.Final
Show newest version
package org.infinispan.factories;

import org.infinispan.factories.annotations.DefaultFactoryFor;
import org.infinispan.commons.CacheException;
import org.infinispan.commons.marshall.Marshaller;
import org.infinispan.commons.marshall.StreamingMarshaller;
import org.infinispan.marshall.core.CacheMarshaller;
import org.infinispan.marshall.core.GlobalMarshaller;
import org.infinispan.marshall.core.VersionAwareMarshaller;

import static org.infinispan.factories.KnownComponentNames.*;

/**
 * MarshallerFactory.
 *
 * @author Galder Zamarreño
 * @since 4.0
 */
@DefaultFactoryFor(classes = {StreamingMarshaller.class, Marshaller.class})
public class MarshallerFactory extends NamedComponentFactory implements AutoInstantiableFactory {

   @Override
   public  T construct(Class componentType, String componentName) {
      Object comp;
      Marshaller configMarshaller =
            globalConfiguration.serialization().marshaller();
      boolean isVersionAwareMarshaller =
            configMarshaller instanceof VersionAwareMarshaller;

      if (isVersionAwareMarshaller) {
         if (componentName.equals(GLOBAL_MARSHALLER))
            comp = new GlobalMarshaller((VersionAwareMarshaller) configMarshaller);
         else if (componentName.equals(CACHE_MARSHALLER))
            comp = new CacheMarshaller(new VersionAwareMarshaller());
         else
            throw new CacheException("Don't know how to handle type " + componentType);
      } else {
         comp = configMarshaller;
      }

      try {
         return componentType.cast(comp);
      } catch (Exception e) {
         throw new CacheException("Problems casting bootstrap component " + comp.getClass() + " to type " + componentType, e);
      }
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy