mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
Merged in nodedircreate (pull request #139)
Todo resolution: Moved node directory creation into the abstract node.
This commit is contained in:
commit
3e82ee45f2
@ -163,6 +163,14 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Run any tasks that are needed to ensure the node is in a correct state before running start()
|
||||
*/
|
||||
open fun setup(): AbstractNode {
|
||||
createNodeDir()
|
||||
return this
|
||||
}
|
||||
|
||||
private fun buildAdvertisedServices() {
|
||||
val serviceTypes = info.advertisedServices
|
||||
if (NetworkMapService.Type in serviceTypes) makeNetworkMapService()
|
||||
@ -327,4 +335,10 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
||||
}
|
||||
return NodeAttachmentService(attachmentsDir, services.monitoringService.metrics)
|
||||
}
|
||||
|
||||
protected fun createNodeDir() {
|
||||
if (!Files.exists(dir)) {
|
||||
Files.createDirectories(dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import org.glassfish.jersey.servlet.ServletContainer
|
||||
import java.io.RandomAccessFile
|
||||
import java.lang.management.ManagementFactory
|
||||
import java.nio.channels.FileLock
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.time.Clock
|
||||
import javax.management.ObjectName
|
||||
@ -152,6 +153,11 @@ class Node(dir: Path, val p2pAddr: HostAndPort, configuration: NodeConfiguration
|
||||
return this
|
||||
}
|
||||
|
||||
override fun setup(): Node {
|
||||
super.setup()
|
||||
return this
|
||||
}
|
||||
|
||||
override fun stop() {
|
||||
webServer.stop()
|
||||
super.stop()
|
||||
@ -177,6 +183,7 @@ class Node(dir: Path, val p2pAddr: HostAndPort, configuration: NodeConfiguration
|
||||
println("Shut that other node down and try again. It may have process ID ${file.readText()}")
|
||||
System.exit(1)
|
||||
}
|
||||
|
||||
nodeFileLock = l
|
||||
val ourProcessID: String = ManagementFactory.getRuntimeMXBean().name.split("@")[0]
|
||||
f.setLength(0)
|
||||
|
@ -122,7 +122,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
override val nearestCity: String = "Atlantis"
|
||||
}
|
||||
val node = nodeFactory.create(path, config, this, networkMapAddress, advertisedServices.toSet(), id, keyPair)
|
||||
if (start) node.start()
|
||||
if (start) node.setup().start()
|
||||
_nodes.add(node)
|
||||
return node
|
||||
}
|
||||
|
@ -401,7 +401,7 @@ private fun startNode(params : NodeParams) : Node {
|
||||
|
||||
val node = logElapsedTime("Node startup") { Node(params.dir, myNetAddr, config, networkMapId,
|
||||
advertisedServices, DemoClock(),
|
||||
listOf(InterestRateSwapAPI::class.java)).start() }
|
||||
listOf(InterestRateSwapAPI::class.java)).setup().start() }
|
||||
|
||||
// TODO: This should all be replaced by the identity service being updated
|
||||
// as the network map changes.
|
||||
|
@ -48,12 +48,7 @@ fun main(args: Array<String>) {
|
||||
// Suppress the Artemis MQ noise, and activate the demo logging.
|
||||
BriefLogFormatter.initVerbose("+demo.ratefix", "-org.apache.activemq")
|
||||
|
||||
// TODO: Move this into the AbstractNode class.
|
||||
val dir = Paths.get(options.valueOf(dirArg))
|
||||
if (!Files.exists(dir)) {
|
||||
Files.createDirectory(dir)
|
||||
}
|
||||
|
||||
val networkMapAddr = ArtemisMessagingService.makeRecipient(options.valueOf(networkMapAddrArg))
|
||||
val networkMapIdentity = Files.readAllBytes(Paths.get(options.valueOf(networkMapIdentityArg))).deserialize<Party>()
|
||||
val networkMapAddress = NodeInfo(networkMapAddr, networkMapIdentity)
|
||||
@ -78,7 +73,7 @@ fun main(args: Array<String>) {
|
||||
|
||||
val node = logElapsedTime("Node startup") { Node(dir, myNetAddr, config, networkMapAddress,
|
||||
advertisedServices, DemoClock(),
|
||||
listOf(InterestRateSwapAPI::class.java)).start() }
|
||||
listOf(InterestRateSwapAPI::class.java)).setup().start() }
|
||||
|
||||
val notary = node.services.networkMapCache.notaryNodes[0]
|
||||
|
||||
|
@ -95,7 +95,7 @@ fun main(args: Array<String>) {
|
||||
// for protocols will change in future.
|
||||
BriefLogFormatter.initVerbose("+demo.buyer", "+demo.seller", "-org.apache.activemq")
|
||||
|
||||
val directory = setupDirectory(role)
|
||||
val directory = Paths.get(DIRNAME, role.name.toLowerCase())
|
||||
|
||||
// Override the default config file (which you can find in the file "reference.conf") to give each node a name.
|
||||
val config = run {
|
||||
@ -131,7 +131,7 @@ fun main(args: Array<String>) {
|
||||
|
||||
// And now construct then start the node object. It takes a little while.
|
||||
val node = logElapsedTime("Node startup") {
|
||||
Node(directory, myNetAddr, config, networkMapId, advertisedServices).start()
|
||||
Node(directory, myNetAddr, config, networkMapId, advertisedServices).setup().start()
|
||||
}
|
||||
|
||||
// TODO: Replace with a separate trusted cash issuer
|
||||
@ -149,12 +149,6 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
fun setupDirectory(mode: Role): Path {
|
||||
val directory = Paths.get(DIRNAME, mode.name.toLowerCase())
|
||||
Files.createDirectories(directory)
|
||||
return directory
|
||||
}
|
||||
|
||||
fun parseOptions(args: Array<String>, parser: OptionParser): OptionSet {
|
||||
try {
|
||||
return parser.parse(*args)
|
||||
|
Loading…
Reference in New Issue
Block a user