From 1557a82992e7c4c2506e0a8847a00aeb89478296 Mon Sep 17 00:00:00 2001 From: Matthew Nesbit Date: Thu, 7 Jul 2016 13:55:15 +0100 Subject: [PATCH] Make ServiceLoader results for CordaPlugins a protected property on the AbstractNode --- .../main/kotlin/com/r3corda/node/internal/AbstractNode.kt | 7 +++++-- node/src/main/kotlin/com/r3corda/node/internal/Node.kt | 2 -- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt index 3b4dae1b20..c6924b73dd 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt @@ -137,6 +137,10 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration, val networkMapRegistrationFuture: ListenableFuture get() = _networkMapRegistrationFuture + /** fetch CordaPluginRegistry classes registered in META-INF/services/com.r3corda.core.node.CordaPluginRegistry files that exist in the classpath */ + protected val pluginRegistries: List + get() = ServiceLoader.load(CordaPluginRegistry::class.java).toList() + /** Set to true once [start] has been successfully called. */ @Volatile var started = false private set @@ -188,8 +192,6 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration, } private fun initialiseProtocolLogicFactory(): ProtocolLogicRefFactory { - val serviceLoader = ServiceLoader.load(CordaPluginRegistry::class.java) - val pluginRegistries = serviceLoader.toList() val protocolWhitelist = HashMap>() for (plugin in pluginRegistries) { for (protocol in plugin.requiredProtocols) { @@ -200,6 +202,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration, return ProtocolLogicRefFactory(protocolWhitelist) } + /** * Run any tasks that are needed to ensure the node is in a correct state before running start() */ diff --git a/node/src/main/kotlin/com/r3corda/node/internal/Node.kt b/node/src/main/kotlin/com/r3corda/node/internal/Node.kt index 98e7a72745..1c5c167b76 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/Node.kt +++ b/node/src/main/kotlin/com/r3corda/node/internal/Node.kt @@ -109,8 +109,6 @@ class Node(dir: Path, val p2pAddr: HostAndPort, val webServerAddr: HostAndPort, resourceConfig.register(ResponseFilter()) resourceConfig.register(api) - val serviceLoader = ServiceLoader.load(CordaPluginRegistry::class.java) - val pluginRegistries = serviceLoader.toList() val webAPIsOnClasspath = pluginRegistries.flatMap { x -> x.webApis } for (webapi in webAPIsOnClasspath) { log.info("Add Plugin web API from attachment ${webapi.name}")