Class DefaultModelMapperSerializer
java.lang.Object
com.broadleafcommerce.data.tracking.core.mapping.cache.DefaultModelMapperSerializer
- All Implemented Interfaces:
ModelMapperSerializer,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanClassLoaderAware
public class DefaultModelMapperSerializer
extends Object
implements ModelMapperSerializer, org.springframework.beans.factory.BeanClassLoaderAware
Default version of
ModelMapperSerializer- Author:
- Jeff Fischer
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultModelMapperSerializer(DomainMapperMember domainMapperMember, DomainMapperManager domainMapperManager, ResourceProvider resourceProvider, com.broadleafcommerce.common.extension.TypeFactory typeFactory, KryoCustomizer kryoCustomizer, com.broadleafcommerce.common.extension.data.DataRouteReference reference, ModelMapperCacheProperties properties) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendAnyMissingClasses(String dumpDir, DynamicClassContext context) Review the dump dir and add any pertinent dynamic classes that may have been missed during class resolution at the time of serialization.protected voidcompileMappers(Class<?>[] entities) UsingModelMapperDomainMapperMember, exercise the system to createModelMapperinstances for the requested entities.protected voidcurateMapper(org.modelmapper.ModelMapper mapper) Process the ModelMapper before populating in the cacheorg.modelmapper.ModelMapperdeserialize(com.esotericsoftware.kryo.kryo5.Kryo kryo, byte[] serialized) Given a byte array representation of aModelMapperinstance, deserialize into a concrete instance usingKryo.voidgenerateCacheResources(Class<?>[] entities) A rich lifecycle method, calls will generateModelMapperinstances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitledmappers.zip.voidgenerateCacheResources(Class<?>[] entities, boolean hashShapes) A rich lifecycle method, calls will generateModelMapperinstances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitledmappers.zip.protected com.broadleafcommerce.data.tracking.core.mapping.cache.DefaultModelMapperSerializer.ClassFilegetDumpFile(String dumpDir, String[] files, String packageName, String simpleName) If the system detects a dynamic class required during serialization, retrieve it from the dump location used by ByteBuddy.Create a hash uniquely identifying the class structure, including fields and types in the object graph.protected voidInject all classes in classes.zip into the classloadervoidloadCacheResources(Class<?>[] entities) A rich lifecycle method, calls will readModelMapperserialized files frommappers.zipfor the specified entities, deserialize those ModelMappers, and inject those mappers into cache upon application startup.protected voidloadModelMappers(Class<?>[] entities) Load ModelMapper instances form mappers.zip and put in the cachebyte[]serialize(com.esotericsoftware.kryo.kryo5.Kryo kryo, org.modelmapper.ModelMapper mapper) Serialize theModelMapperinstance to a byte array - presumably to save to a file.protected voidserializeResources(Class<?>[] entities, boolean hashShape) Serialize the ModelMapper instances and required classes and put to mappers.zip and classes.zip by default.voidsetBeanClassLoader(ClassLoader classLoader) voidsetObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) voidsetProjectionFactory(com.broadleafcommerce.common.extension.projection.ProjectionFactory projectionFactory) com.esotericsoftware.kryo.kryo5.KryoCreate aKryoinstance and perform the initial setup.
-
Constructor Details
-
DefaultModelMapperSerializer
public DefaultModelMapperSerializer(DomainMapperMember domainMapperMember, DomainMapperManager domainMapperManager, ResourceProvider resourceProvider, com.broadleafcommerce.common.extension.TypeFactory typeFactory, KryoCustomizer kryoCustomizer, com.broadleafcommerce.common.extension.data.DataRouteReference reference, ModelMapperCacheProperties properties)
-
-
Method Details
-
setBeanClassLoader
- Specified by:
setBeanClassLoaderin interfaceorg.springframework.beans.factory.BeanClassLoaderAware
-
setup
Description copied from interface:ModelMapperSerializerCreate aKryoinstance and perform the initial setup. SeeKryoCustomizer.- Specified by:
setupin interfaceModelMapperSerializer- Parameters:
entities- The list of entities registered in the ORM.- Returns:
- The configured
Kryoinstance.
-
serialize
public byte[] serialize(com.esotericsoftware.kryo.kryo5.Kryo kryo, org.modelmapper.ModelMapper mapper) Description copied from interface:ModelMapperSerializerSerialize theModelMapperinstance to a byte array - presumably to save to a file.- Specified by:
serializein interfaceModelMapperSerializer- Parameters:
kryo- TheKryoinstance to use for serializationmapper- TheModelMapperinstance to serialize- Returns:
- The resulting byte array representing the serialized ModelMapper instance
-
deserialize
public org.modelmapper.ModelMapper deserialize(com.esotericsoftware.kryo.kryo5.Kryo kryo, byte[] serialized) Description copied from interface:ModelMapperSerializerGiven a byte array representation of aModelMapperinstance, deserialize into a concrete instance usingKryo.- Specified by:
deserializein interfaceModelMapperSerializer- Parameters:
kryo- TheKryoinstance to use for deserializationserialized- The serialized model mapper- Returns:
- The resulting ModelMapper instance after deserialization
-
hash
Description copied from interface:ModelMapperSerializerCreate a hash uniquely identifying the class structure, including fields and types in the object graph.- Specified by:
hashin interfaceModelMapperSerializer- Parameters:
entity- The entity class to evaluate- Returns:
- The hash uniquely identifying the current structure of the entity class
-
generateCacheResources
Description copied from interface:ModelMapperSerializerA rich lifecycle method, calls will generateModelMapperinstances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitledmappers.zip. The file is usually saved in the current application's source under the maven resources/cache directory structure. SeeResourceProvider, and concrete implementations, for where and how the mappers.zip file is stored.
A file calledclasses.zipis also created in the same location to hold any additional required classes that are needed to successfully deserialize the ModelMapper instances. These classes are generally injected into the target classloader upon deserialization (seeModelMapperSerializer.loadCacheResources(Class[])).- Specified by:
generateCacheResourcesin interfaceModelMapperSerializer- Parameters:
entities- The entities from which to derive ModelMapper instances for serialization
-
generateCacheResources
Description copied from interface:ModelMapperSerializerA rich lifecycle method, calls will generateModelMapperinstances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitledmappers.zip. The file is usually saved in the current application's source under the maven resources/cache directory structure. SeeResourceProvider, and concrete implementations, for where and how the mappers.zip file is stored.
A file calledclasses.zipis also created in the same location to hold any additional required classes that are needed to successfully deserialize the ModelMapper instances. These classes are generally injected into the target classloader upon deserialization (seeModelMapperSerializer.loadCacheResources(Class[])).- Specified by:
generateCacheResourcesin interfaceModelMapperSerializer- Parameters:
entities- The entities from which to derive ModelMapper instances for serializationhashShapes- Whether or not the mapper cache should include a deep hash of the entity shape. This is useful if the cache archive is separated from the build process and can become stale. Stale cache entries will not match the entity shape at runtime and will not be accidentally included. This value should be false if the cache is always built during project compilation.
-
loadCacheResources
Description copied from interface:ModelMapperSerializerA rich lifecycle method, calls will readModelMapperserialized files frommappers.zipfor the specified entities, deserialize those ModelMappers, and inject those mappers into cache upon application startup.classes.zipis also consulted and classes discovered there are injected into the current classloader prior to attempting deserialization. SeeModelMapperSerializer.generateCacheResources(Class[])for information on how mappers.zip and classes.zip originate.- Specified by:
loadCacheResourcesin interfaceModelMapperSerializer- Parameters:
entities- The entities from which to deserialize ModelMapper instances and populate cache
-
serializeResources
Serialize the ModelMapper instances and required classes and put to mappers.zip and classes.zip by default. Alternatively, ifbroadleaf.modelmapper.cache.generate.useCacheInfis true, the serialized output will instead be put on the classpath at CACHE-INF/modelmapper.- Parameters:
entities- The entities for which ModelMapper instances are being createdhashShape- seegenerateCacheResources(Class[], boolean).
-
appendAnyMissingClasses
Review the dump dir and add any pertinent dynamic classes that may have been missed during class resolution at the time of serialization.- Parameters:
dumpDir- The location where ByteBuddy dumps dynamically created classescontext- The context object containing the dynamic class registrations detected during serialization
-
getDumpFile
protected com.broadleafcommerce.data.tracking.core.mapping.cache.DefaultModelMapperSerializer.ClassFile getDumpFile(String dumpDir, String[] files, String packageName, String simpleName) If the system detects a dynamic class required during serialization, retrieve it from the dump location used by ByteBuddy. SeeModelMapperCacheProperties.getGenerate()#getDumpFile(String, String, String)} for configuration of the location of the dump directory.- Parameters:
dumpDir- The location where ByteBuddy dumps dynamically created classespackageName- The package name for the class filesimpleName- The simple name of the class- Returns:
- Stream to load the class file from disk
-
compileMappers
UsingModelMapperDomainMapperMember, exercise the system to createModelMapperinstances for the requested entities.- Parameters:
entities- The entities for which to generate ModelMapper instances
-
loadModelMappers
Load ModelMapper instances form mappers.zip and put in the cache- Parameters:
entities- The entities for which ModelMappers should be identified
-
curateMapper
protected void curateMapper(org.modelmapper.ModelMapper mapper) Process the ModelMapper before populating in the cache- Parameters:
mapper- The ModelMapper to modify prior to usage
-
injectDynamicClasses
protected void injectDynamicClasses()Inject all classes in classes.zip into the classloader -
setProjectionFactory
@Autowired public void setProjectionFactory(com.broadleafcommerce.common.extension.projection.ProjectionFactory projectionFactory) -
setObjectMapper
@Autowired public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
-