From 308d7c1df7e7d334f360b4624513c3366403d746 Mon Sep 17 00:00:00 2001 From: Jose Coll Date: Mon, 31 Oct 2016 17:15:06 +0000 Subject: [PATCH 1/7] Added PluginServiceHub for use by Corda plugin service extensions. --- .../r3corda/core/node/CordaPluginRegistry.kt | 4 +-- .../com/r3corda/core/node/PluginServiceHub.kt | 28 +++++++++++++++++++ .../com/r3corda/node/internal/AbstractNode.kt | 2 +- .../node/services/NotaryChangeService.kt | 3 +- .../node/services/api/ServiceHubInternal.kt | 21 ++------------ .../persistence/DataVendingService.kt | 3 +- 6 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 core/src/main/kotlin/com/r3corda/core/node/PluginServiceHub.kt diff --git a/core/src/main/kotlin/com/r3corda/core/node/CordaPluginRegistry.kt b/core/src/main/kotlin/com/r3corda/core/node/CordaPluginRegistry.kt index de3f97f022..b3d4876b2f 100644 --- a/core/src/main/kotlin/com/r3corda/core/node/CordaPluginRegistry.kt +++ b/core/src/main/kotlin/com/r3corda/core/node/CordaPluginRegistry.kt @@ -30,8 +30,8 @@ abstract class CordaPluginRegistry { /** * List of additional long lived services to be hosted within the node. - * They are expected to have a single parameter constructor that takes a ServiceHubInternal as input. - * The ServiceHubInternal will be fully constructed before the plugin service is created and will + * They are expected to have a single parameter constructor that takes a [PluginServiceHub] as input. + * The [PluginServiceHub] will be fully constructed before the plugin service is created and will * allow access to the protocol factory and protocol initiation entry points there. */ open val servicePlugins: List> = emptyList() diff --git a/core/src/main/kotlin/com/r3corda/core/node/PluginServiceHub.kt b/core/src/main/kotlin/com/r3corda/core/node/PluginServiceHub.kt new file mode 100644 index 0000000000..7f6d6c2894 --- /dev/null +++ b/core/src/main/kotlin/com/r3corda/core/node/PluginServiceHub.kt @@ -0,0 +1,28 @@ +package com.r3corda.core.node + +import com.r3corda.core.crypto.Party +import com.r3corda.core.protocols.ProtocolLogic +import kotlin.reflect.KClass + +/** + * A service hub to be used by the [CordaPluginRegistry] + */ +interface PluginServiceHub : ServiceHub { + /** + * Register the protocol factory we wish to use when a initiating party attempts to communicate with us. The + * registration is done against a marker [KClass] which is sent in the session handshake by the other party. If this + * marker class has been registered then the corresponding factory will be used to create the protocol which will + * communicate with the other side. If there is no mapping then the session attempt is rejected. + * @param markerClass The marker [KClass] present in a session initiation attempt, which is a 1:1 mapping to a [Class] + * using the
::class
construct. Conventionally this is a [ProtocolLogic] subclass, however any class can + * be used, with the default being the class of the initiating protocol. This enables the registration to be of the + * form: registerProtocolInitiator(InitiatorProtocol::class, ::InitiatedProtocol) + * @param protocolFactory The protocol factory generating the initiated protocol. + */ + fun registerProtocolInitiator(markerClass: KClass<*>, protocolFactory: (Party) -> ProtocolLogic<*>) + + /** + * Return the protocol factory that has been registered with [markerClass], or null if no factory is found. + */ + fun getProtocolFactory(markerClass: Class<*>): ((Party) -> ProtocolLogic<*>)? +} 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 d4b88fe829..1e19492c0c 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt @@ -307,7 +307,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, val netwo val pluginServices = pluginRegistries.flatMap { x -> x.servicePlugins } val serviceList = mutableListOf() for (serviceClass in pluginServices) { - val service = serviceClass.getConstructor(ServiceHubInternal::class.java).newInstance(services) + val service = serviceClass.getConstructor(PluginServiceHub::class.java).newInstance(services) serviceList.add(service) tokenizableServices.add(service) if (service is AcceptsFileUpload) { diff --git a/node/src/main/kotlin/com/r3corda/node/services/NotaryChangeService.kt b/node/src/main/kotlin/com/r3corda/node/services/NotaryChangeService.kt index b6e89211b8..f444519e91 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/NotaryChangeService.kt +++ b/node/src/main/kotlin/com/r3corda/node/services/NotaryChangeService.kt @@ -1,6 +1,7 @@ package com.r3corda.node.services import com.r3corda.core.node.CordaPluginRegistry +import com.r3corda.core.node.PluginServiceHub import com.r3corda.core.serialization.SingletonSerializeAsToken import com.r3corda.node.services.api.ServiceHubInternal import com.r3corda.protocols.NotaryChangeProtocol @@ -14,7 +15,7 @@ object NotaryChange { * A service that monitors the network for requests for changing the notary of a state, * and immediately runs the [NotaryChangeProtocol] if the auto-accept criteria are met. */ - class Service(services: ServiceHubInternal) : SingletonSerializeAsToken() { + class Service(services: PluginServiceHub) : SingletonSerializeAsToken() { init { services.registerProtocolInitiator(NotaryChangeProtocol.Instigator::class) { NotaryChangeProtocol.Acceptor(it) } } diff --git a/node/src/main/kotlin/com/r3corda/node/services/api/ServiceHubInternal.kt b/node/src/main/kotlin/com/r3corda/node/services/api/ServiceHubInternal.kt index 9e8991264a..224ac57d27 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/api/ServiceHubInternal.kt +++ b/node/src/main/kotlin/com/r3corda/node/services/api/ServiceHubInternal.kt @@ -3,6 +3,7 @@ package com.r3corda.node.services.api import com.google.common.util.concurrent.ListenableFuture import com.r3corda.core.crypto.Party import com.r3corda.core.messaging.MessagingService +import com.r3corda.core.node.PluginServiceHub import com.r3corda.core.node.ServiceHub import com.r3corda.core.node.services.TxWritableStorageService import com.r3corda.core.protocols.ProtocolLogic @@ -37,7 +38,7 @@ interface MessagingServiceBuilder { private val log = LoggerFactory.getLogger(ServiceHubInternal::class.java) -abstract class ServiceHubInternal : ServiceHub { +abstract class ServiceHubInternal : PluginServiceHub { abstract val monitoringService: MonitoringService abstract val protocolLogicRefFactory: ProtocolLogicRefFactory abstract val schemaService: SchemaService @@ -71,24 +72,6 @@ abstract class ServiceHubInternal : ServiceHub { */ abstract fun startProtocol(logic: ProtocolLogic): ListenableFuture - /** - * Register the protocol factory we wish to use when a initiating party attempts to communicate with us. The - * registration is done against a marker [KClass] which is sent in the session handshake by the other party. If this - * marker class has been registered then the corresponding factory will be used to create the protocol which will - * communicate with the other side. If there is no mapping then the session attempt is rejected. - * @param markerClass The marker [KClass] present in a session initiation attempt, which is a 1:1 mapping to a [Class] - * using the
::class
construct. Conventionally this is a [ProtocolLogic] subclass, however any class can - * be used, with the default being the class of the initiating protocol. This enables the registration to be of the - * form: registerProtocolInitiator(InitiatorProtocol::class, ::InitiatedProtocol) - * @param protocolFactory The protocol factory generating the initiated protocol. - */ - abstract fun registerProtocolInitiator(markerClass: KClass<*>, protocolFactory: (Party) -> ProtocolLogic<*>) - - /** - * Return the protocol factory that has been registered with [markerClass], or null if no factory is found. - */ - abstract fun getProtocolFactory(markerClass: Class<*>): ((Party) -> ProtocolLogic<*>)? - override fun invokeProtocolAsync(logicType: Class>, vararg args: Any?): ListenableFuture { val logicRef = protocolLogicRefFactory.create(logicType, *args) @Suppress("UNCHECKED_CAST") diff --git a/node/src/main/kotlin/com/r3corda/node/services/persistence/DataVendingService.kt b/node/src/main/kotlin/com/r3corda/node/services/persistence/DataVendingService.kt index 6ed9dc5208..149ce3d21f 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/persistence/DataVendingService.kt +++ b/node/src/main/kotlin/com/r3corda/node/services/persistence/DataVendingService.kt @@ -3,6 +3,7 @@ package com.r3corda.node.services.persistence import co.paralleluniverse.fibers.Suspendable import com.r3corda.core.crypto.Party import com.r3corda.core.node.CordaPluginRegistry +import com.r3corda.core.node.PluginServiceHub import com.r3corda.core.node.recordTransactions import com.r3corda.core.protocols.ProtocolLogic import com.r3corda.core.serialization.SingletonSerializeAsToken @@ -34,7 +35,7 @@ object DataVending { // TODO: I don't like that this needs ServiceHubInternal, but passing in a state machine breaks MockServices because // the state machine isn't set when this is constructed. [NodeSchedulerService] has the same problem, and both // should be fixed at the same time. - class Service(services: ServiceHubInternal) : SingletonSerializeAsToken() { + class Service(services: PluginServiceHub) : SingletonSerializeAsToken() { companion object { val logger = loggerFor() From d9f0a161e42a6a60b6131546684a761596cd39f1 Mon Sep 17 00:00:00 2001 From: Jose Coll Date: Tue, 1 Nov 2016 12:05:48 +0000 Subject: [PATCH 2/7] Addressed comments in PR review. --- core/src/main/kotlin/com/r3corda/core/node/PluginServiceHub.kt | 2 ++ .../r3corda/node/services/persistence/DataVendingService.kt | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/com/r3corda/core/node/PluginServiceHub.kt b/core/src/main/kotlin/com/r3corda/core/node/PluginServiceHub.kt index 7f6d6c2894..6814ab1c25 100644 --- a/core/src/main/kotlin/com/r3corda/core/node/PluginServiceHub.kt +++ b/core/src/main/kotlin/com/r3corda/core/node/PluginServiceHub.kt @@ -19,6 +19,8 @@ interface PluginServiceHub : ServiceHub { * form: registerProtocolInitiator(InitiatorProtocol::class, ::InitiatedProtocol) * @param protocolFactory The protocol factory generating the initiated protocol. */ + + // TODO: remove dependency on Kotlin relfection (Kotlin KClass -> Java Class). fun registerProtocolInitiator(markerClass: KClass<*>, protocolFactory: (Party) -> ProtocolLogic<*>) /** diff --git a/node/src/main/kotlin/com/r3corda/node/services/persistence/DataVendingService.kt b/node/src/main/kotlin/com/r3corda/node/services/persistence/DataVendingService.kt index 149ce3d21f..66a5c13639 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/persistence/DataVendingService.kt +++ b/node/src/main/kotlin/com/r3corda/node/services/persistence/DataVendingService.kt @@ -32,9 +32,6 @@ object DataVending { * Additionally, because nodes do not store invalid transactions, requesting such a transaction will always yield null. */ @ThreadSafe - // TODO: I don't like that this needs ServiceHubInternal, but passing in a state machine breaks MockServices because -// the state machine isn't set when this is constructed. [NodeSchedulerService] has the same problem, and both -// should be fixed at the same time. class Service(services: PluginServiceHub) : SingletonSerializeAsToken() { companion object { From 1e6cca4d5dfaddd62b0d1330aa285a1e9e427aff Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Tue, 1 Nov 2016 16:09:13 +0000 Subject: [PATCH 3/7] Removed dead installDist configurations and moved Jolokia access to the correct resources dir. --- .idea/runConfigurations/Clean___Install.xml | 1 + build.gradle | 43 ------------------- .../src/test}/resources/jolokia-access.xml | 0 3 files changed, 1 insertion(+), 43 deletions(-) rename {src/main => node/src/test}/resources/jolokia-access.xml (100%) diff --git a/.idea/runConfigurations/Clean___Install.xml b/.idea/runConfigurations/Clean___Install.xml index 57e99db323..7401f4120c 100644 --- a/.idea/runConfigurations/Clean___Install.xml +++ b/.idea/runConfigurations/Clean___Install.xml @@ -11,6 +11,7 @@