public class DefaultModelMapperSerializer extends Object implements ModelMapperSerializer, org.springframework.beans.factory.BeanClassLoaderAware
ModelMapperSerializer
Constructor and Description |
---|
DefaultModelMapperSerializer(DomainMapperMember domainMapperMember,
DomainMapperManager domainMapperManager,
ResourceProvider resourceProvider,
com.broadleafcommerce.common.extension.TypeFactory typeFactory,
KryoCustomizer kryoCustomizer,
com.broadleafcommerce.common.extension.data.DataRouteReference reference,
ModelMapperCacheProperties properties) |
Modifier and Type | Method and Description |
---|---|
protected void |
appendAnyMissingClasses(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 void |
compileMappers(Class<?>[] entities)
Using
ModelMapperDomainMapperMember , exercise the system to create
ModelMapper instances for the requested entities. |
protected void |
curateMapper(org.modelmapper.ModelMapper mapper)
Process the ModelMapper before populating in the cache
|
org.modelmapper.ModelMapper |
deserialize(com.esotericsoftware.kryo.kryo5.Kryo kryo,
byte[] serialized)
Given a byte array representation of a
ModelMapper instance, deserialize into a
concrete instance using Kryo . |
void |
generateCacheResources(Class<?>[] entities)
A rich lifecycle method, calls will generate
ModelMapper instances for the specified
entities, serialize those ModelMappers, and persist those mappers to disk in a file entitled
mappers.zip . |
protected com.broadleafcommerce.data.tracking.core.mapping.cache.DefaultModelMapperSerializer.ClassFile |
getDumpFile(String dumpDir,
String packageName,
String simpleName)
If the system detects a dynamic class required during serialization, retrieve it from the
dump location used by ByteBuddy.
|
String |
hash(Class<?> entity)
Create a hash uniquely identifying the class structure, including fields and types in the
object graph.
|
protected void |
injectDynamicClasses()
Inject all classes in classes.zip into the classloader
|
void |
loadCacheResources(Class<?>[] entities)
A rich lifecycle method, calls will read
ModelMapper serialized files from
mappers.zip for the specified entities, deserialize those ModelMappers, and inject
those mappers into cache upon application startup. |
protected void |
loadModelMappers(Class<?>[] entities)
Load ModelMapper instances form mappers.zip and put in the cache
|
byte[] |
serialize(com.esotericsoftware.kryo.kryo5.Kryo kryo,
org.modelmapper.ModelMapper mapper)
Serialize the
ModelMapper instance to a byte array - presumably to save to a file. |
protected void |
serializeResources(Class<?>[] entities)
Serialize the ModelMapper instances and required classes to mappers.zip and classes.zip,
respectively.
|
void |
setBeanClassLoader(ClassLoader classLoader) |
com.esotericsoftware.kryo.kryo5.Kryo |
setup(Class<?>[] entities)
Create a
Kryo instance and perform the initial setup. |
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)
public void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader
in interface org.springframework.beans.factory.BeanClassLoaderAware
public com.esotericsoftware.kryo.kryo5.Kryo setup(Class<?>[] entities)
ModelMapperSerializer
Kryo
instance and perform the initial setup. See KryoCustomizer
.setup
in interface ModelMapperSerializer
entities
- The list of entities registered in the ORM.Kryo
instance.public byte[] serialize(com.esotericsoftware.kryo.kryo5.Kryo kryo, org.modelmapper.ModelMapper mapper)
ModelMapperSerializer
ModelMapper
instance to a byte array - presumably to save to a file.serialize
in interface ModelMapperSerializer
kryo
- The Kryo
instance to use for serializationmapper
- The ModelMapper
instance to serializepublic org.modelmapper.ModelMapper deserialize(com.esotericsoftware.kryo.kryo5.Kryo kryo, byte[] serialized)
ModelMapperSerializer
ModelMapper
instance, deserialize into a
concrete instance using Kryo
.deserialize
in interface ModelMapperSerializer
kryo
- The Kryo
instance to use for deserializationserialized
- The serialized model mapperpublic String hash(Class<?> entity)
ModelMapperSerializer
hash
in interface ModelMapperSerializer
entity
- The entity class to evaluatepublic void generateCacheResources(Class<?>[] entities)
ModelMapperSerializer
ModelMapper
instances for the specified
entities, serialize those ModelMappers, and persist those mappers to disk in a file entitled
mappers.zip
. The file is usually saved in the current application's source under the
maven resources/cache directory structure. See ResourceProvider
, and concrete
implementations, for where and how the mappers.zip file is stored.
A file called
classes.zip
is 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 (see
ModelMapperSerializer.loadCacheResources(Class[])
).generateCacheResources
in interface ModelMapperSerializer
entities
- The entities from which to derive ModelMapper instances for serializationpublic void loadCacheResources(Class<?>[] entities)
ModelMapperSerializer
ModelMapper
serialized files from
mappers.zip
for the specified entities, deserialize those ModelMappers, and inject
those mappers into cache upon application startup. classes.zip
is also consulted and
classes discovered there are injected into the current classloader prior to attempting
deserialization. See ModelMapperSerializer.generateCacheResources(Class[])
for information on how
mappers.zip and classes.zip originate.loadCacheResources
in interface ModelMapperSerializer
entities
- The entities from which to deserialize ModelMapper instances and populate
cacheprotected void serializeResources(Class<?>[] entities)
entities
- The entities for which ModelMapper instances are being createdprotected void appendAnyMissingClasses(String dumpDir, DynamicClassContext context)
dumpDir
- The location where ByteBuddy dumps dynamically created classescontext
- The context object containing the dynamic class registrations detected during
serializationprotected com.broadleafcommerce.data.tracking.core.mapping.cache.DefaultModelMapperSerializer.ClassFile getDumpFile(String dumpDir, String packageName, String simpleName)
ModelMapperCacheProperties.getGenerate()
#getDumpFile(String, String, String)} for configuration of the location of the dump
directory.dumpDir
- The location where ByteBuddy dumps dynamically created classespackageName
- The package name for the class filesimpleName
- The simple name of the classprotected void compileMappers(Class<?>[] entities)
ModelMapperDomainMapperMember
, exercise the system to create
ModelMapper
instances for the requested entities.entities
- The entities for which to generate ModelMapper instancesprotected void loadModelMappers(Class<?>[] entities)
entities
- The entities for which ModelMappers should be identifiedprotected void curateMapper(org.modelmapper.ModelMapper mapper)
mapper
- The ModelMapper to modify prior to usageprotected void injectDynamicClasses()
Copyright © 2021. All rights reserved.