node: make AbstractNode's networkMapRegistrationFuture non-nullable

This commit is contained in:
Andras Slemmer 2016-06-08 13:05:49 +01:00
parent 8ea8ec435e
commit 53bd5c2287
2 changed files with 10 additions and 4 deletions

View File

@ -1,6 +1,8 @@
package com.r3corda.node.internal package com.r3corda.node.internal
import com.codahale.metrics.MetricRegistry import com.codahale.metrics.MetricRegistry
import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.JdkFutureAdapters
import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.SettableFuture import com.google.common.util.concurrent.SettableFuture
import com.r3corda.core.RunOnCallerThread import com.r3corda.core.RunOnCallerThread
@ -47,6 +49,7 @@ import java.security.KeyPair
import java.time.Clock import java.time.Clock
import java.time.Instant import java.time.Instant
import java.util.* import java.util.*
import java.util.concurrent.CompletableFuture
/** /**
* A base node implementation that can be customised either for production (with real implementations that do real * A base node implementation that can be customised either for production (with real implementations that do real
@ -109,9 +112,9 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
var isPreviousCheckpointsPresent = false var isPreviousCheckpointsPresent = false
private set private set
/** Completes once the node has successfully registered with the network map service. Null until [start] returns. */ /** Completes once the node has successfully registered with the network map service */
@Volatile var networkMapRegistrationFuture: ListenableFuture<Unit>? = null val networkMapRegistrationSettableFuture: SettableFuture<Unit> = SettableFuture.create()
private set val networkMapRegistrationFuture: ListenableFuture<Unit> = networkMapRegistrationSettableFuture
/** Set to true once [start] has been successfully called. */ /** Set to true once [start] has been successfully called. */
@Volatile var started = false @Volatile var started = false
@ -145,7 +148,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
CashBalanceAsMetricsObserver(services) CashBalanceAsMetricsObserver(services)
startMessagingService() startMessagingService()
networkMapRegistrationFuture = registerWithNetworkMap() networkMapRegistrationSettableFuture.setFuture(registerWithNetworkMap())
isPreviousCheckpointsPresent = checkpointStorage.checkpoints.any() isPreviousCheckpointsPresent = checkpointStorage.checkpoints.any()
smm.start() smm.start()
started = true started = true

View File

@ -1,5 +1,6 @@
package com.r3corda.node.internal.testing package com.r3corda.node.internal.testing
import com.google.common.base.Function
import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.ListenableFuture
import com.r3corda.core.node.CityDatabase import com.r3corda.core.node.CityDatabase
@ -213,6 +214,8 @@ abstract class Simulation(val runAsync: Boolean,
} }
} }
val networkInitialisationFinished: ListenableFuture<Unit> = Futures.transform(Futures.allAsList(network.nodes.map { it.networkMapRegistrationFuture }), Function { })
fun start(): ListenableFuture<Unit> { fun start(): ListenableFuture<Unit> {
network.startNodes() network.startNodes()
// Wait for all the nodes to have finished registering with the network map service. // Wait for all the nodes to have finished registering with the network map service.