Added clock to node configuration to allow for creating a demo with a different clock.

This commit is contained in:
Clinton Alexander 2016-10-14 16:48:33 +01:00
parent 0ee4f9c19b
commit 201561497a
2 changed files with 11 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import com.r3corda.core.crypto.generateKeyPair
import com.r3corda.core.node.NodeInfo import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.services.NetworkMapCache import com.r3corda.core.node.services.NetworkMapCache
import com.r3corda.core.node.services.ServiceInfo import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.node.serialization.NodeClock
import com.r3corda.node.services.config.ConfigHelper import com.r3corda.node.services.config.ConfigHelper
import com.r3corda.node.services.config.FullNodeConfiguration import com.r3corda.node.services.config.FullNodeConfiguration
import com.r3corda.node.services.messaging.ArtemisMessagingComponent import com.r3corda.node.services.messaging.ArtemisMessagingComponent
@ -27,12 +28,13 @@ import java.net.*
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.Paths import java.nio.file.Paths
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.time.Clock
import java.util.* import java.util.*
import java.util.concurrent.* import java.util.concurrent.*
import kotlin.concurrent.thread import kotlin.concurrent.thread
/** /**
* This file defines a small "Driver" DSL for starting up nodes. * This file defines a small "Driver" DSL for starting up nodes that is only intended for development, demos and tests.
* *
* The process the driver is run in behaves as an Artemis client and starts up other processes. Namely it first * The process the driver is run in behaves as an Artemis client and starts up other processes. Namely it first
* bootstraps a network map service to allow the specified nodes to connect to, then starts up the actual nodes. * bootstraps a network map service to allow the specified nodes to connect to, then starts up the actual nodes.
@ -113,6 +115,7 @@ fun <A> driver(
baseDirectory: String = "build/${getTimestampAsDirectoryName()}", baseDirectory: String = "build/${getTimestampAsDirectoryName()}",
portAllocation: PortAllocation = PortAllocation.Incremental(10000), portAllocation: PortAllocation = PortAllocation.Incremental(10000),
debugPortAllocation: PortAllocation = PortAllocation.Incremental(5005), debugPortAllocation: PortAllocation = PortAllocation.Incremental(5005),
clock: Clock = NodeClock(),
isDebug: Boolean = false, isDebug: Boolean = false,
dsl: DriverDSLExposedInterface.() -> A dsl: DriverDSLExposedInterface.() -> A
) = genericDriver( ) = genericDriver(
@ -120,6 +123,7 @@ fun <A> driver(
portAllocation = portAllocation, portAllocation = portAllocation,
debugPortAllocation = debugPortAllocation, debugPortAllocation = debugPortAllocation,
baseDirectory = baseDirectory, baseDirectory = baseDirectory,
clock = clock,
isDebug = isDebug isDebug = isDebug
), ),
coerce = { it }, coerce = { it },
@ -199,10 +203,11 @@ fun <A> poll(pollName: String, pollIntervalMs: Long = 500, warnCount: Int = 120,
return result return result
} }
class DriverDSL( open class DriverDSL(
val portAllocation: PortAllocation, val portAllocation: PortAllocation,
val debugPortAllocation: PortAllocation, val debugPortAllocation: PortAllocation,
val baseDirectory: String, val baseDirectory: String,
val clock: Clock,
val isDebug: Boolean val isDebug: Boolean
) : DriverDSLInternalInterface { ) : DriverDSLInternalInterface {
private val networkMapName = "NetworkMapService" private val networkMapName = "NetworkMapService"
@ -326,6 +331,7 @@ class DriverDSL(
configOverrides = mapOf( configOverrides = mapOf(
"myLegalName" to networkMapName, "myLegalName" to networkMapName,
"basedir" to Paths.get(nodeDirectory).normalize().toString(), "basedir" to Paths.get(nodeDirectory).normalize().toString(),
"clock" to clock,
"artemisAddress" to networkMapAddress.toString(), "artemisAddress" to networkMapAddress.toString(),
"webAddress" to apiAddress.toString(), "webAddress" to apiAddress.toString(),
"extraAdvertisedServiceIds" to "" "extraAdvertisedServiceIds" to ""

View File

@ -9,6 +9,7 @@ import com.r3corda.node.services.messaging.NodeMessagingClient
import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.network.NetworkMapService
import com.typesafe.config.Config import com.typesafe.config.Config
import java.nio.file.Path import java.nio.file.Path
import java.time.Clock
import java.util.* import java.util.*
interface NodeSSLConfiguration { interface NodeSSLConfiguration {
@ -46,6 +47,7 @@ class FullNodeConfiguration(config: Config) : NodeConfiguration {
val webAddress: HostAndPort by config val webAddress: HostAndPort by config
val messagingServerAddress: HostAndPort? by config.getOrElse { null } val messagingServerAddress: HostAndPort? by config.getOrElse { null }
val extraAdvertisedServiceIds: String by config val extraAdvertisedServiceIds: String by config
val clock: Clock by config
fun createNode(): Node { fun createNode(): Node {
val advertisedServices = mutableSetOf<ServiceInfo>() val advertisedServices = mutableSetOf<ServiceInfo>()
@ -56,7 +58,7 @@ class FullNodeConfiguration(config: Config) : NodeConfiguration {
} }
if (networkMapAddress == null) advertisedServices.add(ServiceInfo(NetworkMapService.type)) if (networkMapAddress == null) advertisedServices.add(ServiceInfo(NetworkMapService.type))
val networkMapMessageAddress: SingleMessageRecipient? = if (networkMapAddress == null) null else NodeMessagingClient.makeNetworkMapAddress(networkMapAddress!!) val networkMapMessageAddress: SingleMessageRecipient? = if (networkMapAddress == null) null else NodeMessagingClient.makeNetworkMapAddress(networkMapAddress!!)
return Node(this, networkMapMessageAddress, advertisedServices) return Node(this, networkMapMessageAddress, advertisedServices, clock)
} }
} }