mirror of
https://github.com/corda/corda.git
synced 2025-01-31 00:24:59 +00:00
ENT-9837 Use a cache to avoid resolving contract class name for a contract state repeatedly. (#7348)
This commit is contained in:
parent
32326a168f
commit
f4917e08e1
@ -82,6 +82,7 @@ def patchCore = tasks.register('patchCore', Zip) {
|
|||||||
exclude 'net/corda/core/serialization/internal/CheckpointSerializationFactory*.class'
|
exclude 'net/corda/core/serialization/internal/CheckpointSerializationFactory*.class'
|
||||||
exclude 'net/corda/core/internal/rules/*.class'
|
exclude 'net/corda/core/internal/rules/*.class'
|
||||||
exclude 'net/corda/core/internal/utilities/PrivateInterner*.class'
|
exclude 'net/corda/core/internal/utilities/PrivateInterner*.class'
|
||||||
|
exclude 'net/corda/core/internal/ContractStateClassCache*.class'
|
||||||
}
|
}
|
||||||
|
|
||||||
reproducibleFileOrder = true
|
reproducibleFileOrder = true
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package net.corda.core.internal
|
||||||
|
|
||||||
|
import net.corda.core.contracts.ContractState
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
object ContractStateClassCache {
|
||||||
|
@Suppress("UNUSED_PARAMETER")
|
||||||
|
fun contractClassName(key: Class<ContractState>): String? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("UNUSED_PARAMETER")
|
||||||
|
fun cacheContractClassName(key: Class<ContractState>, contractClassName: String?): String? {
|
||||||
|
return contractClassName
|
||||||
|
}
|
||||||
|
}
|
@ -28,15 +28,19 @@ val Attachment.contractVersion: Version get() = if (this is ContractAttachment)
|
|||||||
* one and it inherits from [Contract].
|
* one and it inherits from [Contract].
|
||||||
*/
|
*/
|
||||||
val ContractState.requiredContractClassName: String? get() {
|
val ContractState.requiredContractClassName: String? get() {
|
||||||
val annotation = javaClass.getAnnotation(BelongsToContract::class.java)
|
return ContractStateClassCache.contractClassName(this.javaClass) ?: let {
|
||||||
if (annotation != null) {
|
val annotation = javaClass.getAnnotation(BelongsToContract::class.java)
|
||||||
return annotation.value.java.typeName.removePrefix(DJVM_SANDBOX_PREFIX)
|
val className = if (annotation != null) {
|
||||||
}
|
annotation.value.java.typeName.removePrefix(DJVM_SANDBOX_PREFIX)
|
||||||
val enclosingClass = javaClass.enclosingClass ?: return null
|
} else {
|
||||||
return if (Contract::class.java.isAssignableFrom(enclosingClass)) {
|
val enclosingClass = javaClass.enclosingClass ?: return null
|
||||||
enclosingClass.typeName.removePrefix(DJVM_SANDBOX_PREFIX)
|
if (Contract::class.java.isAssignableFrom(enclosingClass)) {
|
||||||
} else {
|
enclosingClass.typeName.removePrefix(DJVM_SANDBOX_PREFIX)
|
||||||
null
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ContractStateClassCache.cacheContractClassName(this.javaClass, className)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package net.corda.core.internal
|
||||||
|
|
||||||
|
import com.google.common.collect.MapMaker
|
||||||
|
import net.corda.core.contracts.ContractState
|
||||||
|
|
||||||
|
object ContractStateClassCache {
|
||||||
|
private val classToString = MapMaker().weakKeys().makeMap<Class<*>, String>()
|
||||||
|
|
||||||
|
fun contractClassName(key: Class<ContractState>): String? {
|
||||||
|
return classToString[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun cacheContractClassName(key: Class<ContractState>, contractClassName: String?): String? {
|
||||||
|
if (contractClassName == null) return null
|
||||||
|
classToString.putIfAbsent(key, contractClassName)
|
||||||
|
return contractClassName
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user