mirror of
https://github.com/corda/corda.git
synced 2024-12-28 08:48:57 +00:00
Merge remote-tracking branch 'open/master' into colljos-merge-171117
This commit is contained in:
commit
fe34a4e7bc
@ -14,7 +14,7 @@ import kotlin.reflect.KProperty
|
|||||||
// READ ME FIRST:
|
// READ ME FIRST:
|
||||||
// This is a collection of public utilities useful only for Kotlin code. Think carefully before adding anything here and
|
// This is a collection of public utilities useful only for Kotlin code. Think carefully before adding anything here and
|
||||||
// make sure it's tested and documented. If you're looking to add a public utility that is also relevant to Java then
|
// make sure it's tested and documented. If you're looking to add a public utility that is also relevant to Java then
|
||||||
// don't put it here but in a seperate file called Utils.kt
|
// don't put it here but in a separate file called Utils.kt
|
||||||
//
|
//
|
||||||
|
|
||||||
/** Like the + operator but throws [ArithmeticException] in case of integer overflow. */
|
/** Like the + operator but throws [ArithmeticException] in case of integer overflow. */
|
||||||
|
@ -16,6 +16,7 @@ import net.corda.core.utilities.loggerFor
|
|||||||
import net.corda.node.internal.classloading.requireAnnotation
|
import net.corda.node.internal.classloading.requireAnnotation
|
||||||
import net.corda.node.services.config.NodeConfiguration
|
import net.corda.node.services.config.NodeConfiguration
|
||||||
import net.corda.nodeapi.internal.serialization.DefaultWhitelist
|
import net.corda.nodeapi.internal.serialization.DefaultWhitelist
|
||||||
|
import org.apache.commons.collections4.map.LRUMap
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.lang.reflect.Modifier
|
import java.lang.reflect.Modifier
|
||||||
@ -67,6 +68,9 @@ class CordappLoader private constructor(private val cordappJarPaths: List<Restri
|
|||||||
*/
|
*/
|
||||||
fun createDefault(baseDir: Path) = CordappLoader(getCordappsInDirectory(getCordappsPath(baseDir)))
|
fun createDefault(baseDir: Path) = CordappLoader(getCordappsInDirectory(getCordappsPath(baseDir)))
|
||||||
|
|
||||||
|
// Cache for CordappLoaders to avoid costly classpath scanning
|
||||||
|
private val cordappLoadersCache = LRUMap<List<*>, CordappLoader>(1000)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a dev mode CordappLoader for test environments that creates and loads cordapps from the classpath
|
* Create a dev mode CordappLoader for test environments that creates and loads cordapps from the classpath
|
||||||
* and cordapps directory. This is intended mostly for use by the driver.
|
* and cordapps directory. This is intended mostly for use by the driver.
|
||||||
@ -77,7 +81,8 @@ class CordappLoader private constructor(private val cordappJarPaths: List<Restri
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
fun createDefaultWithTestPackages(configuration: NodeConfiguration, testPackages: List<String>): CordappLoader {
|
fun createDefaultWithTestPackages(configuration: NodeConfiguration, testPackages: List<String>): CordappLoader {
|
||||||
check(configuration.devMode) { "Package scanning can only occur in dev mode" }
|
check(configuration.devMode) { "Package scanning can only occur in dev mode" }
|
||||||
return CordappLoader(getCordappsInDirectory(getCordappsPath(configuration.baseDirectory)) + testPackages.flatMap(this::createScanPackage))
|
val paths = getCordappsInDirectory(getCordappsPath(configuration.baseDirectory)) + testPackages.flatMap(this::createScanPackage)
|
||||||
|
return cordappLoadersCache.computeIfAbsent(paths, { CordappLoader(paths) })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +94,7 @@ class CordappLoader private constructor(private val cordappJarPaths: List<Restri
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
fun createWithTestPackages(testPackages: List<String>)
|
fun createWithTestPackages(testPackages: List<String>)
|
||||||
= CordappLoader(testPackages.flatMap(this::createScanPackage))
|
= cordappLoadersCache.computeIfAbsent(testPackages, { CordappLoader(testPackages.flatMap(this::createScanPackage)) })
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a dev mode CordappLoader intended only to be used in test environments
|
* Creates a dev mode CordappLoader intended only to be used in test environments
|
||||||
@ -242,9 +247,12 @@ class CordappLoader private constructor(private val cordappJarPaths: List<Restri
|
|||||||
return scanResult.getClassesWithSuperclass(MappedSchema::class).toSet()
|
return scanResult.getClassesWithSuperclass(MappedSchema::class).toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val cachedScanResult = LRUMap<RestrictedURL, RestrictedScanResult>(1000)
|
||||||
private fun scanCordapp(cordappJarPath: RestrictedURL): RestrictedScanResult {
|
private fun scanCordapp(cordappJarPath: RestrictedURL): RestrictedScanResult {
|
||||||
logger.info("Scanning CorDapp in $cordappJarPath")
|
logger.info("Scanning CorDapp in $cordappJarPath")
|
||||||
return RestrictedScanResult(FastClasspathScanner().addClassLoader(appClassLoader).overrideClasspath(cordappJarPath.url).scan(), cordappJarPath.qualifiedNamePrefix)
|
return cachedScanResult.computeIfAbsent(cordappJarPath, {
|
||||||
|
RestrictedScanResult(FastClasspathScanner().addClassLoader(appClassLoader).overrideClasspath(cordappJarPath.url).scan(), cordappJarPath.qualifiedNamePrefix)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FlowTypeHierarchyComparator(val initiatingFlow: Class<out FlowLogic<*>>) : Comparator<Class<out FlowLogic<*>>> {
|
private class FlowTypeHierarchyComparator(val initiatingFlow: Class<out FlowLogic<*>>) : Comparator<Class<out FlowLogic<*>>> {
|
||||||
|
@ -169,7 +169,7 @@ class MockNetwork(defaultParameters: MockNetworkParameters = MockNetworkParamete
|
|||||||
* @see defaultNotaryNode
|
* @see defaultNotaryNode
|
||||||
*/
|
*/
|
||||||
val defaultNotaryIdentityAndCert: PartyAndCertificate get() {
|
val defaultNotaryIdentityAndCert: PartyAndCertificate get() {
|
||||||
return defaultNotaryNode.info.legalIdentitiesAndCerts.singleOrNull() ?: throw IllegalStateException("Default notary has multiple identities")
|
return defaultNotaryNode.info.legalIdentitiesAndCerts[1] // TODO Resolve once network parameters is merged back in
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user