From cc1d3e0ccf2e37f6e81b361377bfc98d802cec5d Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Thu, 26 Jan 2017 09:55:45 +0000 Subject: [PATCH] Add initial form for configuring new nodes. --- tools/demobench/build.gradle | 18 ++- .../java/net/corda/demobench/pty/R3Pty.java | 4 +- .../net/corda/demobench/model/NodeConfig.kt | 29 ++++ .../corda/demobench/model/NodeController.kt | 31 ++++ .../net/corda/demobench/model/NodeData.kt | 13 ++ .../corda/demobench/model/NodeDataModel.kt | 12 ++ .../corda/demobench/views/DemoBenchView.kt | 44 +----- .../net/corda/demobench/views/NodeTabView.kt | 132 +++++++++++++++--- .../corda/demobench/views/NodeTerminalView.kt | 72 ++++++++++ ...NodeTabView.fxml => NodeTerminalView.fxml} | 2 +- 10 files changed, 292 insertions(+), 65 deletions(-) create mode 100644 tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeConfig.kt create mode 100644 tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeController.kt create mode 100644 tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeData.kt create mode 100644 tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeDataModel.kt create mode 100644 tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTerminalView.kt rename tools/demobench/src/main/resources/net/corda/demobench/views/{NodeTabView.fxml => NodeTerminalView.fxml} (92%) diff --git a/tools/demobench/build.gradle b/tools/demobench/build.gradle index 5b6f572094..1e44ff6e3e 100644 --- a/tools/demobench/build.gradle +++ b/tools/demobench/build.gradle @@ -3,10 +3,12 @@ version '0.7-SNAPSHOT' buildscript { ext.kotlin_version = '1.0.6' + ext.tornadofx_version = '1.6.0' ext.jna_version = '4.1.0' ext.purejavacomm_version = '0.0.17' ext.guava_version = '14.0.1' ext.slf4j_version = '1.7.22' + ext.logback_version = '1.1.3' repositories { mavenCentral() @@ -18,8 +20,11 @@ buildscript { apply plugin: 'java' apply plugin: 'kotlin' +apply plugin: 'application' sourceCompatibility = 1.8 +mainClassName = 'net.corda.demobench.DemoBench' +applicationDefaultJvmArgs = ['-Djava.util.logging.config.class=net.corda.demobench.config.LoggingConfig'] repositories { flatDir { @@ -34,6 +39,8 @@ repositories { } dependencies { + // TornadoFX: A lightweight Kotlin framework for working with JavaFX UI's. + compile "no.tornado:tornadofx:$tornadofx_version" compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "net.java.dev.jna:jna:$jna_version" @@ -42,12 +49,15 @@ dependencies { compile "com.sparetimelabs:purejavacomm:$purejavacomm_version" compile "org.slf4j:log4j-over-slf4j:$slf4j_version" compile "org.slf4j:jul-to-slf4j:$slf4j_version" - compile "ch.qos.logback:logback-classic:1.1.3" + compile "ch.qos.logback:logback-classic:$logback_version" compile ":jediterm-terminal-2.5" compile ':pty4j-0.7.2' testCompile group: 'junit', name: 'junit', version: '4.11' - - // TornadoFX: A lightweight Kotlin framework for working with JavaFX UI's. - compile 'no.tornado:tornadofx:1.6.0' +} + +jar { + manifest { + attributes 'Main-Class': mainClassName + } } diff --git a/tools/demobench/src/main/java/net/corda/demobench/pty/R3Pty.java b/tools/demobench/src/main/java/net/corda/demobench/pty/R3Pty.java index f133c27ce9..5a0ec1213e 100644 --- a/tools/demobench/src/main/java/net/corda/demobench/pty/R3Pty.java +++ b/tools/demobench/src/main/java/net/corda/demobench/pty/R3Pty.java @@ -28,7 +28,9 @@ public class R3Pty implements AutoCloseable { @Override public void close() { LOG.info("Closing terminal '{}'", name); - terminal.close(); + if (terminal.getTerminalStarter() != null) { + terminal.close(); + } } public String getName() { diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeConfig.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeConfig.kt new file mode 100644 index 0000000000..c5798abe9d --- /dev/null +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeConfig.kt @@ -0,0 +1,29 @@ +package net.corda.demobench.model + +class NodeConfig(name: String, p2pPort: Int, artemisPort: Int, webPort: Int) { + + private var keyValue: String = toKey(name) + val key : String + get() { return keyValue } + + private var nameValue: String = name + val name : String + get() { return nameValue } + + private var p2pPortValue: Int = p2pPort + val p2pPort : Int + get() { return p2pPortValue } + + private var artemisPortValue: Int = artemisPort + val artemisPort : Int + get() { return artemisPortValue } + + private var webPortValue: Int = webPort + val webPort : Int + get() { return webPortValue } + + private fun toKey(value: String): String { + return value.replace("\\s++", "").toLowerCase() + } + +} diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeController.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeController.kt new file mode 100644 index 0000000000..025816eabc --- /dev/null +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeController.kt @@ -0,0 +1,31 @@ +package net.corda.demobench.model + +import tornadofx.Controller +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.atomic.AtomicInteger + +class NodeController : Controller() { + private val FIRST_PORT = 10000 + + private val nodes = ConcurrentHashMap() + private val port = AtomicInteger(FIRST_PORT) + + fun validate(nodeData: NodeData): NodeConfig? { + val config = NodeConfig( + nodeData.legalName.value, + nodeData.p2pPort.value, + nodeData.artemisPort.value, + nodeData.webPort.value + ) + + if (nodes.putIfAbsent(config.key, config) != null) { + return null + } + + return config + } + + val nextPort: Int + get() { return port.andIncrement } + +} diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeData.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeData.kt new file mode 100644 index 0000000000..60a7240155 --- /dev/null +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeData.kt @@ -0,0 +1,13 @@ +package net.corda.demobench.model + +import javafx.beans.property.SimpleIntegerProperty +import javafx.beans.property.SimpleStringProperty + +class NodeData { + + var legalName : SimpleStringProperty = SimpleStringProperty("") + var p2pPort: SimpleIntegerProperty = SimpleIntegerProperty(0) + val artemisPort: SimpleIntegerProperty = SimpleIntegerProperty(0) + val webPort: SimpleIntegerProperty = SimpleIntegerProperty(0) + +} \ No newline at end of file diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeDataModel.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeDataModel.kt new file mode 100644 index 0000000000..a58bc6b7ae --- /dev/null +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeDataModel.kt @@ -0,0 +1,12 @@ +package net.corda.demobench.model + +import tornadofx.ItemViewModel + +class NodeDataModel : ItemViewModel(NodeData()) { + + val legalName = bind { item?.legalName } + val p2pPort = bind { item?.p2pPort } + val artemisPort = bind { item?.artemisPort } + val webPort = bind { item?.webPort } + +} diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/views/DemoBenchView.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/views/DemoBenchView.kt index 8e80638ec4..aa40180e08 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/views/DemoBenchView.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/views/DemoBenchView.kt @@ -1,17 +1,11 @@ package net.corda.demobench.views -import com.jediterm.terminal.TerminalColor -import com.jediterm.terminal.TextStyle -import com.jediterm.terminal.ui.settings.DefaultSettingsProvider import java.util.* import javafx.application.Platform -import javafx.embed.swing.SwingNode import javafx.scene.Parent import javafx.scene.control.Button import javafx.scene.control.Tab import javafx.scene.control.TabPane -import javax.swing.SwingUtilities -import net.corda.demobench.pty.R3Pty import net.corda.demobench.ui.CloseableTab import tornadofx.* @@ -22,8 +16,6 @@ class DemoBenchView : View("Corda Demo Bench") { val addNodeButton by fxid