Merged in nodedircreate (pull request #139)

Todo resolution: Moved node directory creation into the abstract node.
This commit is contained in:
Clinton Alexander
2016-06-21 11:02:29 +01:00
6 changed files with 26 additions and 16 deletions

View File

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

View File

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

View File

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