mirror of
https://github.com/corda/corda.git
synced 2025-01-18 02:39:51 +00:00
CORDA-1820: Reduce amount of logging/lookup performed by SerializerFactory.findCustomSerializer() (#3633)
* CORDA-1820: Reduce amount of logging/lookup performed by SerializerFactory.findCustomSerializer() * CORDA-1820: Changes to make DJVM work.
This commit is contained in:
parent
dafd979bde
commit
7e3687c306
@ -21,6 +21,7 @@ private class DeterministicSerializerFactoryFactory : SerializerFactoryFactory {
|
||||
serializersByType = mutableMapOf(),
|
||||
serializersByDescriptor = mutableMapOf(),
|
||||
customSerializers = ArrayList(),
|
||||
customSerializersCache = mutableMapOf(),
|
||||
transformsCache = mutableMapOf()
|
||||
)
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ import javax.annotation.concurrent.ThreadSafe
|
||||
data class SerializationSchemas(val schema: Schema, val transforms: TransformsSchema)
|
||||
@KeepForDJVM
|
||||
data class FactorySchemaAndDescriptor(val schemas: SerializationSchemas, val typeDescriptor: Any)
|
||||
@KeepForDJVM
|
||||
data class CustomSerializersCacheKey(val clazz: Class<*>, val declaredType: Type)
|
||||
|
||||
/**
|
||||
* Factory of serializers designed to be shared across threads and invocations.
|
||||
@ -56,6 +58,7 @@ open class SerializerFactory(
|
||||
private val serializersByType: MutableMap<Type, AMQPSerializer<Any>>,
|
||||
val serializersByDescriptor: MutableMap<Any, AMQPSerializer<Any>>,
|
||||
private val customSerializers: MutableList<SerializerFor>,
|
||||
private val customSerializersCache: MutableMap<CustomSerializersCacheKey, AMQPSerializer<Any>?>,
|
||||
val transformsCache: MutableMap<String, EnumMap<TransformTypes, MutableList<Transform>>>,
|
||||
private val onlyCustomSerializers: Boolean = false
|
||||
) {
|
||||
@ -74,6 +77,7 @@ open class SerializerFactory(
|
||||
ConcurrentHashMap(),
|
||||
CopyOnWriteArrayList(),
|
||||
ConcurrentHashMap(),
|
||||
ConcurrentHashMap(),
|
||||
onlyCustomSerializers
|
||||
)
|
||||
|
||||
@ -377,6 +381,13 @@ open class SerializerFactory(
|
||||
}
|
||||
|
||||
internal fun findCustomSerializer(clazz: Class<*>, declaredType: Type): AMQPSerializer<Any>? {
|
||||
return customSerializersCache.computeIfAbsent(CustomSerializersCacheKey(clazz, declaredType), ::doFindCustomSerializer)
|
||||
}
|
||||
|
||||
private fun doFindCustomSerializer(key: CustomSerializersCacheKey): AMQPSerializer<Any>? {
|
||||
|
||||
val (clazz, declaredType) = key
|
||||
|
||||
// e.g. Imagine if we provided a Map serializer this way, then it won't work if the declared type is
|
||||
// AbstractMap, only Map. Otherwise it needs to inject additional schema for a RestrictedType source of the
|
||||
// super type. Could be done, but do we need it?
|
||||
@ -389,7 +400,7 @@ open class SerializerFactory(
|
||||
|| !customSerializer.isSerializerFor(declaredSuperClass)
|
||||
|| !customSerializer.revealSubclassesInSchema
|
||||
) {
|
||||
logger.info ("action=\"Using custom serializer\", class=${clazz.typeName}, " +
|
||||
logger.debug("action=\"Using custom serializer\", class=${clazz.typeName}, " +
|
||||
"declaredType=${declaredType.typeName}")
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
Loading…
Reference in New Issue
Block a user