mirror of
https://github.com/corda/corda.git
synced 2024-12-19 21:17:58 +00:00
ENT-2848 Put some caching back into serialization transforms lookup. (#4397)
* Attempt to put some caching back into transforms lookup. Cleanup for PR after testing. * Match spacing in OS. * Avoid checking two caches.
This commit is contained in:
parent
4799df9b80
commit
85102fa0e5
@ -53,6 +53,13 @@ interface LocalSerializerFactory {
|
||||
*/
|
||||
fun getTypeInformation(type: Type): LocalTypeInformation
|
||||
|
||||
/**
|
||||
* Obtain [LocalTypeInformation] for the [Type] that has the given name in the [ClassLoader] associated with this factory.
|
||||
*
|
||||
* @return null if the type with the given name does not exist in the [ClassLoader] for this factory.
|
||||
*/
|
||||
fun getTypeInformation(typeName: String): LocalTypeInformation?
|
||||
|
||||
/**
|
||||
* Use the [FingerPrinter] to create a type descriptor for the given [type].
|
||||
*/
|
||||
@ -84,12 +91,24 @@ class DefaultLocalSerializerFactory(
|
||||
}
|
||||
|
||||
private val serializersByType: MutableMap<TypeIdentifier, AMQPSerializer<Any>> = DefaultCacheProvider.createCache()
|
||||
private val typesByName = DefaultCacheProvider.createCache<String, Optional<LocalTypeInformation>>()
|
||||
|
||||
override fun createDescriptor(typeInformation: LocalTypeInformation): Symbol =
|
||||
Symbol.valueOf("$DESCRIPTOR_DOMAIN:${fingerPrinter.fingerprint(typeInformation)}")
|
||||
|
||||
override fun getTypeInformation(type: Type): LocalTypeInformation = typeModel.inspect(type)
|
||||
|
||||
override fun getTypeInformation(typeName: String): LocalTypeInformation? {
|
||||
return typesByName.getOrPut(typeName) {
|
||||
val localType = try {
|
||||
Class.forName(typeName, false, classloader)
|
||||
} catch (_: ClassNotFoundException) {
|
||||
null
|
||||
}
|
||||
Optional.ofNullable(localType?.run { getTypeInformation(this) })
|
||||
}.orElse(null)
|
||||
}
|
||||
|
||||
override fun get(typeInformation: LocalTypeInformation): AMQPSerializer<Any> =
|
||||
get(typeInformation.observedType, typeInformation)
|
||||
|
||||
|
@ -257,12 +257,7 @@ data class TransformsSchema(val types: Map<String, EnumMap<TransformTypes, Mutab
|
||||
*/
|
||||
fun build(schema: Schema, sf: LocalSerializerFactory): TransformsSchema {
|
||||
val transformsMap = schema.types.asSequence().mapNotNull { type ->
|
||||
val localType = try {
|
||||
sf.classloader.loadClass(type.name)
|
||||
} catch (_: ClassNotFoundException) {
|
||||
return@mapNotNull null
|
||||
}
|
||||
val localTypeInformation = sf.getTypeInformation(localType)
|
||||
val localTypeInformation = sf.getTypeInformation(type.name)
|
||||
if (localTypeInformation is LocalTypeInformation.AnEnum) {
|
||||
localTypeInformation.transforms.source.let {
|
||||
if (it.isEmpty()) null else type.name to it
|
||||
|
Loading…
Reference in New Issue
Block a user