From 8f0c0c784b6c659c74295d7324efabe8cbf60971 Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Thu, 14 Sep 2017 09:00:02 +0100 Subject: [PATCH] Removed PluginServiceHub --- .../main/kotlin/net/corda/core/node/PluginServiceHub.kt | 6 ------ .../kotlin/net/corda/core/node/services/CordaService.kt | 7 +++---- docs/source/changelog.rst | 2 ++ .../main/kotlin/net/corda/docs/CustomNotaryTutorial.kt | 4 ++-- .../src/main/kotlin/net/corda/docs/CustomVaultQuery.kt | 4 ++-- docs/source/node-services.rst | 7 +------ docs/source/oracles.rst | 3 +-- docs/source/tutorial-custom-notary.rst | 2 +- .../main/kotlin/net/corda/node/internal/AbstractNode.kt | 8 ++++---- .../net/corda/node/services/api/ServiceHubInternal.kt | 6 +++--- .../main/kotlin/net/corda/irs/api/NodeInterestRates.kt | 4 ++-- .../main/kotlin/net/corda/testing/node/MockServices.kt | 4 ++-- 12 files changed, 23 insertions(+), 34 deletions(-) delete mode 100644 core/src/main/kotlin/net/corda/core/node/PluginServiceHub.kt diff --git a/core/src/main/kotlin/net/corda/core/node/PluginServiceHub.kt b/core/src/main/kotlin/net/corda/core/node/PluginServiceHub.kt deleted file mode 100644 index aa8066fd54..0000000000 --- a/core/src/main/kotlin/net/corda/core/node/PluginServiceHub.kt +++ /dev/null @@ -1,6 +0,0 @@ -package net.corda.core.node - -/** - * A service hub to be used by the [CordaPluginRegistry] - */ -interface PluginServiceHub : ServiceHub diff --git a/core/src/main/kotlin/net/corda/core/node/services/CordaService.kt b/core/src/main/kotlin/net/corda/core/node/services/CordaService.kt index fb8b9340dd..c1b64cdc7c 100644 --- a/core/src/main/kotlin/net/corda/core/node/services/CordaService.kt +++ b/core/src/main/kotlin/net/corda/core/node/services/CordaService.kt @@ -1,6 +1,5 @@ package net.corda.core.node.services -import net.corda.core.node.PluginServiceHub import net.corda.core.node.ServiceHub import net.corda.core.serialization.SerializeAsToken import net.corda.core.serialization.SingletonSerializeAsToken @@ -8,9 +7,9 @@ import kotlin.annotation.AnnotationTarget.CLASS /** * Annotate any class that needs to be a long-lived service within the node, such as an oracle, with this annotation. - * Such a class needs to have a constructor with a single parameter of type [PluginServiceHub]. This construtor will be - * invoked during node start to initialise the service. The service hub provided can be used to get information about the - * node that may be necessary for the service. Corda services are created as singletons within the node and are available + * Such a class needs to have a constructor with a single parameter of type [ServiceHub]. This construtor will be invoked + * during node start to initialise the service. The service hub provided can be used to get information about the node + * that may be necessary for the service. Corda services are created as singletons within the node and are available * to flows via [ServiceHub.cordaService]. * * The service class has to implement [SerializeAsToken] to ensure correct usage within flows. (If possible extend diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index c2addf4265..d02bc0fea3 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -146,6 +146,8 @@ UNRELEASED * Removed deprecated parts of the API. +* Removed ``PluginServiceHub``. Replace with ``ServiceHub`` for ``@CordaService`` constructors. + Milestone 14 ------------ diff --git a/docs/source/example-code/src/main/kotlin/net/corda/docs/CustomNotaryTutorial.kt b/docs/source/example-code/src/main/kotlin/net/corda/docs/CustomNotaryTutorial.kt index 4ae47e52a3..a9509e2d5e 100644 --- a/docs/source/example-code/src/main/kotlin/net/corda/docs/CustomNotaryTutorial.kt +++ b/docs/source/example-code/src/main/kotlin/net/corda/docs/CustomNotaryTutorial.kt @@ -4,7 +4,7 @@ import co.paralleluniverse.fibers.Suspendable import net.corda.core.contracts.TransactionVerificationException import net.corda.core.flows.* import net.corda.core.identity.Party -import net.corda.core.node.PluginServiceHub +import net.corda.core.node.ServiceHub import net.corda.core.node.services.CordaService import net.corda.core.node.services.TimeWindowChecker import net.corda.core.node.services.TrustedAuthorityNotaryService @@ -14,7 +14,7 @@ import java.security.SignatureException // START 1 @CordaService -class MyCustomValidatingNotaryService(override val services: PluginServiceHub) : TrustedAuthorityNotaryService() { +class MyCustomValidatingNotaryService(override val services: ServiceHub) : TrustedAuthorityNotaryService() { override val timeWindowChecker = TimeWindowChecker(services.clock) override val uniquenessProvider = PersistentUniquenessProvider() diff --git a/docs/source/example-code/src/main/kotlin/net/corda/docs/CustomVaultQuery.kt b/docs/source/example-code/src/main/kotlin/net/corda/docs/CustomVaultQuery.kt index fff94dbbbd..60298055f9 100644 --- a/docs/source/example-code/src/main/kotlin/net/corda/docs/CustomVaultQuery.kt +++ b/docs/source/example-code/src/main/kotlin/net/corda/docs/CustomVaultQuery.kt @@ -7,7 +7,7 @@ import net.corda.core.flows.InitiatedBy import net.corda.core.flows.InitiatingFlow import net.corda.core.flows.StartableByRPC import net.corda.core.identity.Party -import net.corda.core.node.PluginServiceHub +import net.corda.core.node.ServiceHub import net.corda.core.node.services.CordaService import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.SingletonSerializeAsToken @@ -26,7 +26,7 @@ import java.util.* object CustomVaultQuery { @CordaService - class Service(val services: PluginServiceHub) : SingletonSerializeAsToken() { + class Service(val services: ServiceHub) : SingletonSerializeAsToken() { private companion object { val log = loggerFor() } diff --git a/docs/source/node-services.rst b/docs/source/node-services.rst index b2db166b8f..8e25eb6115 100644 --- a/docs/source/node-services.rst +++ b/docs/source/node-services.rst @@ -29,12 +29,7 @@ shutdown handler during initialisation, which will be called in reverse order to the start registration sequence when the ``Node.stop`` is called. -As well as the standard services trusted CorDapp plugins may register -custom services. These plugin services are passed a reference to the -``PluginServiceHub`` which allows some more powerful functions e.g. -starting flows. - -For unit testing a number of non-persistent, memory only services are +For unit testing a number of non-persistent, memory only services are defined in the ``:node`` and ``:test-utils`` projects. The ``:test-utils`` project also provides an in-memory networking simulation to allow unit testing of flows and service functions. diff --git a/docs/source/oracles.rst b/docs/source/oracles.rst index 842a5cd7b4..d6c9f101d6 100644 --- a/docs/source/oracles.rst +++ b/docs/source/oracles.rst @@ -211,8 +211,7 @@ done: :end-before: DOCEND 3 The Corda node scans for any class with this annotation and initialises them. The only requirement is that the class provide -a constructor with a single parameter of type ``PluginServiceHub```. In our example the oracle class has two constructors. -The second is used for testing. +a constructor with a single parameter of type ``ServiceHub``. .. literalinclude:: ../../samples/irs-demo/src/main/kotlin/net/corda/irs/api/NodeInterestRates.kt :language: kotlin diff --git a/docs/source/tutorial-custom-notary.rst b/docs/source/tutorial-custom-notary.rst index 07be4fab06..190d51533a 100644 --- a/docs/source/tutorial-custom-notary.rst +++ b/docs/source/tutorial-custom-notary.rst @@ -9,7 +9,7 @@ Writing a custom notary service Similarly to writing an oracle service, the first step is to create a service class in your CorDapp and annotate it with ``@CordaService``. The Corda node scans for any class with this annotation and initialises them. The only requirement -is that the class provide a constructor with a single parameter of type ``PluginServiceHub``. +is that the class provide a constructor with a single parameter of type ``ServiceHub``. .. literalinclude:: example-code/src/main/kotlin/net/corda/docs/CustomNotaryTutorial.kt :language: kotlin diff --git a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt index 859985d5a1..f9a3a7e652 100644 --- a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt @@ -20,8 +20,8 @@ import net.corda.core.messaging.RPCOps import net.corda.core.messaging.SingleMessageRecipient import net.corda.core.node.CordaPluginRegistry import net.corda.core.node.NodeInfo -import net.corda.core.node.PluginServiceHub import net.corda.core.node.ServiceEntry +import net.corda.core.node.ServiceHub import net.corda.core.node.services.* import net.corda.core.node.services.NetworkMapCache.MapChange import net.corda.core.schemas.MappedSchema @@ -234,8 +234,8 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, try { installCordaService(it) } catch (e: NoSuchMethodException) { - log.error("${it.name}, as a Corda service, must have a constructor with a single parameter " + - "of type ${PluginServiceHub::class.java.name}") + log.error("${it.name}, as a Corda service, must have a constructor with a single parameter of type " + + ServiceHub::class.java.name) } catch (e: ServiceInstantiationException) { log.error("Corda service ${it.name} failed to instantiate", e.cause) } catch (e: Exception) { @@ -250,7 +250,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, */ fun installCordaService(serviceClass: Class): T { serviceClass.requireAnnotation() - val constructor = serviceClass.getDeclaredConstructor(PluginServiceHub::class.java).apply { isAccessible = true } + val constructor = serviceClass.getDeclaredConstructor(ServiceHub::class.java).apply { isAccessible = true } val service = try { constructor.newInstance(services) } catch (e: InvocationTargetException) { diff --git a/node/src/main/kotlin/net/corda/node/services/api/ServiceHubInternal.kt b/node/src/main/kotlin/net/corda/node/services/api/ServiceHubInternal.kt index 5aee5ca7b9..68d37eb3a9 100644 --- a/node/src/main/kotlin/net/corda/node/services/api/ServiceHubInternal.kt +++ b/node/src/main/kotlin/net/corda/node/services/api/ServiceHubInternal.kt @@ -1,17 +1,17 @@ package net.corda.node.services.api -import net.corda.core.internal.VisibleForTesting import net.corda.core.concurrent.CordaFuture import net.corda.core.crypto.SecureHash import net.corda.core.flows.FlowInitiator import net.corda.core.flows.FlowLogic import net.corda.core.flows.StateMachineRunId import net.corda.core.internal.FlowStateMachine +import net.corda.core.internal.VisibleForTesting import net.corda.core.messaging.DataFeed import net.corda.core.messaging.SingleMessageRecipient import net.corda.core.messaging.StateMachineTransactionMapping import net.corda.core.node.NodeInfo -import net.corda.core.node.PluginServiceHub +import net.corda.core.node.ServiceHub import net.corda.core.node.services.NetworkMapCache import net.corda.core.node.services.TransactionStorage import net.corda.core.serialization.CordaSerializable @@ -65,7 +65,7 @@ sealed class NetworkCacheError : Exception() { class DeregistrationFailed : NetworkCacheError() } -interface ServiceHubInternal : PluginServiceHub { +interface ServiceHubInternal : ServiceHub { companion object { private val log = loggerFor() } diff --git a/samples/irs-demo/src/main/kotlin/net/corda/irs/api/NodeInterestRates.kt b/samples/irs-demo/src/main/kotlin/net/corda/irs/api/NodeInterestRates.kt index 0e3a8de51c..3a8ba65e2d 100644 --- a/samples/irs-demo/src/main/kotlin/net/corda/irs/api/NodeInterestRates.kt +++ b/samples/irs-demo/src/main/kotlin/net/corda/irs/api/NodeInterestRates.kt @@ -10,7 +10,7 @@ import net.corda.core.flows.InitiatedBy import net.corda.core.flows.StartableByRPC import net.corda.core.identity.Party import net.corda.core.internal.ThreadBox -import net.corda.core.node.PluginServiceHub +import net.corda.core.node.ServiceHub import net.corda.core.node.services.CordaService import net.corda.core.serialization.SingletonSerializeAsToken import net.corda.core.transactions.FilteredTransaction @@ -82,7 +82,7 @@ object NodeInterestRates { @ThreadSafe // DOCSTART 3 @CordaService - class Oracle(private val services: PluginServiceHub) : SingletonSerializeAsToken() { + class Oracle(private val services: ServiceHub) : SingletonSerializeAsToken() { private val mutex = ThreadBox(InnerState()) init { diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt index 6bd2a26c7d..e521b982ca 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt @@ -5,7 +5,7 @@ import net.corda.core.flows.StateMachineRunId import net.corda.core.identity.PartyAndCertificate import net.corda.core.messaging.DataFeed import net.corda.core.node.NodeInfo -import net.corda.core.node.PluginServiceHub +import net.corda.core.node.ServiceHub import net.corda.core.node.services.* import net.corda.core.schemas.MappedSchema import net.corda.core.serialization.SerializeAsToken @@ -45,7 +45,7 @@ import java.util.* * A singleton utility that only provides a mock identity, key and storage service. However, this is sufficient for * building chains of transactions and verifying them. It isn't sufficient for testing flows however. */ -open class MockServices(vararg val keys: KeyPair) : PluginServiceHub { +open class MockServices(vararg val keys: KeyPair) : ServiceHub { companion object {