mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
Closing the app class loader on node shutdown (#4479)
This commit is contained in:
parent
67eb9fec43
commit
33670d62b1
@ -8,7 +8,7 @@ import net.corda.core.schemas.MappedSchema
|
||||
/**
|
||||
* Handles loading [Cordapp]s.
|
||||
*/
|
||||
interface CordappLoader {
|
||||
interface CordappLoader : AutoCloseable {
|
||||
|
||||
/**
|
||||
* Returns all [Cordapp]s found.
|
||||
|
@ -145,7 +145,7 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
|
||||
}
|
||||
}
|
||||
|
||||
val cordappLoader: CordappLoader = makeCordappLoader(configuration, versionInfo)
|
||||
val cordappLoader: CordappLoader = makeCordappLoader(configuration, versionInfo).closeOnStop()
|
||||
val schemaService = NodeSchemaService(cordappLoader.cordappSchemas).tokenize()
|
||||
val identityService = PersistentIdentityService(cacheFactory).tokenize()
|
||||
val database: CordaPersistence = createCordaPersistence(
|
||||
@ -544,7 +544,7 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
|
||||
generatedCordapps += VirtualCordapp.generateSimpleNotaryCordapp(versionInfo)
|
||||
}
|
||||
val blacklistedKeys = if (configuration.devMode) emptyList()
|
||||
else configuration.cordappSignerKeyFingerprintBlacklist.mapNotNull {
|
||||
else configuration.cordappSignerKeyFingerprintBlacklist.map {
|
||||
try {
|
||||
SecureHash.parse(it)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
|
@ -43,13 +43,6 @@ class JarScanningCordappLoader private constructor(private val cordappJarPaths:
|
||||
private val versionInfo: VersionInfo = VersionInfo.UNKNOWN,
|
||||
extraCordapps: List<CordappImpl>,
|
||||
private val signerKeyFingerprintBlacklist: List<SecureHash.SHA256> = emptyList()) : CordappLoaderTemplate() {
|
||||
|
||||
override val cordapps: List<CordappImpl> by lazy {
|
||||
loadCordapps() + extraCordapps
|
||||
}
|
||||
|
||||
override val appClassLoader: ClassLoader = URLClassLoader(cordappJarPaths.stream().map { it.url }.toTypedArray(), javaClass.classLoader)
|
||||
|
||||
init {
|
||||
if (cordappJarPaths.isEmpty()) {
|
||||
logger.info("No CorDapp paths provided")
|
||||
@ -58,6 +51,12 @@ class JarScanningCordappLoader private constructor(private val cordappJarPaths:
|
||||
}
|
||||
}
|
||||
|
||||
override val cordapps: List<CordappImpl> by lazy { loadCordapps() + extraCordapps }
|
||||
|
||||
override val appClassLoader: URLClassLoader = URLClassLoader(cordappJarPaths.stream().map { it.url }.toTypedArray(), javaClass.classLoader)
|
||||
|
||||
override fun close() = appClassLoader.close()
|
||||
|
||||
companion object {
|
||||
private val logger = contextLogger()
|
||||
|
||||
@ -260,7 +259,10 @@ class JarScanningCordappLoader private constructor(private val cordappJarPaths:
|
||||
}
|
||||
|
||||
private fun findPlugins(cordappJarPath: RestrictedURL): List<SerializationWhitelist> {
|
||||
return ServiceLoader.load(SerializationWhitelist::class.java, URLClassLoader(arrayOf(cordappJarPath.url), appClassLoader)).toList().filter {
|
||||
val whitelists = URLClassLoader(arrayOf(cordappJarPath.url), appClassLoader).use {
|
||||
ServiceLoader.load(SerializationWhitelist::class.java, it).toList()
|
||||
}
|
||||
return whitelists.filter {
|
||||
it.javaClass.location == cordappJarPath.url && it.javaClass.name.startsWith(cordappJarPath.qualifiedNamePrefix)
|
||||
} + DefaultWhitelist // Always add the DefaultWhitelist to the whitelist for an app.
|
||||
}
|
||||
@ -378,8 +380,4 @@ abstract class CordappLoaderTemplate : CordappLoader {
|
||||
override val cordappSchemas: Set<MappedSchema> by lazy {
|
||||
cordapps.flatMap { it.customSchemas }.toSet()
|
||||
}
|
||||
|
||||
override val appClassLoader: ClassLoader by lazy {
|
||||
URLClassLoader(cordapps.stream().map { it.jarPath }.toTypedArray(), javaClass.classLoader)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user