Retire setup, and start return value. (#1101)

This commit is contained in:
Andrzej Cichocki 2017-07-25 12:42:02 +01:00 committed by GitHub
parent 46fcbf369a
commit dca2274bff
5 changed files with 12 additions and 33 deletions

View File

@ -9,7 +9,6 @@ import com.google.common.util.concurrent.SettableFuture
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner
import io.github.lukehutch.fastclasspathscanner.scanner.ScanResult
import net.corda.core.crypto.*
import net.corda.core.crypto.composite.CompositeKey
import net.corda.core.flatMap
import net.corda.core.flows.*
import net.corda.core.identity.Party
@ -23,7 +22,6 @@ import net.corda.core.node.services.*
import net.corda.core.node.services.NetworkMapCache.MapChange
import net.corda.core.serialization.SerializeAsToken
import net.corda.core.serialization.SingletonSerializeAsToken
import net.corda.core.serialization.deserialize
import net.corda.core.transactions.SignedTransaction
import net.corda.core.utilities.NetworkHostAndPort
import net.corda.core.utilities.debug
@ -160,7 +158,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
return configuration.myLegalName.locationOrNull?.let { CityDatabase[it] }
}
open fun start(): AbstractNode {
open fun start() {
require(!started) { "Node has already been started" }
if (configuration.devMode) {
@ -221,7 +219,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
_services.schedulerService.start()
}
started = true
return this
}
private class ServiceInstantiationException(cause: Throwable?) : Exception(cause)
@ -566,14 +563,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
}
}
/**
* Run any tasks that are needed to ensure the node is in a correct state before running start().
*/
open fun setup(): AbstractNode {
configuration.baseDirectory.createDirectories()
return this
}
private fun makeAdvertisedServices(tokenizableServices: MutableList<Any>) {
val serviceTypes = info.advertisedServices.map { it.info.type }
if (NetworkMapService.type in serviceTypes) makeNetworkMapService()

View File

@ -294,7 +294,7 @@ open class Node(override val configuration: FullNodeConfiguration,
val startupComplete: ListenableFuture<Unit> = SettableFuture.create()
override fun start(): Node {
override fun start() {
if (initialiseSerialization) {
initialiseSerialization()
}
@ -326,7 +326,6 @@ open class Node(override val configuration: FullNodeConfiguration,
shutdownHook = addShutdownHook {
stop()
}
return this
}
private fun initialiseSerialization() {
@ -344,12 +343,6 @@ open class Node(override val configuration: FullNodeConfiguration,
(network as NodeMessagingClient).run(messageBroker!!.serverControl)
}
// TODO: Do we really need setup?
override fun setup(): Node {
super.setup()
return this
}
private var shutdown = false
override fun stop() {

View File

@ -108,10 +108,9 @@ class AttachmentTests {
overrideServices: Map<ServiceInfo, KeyPair>?,
entropyRoot: BigInteger): MockNetwork.MockNode {
return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
override fun start(): MockNetwork.MockNode {
override fun start() {
super.start()
attachments.checkAttachmentsOnLoad = false
return this
}
}
}

View File

@ -122,7 +122,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
baseDirectory = config.baseDirectory,
myLegalName = RATES_SERVICE_NAME)
return object : SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
override fun start(): MockNetwork.MockNode {
override fun start() {
super.start()
registerInitiatedFlow(NodeInterestRates.FixQueryHandler::class.java)
registerInitiatedFlow(NodeInterestRates.FixSignHandler::class.java)
@ -131,7 +131,6 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
installCordaService(NodeInterestRates.Oracle::class.java).uploadFixes(it.reader().readText())
}
}
return this
}
}
}

View File

@ -229,10 +229,9 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
override fun myAddresses() = emptyList<NetworkHostAndPort>()
override fun start(): MockNode {
override fun start() {
super.start()
mockNet.identities.add(info.legalIdentityAndCert)
return this
}
// Allow unit tests to modify the plugin list before the node start,
@ -300,14 +299,14 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
whenever(it.dataSourceProperties).thenReturn(makeTestDataSourceProperties("node_${id}_net_$networkId"))
configOverrides(it)
}
val node = nodeFactory.create(config, this, networkMapAddress, advertisedServices.toSet(), id, overrideServices, entropyRoot)
if (start) {
node.setup().start()
if (threadPerNode && networkMapAddress != null)
node.networkMapRegistrationFuture.getOrThrow() // Block and wait for the node to register in the net map.
return nodeFactory.create(config, this, networkMapAddress, advertisedServices.toSet(), id, overrideServices, entropyRoot).apply {
if (start) {
configuration.baseDirectory.createDirectories()
start()
if (threadPerNode && networkMapAddress != null) networkMapRegistrationFuture.getOrThrow()
}
_nodes.add(this)
}
_nodes.add(node)
return node
}
fun baseDirectory(nodeId: Int): Path = filesystem.getPath("/nodes/$nodeId")