Removed PluginServiceHub

This commit is contained in:
Shams Asari 2017-09-14 09:00:02 +01:00
parent abac314b31
commit 8f0c0c784b
12 changed files with 23 additions and 34 deletions

View File

@ -1,6 +0,0 @@
package net.corda.core.node
/**
* A service hub to be used by the [CordaPluginRegistry]
*/
interface PluginServiceHub : ServiceHub

View File

@ -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

View File

@ -146,6 +146,8 @@ UNRELEASED
* Removed deprecated parts of the API.
* Removed ``PluginServiceHub``. Replace with ``ServiceHub`` for ``@CordaService`` constructors.
Milestone 14
------------

View File

@ -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()

View File

@ -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<Service>()
}

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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 <T : SerializeAsToken> installCordaService(serviceClass: Class<T>): T {
serviceClass.requireAnnotation<CordaService>()
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) {

View File

@ -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<ServiceHubInternal>()
}

View File

@ -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 {

View File

@ -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 {