From 3ea7d382a26ca1f46f6c786fba6ae23b4f08c410 Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Wed, 12 Oct 2016 16:33:05 +0100 Subject: [PATCH 1/5] Removed IRS demo and network simulator and placed them in separate repos. --- .idea/modules.xml | 18 +- build.gradle | 1 - network-simulator/build.gradle | 59 --- .../corda/netmap/NetworkMapVisualiser.kt | 358 ------------- .../com/r3cev/corda/netmap/VisualiserUtils.kt | 18 - .../com/r3cev/corda/netmap/VisualiserView.kt | 304 ----------- .../r3cev/corda/netmap/VisualiserViewModel.kt | 222 -------- .../com/r3cev/corda/netmap/Europe.jpg | Bin 309247 -> 0 bytes .../com/r3cev/corda/netmap/MainWindow.fxml | 29 - .../com/r3cev/corda/netmap/R3 logo.png | Bin 23602 -> 0 bytes .../corda/netmap/SIL Open Font License.txt | 43 -- .../corda/netmap/SourceSansPro-Black.otf | Bin 234176 -> 0 bytes .../corda/netmap/SourceSansPro-BlackIt.otf | Bin 81120 -> 0 bytes .../r3cev/corda/netmap/SourceSansPro-Bold.otf | Bin 235128 -> 0 bytes .../corda/netmap/SourceSansPro-BoldIt.otf | Bin 80392 -> 0 bytes .../corda/netmap/SourceSansPro-ExtraLight.otf | Bin 221580 -> 0 bytes .../netmap/SourceSansPro-ExtraLightIt.otf | Bin 76400 -> 0 bytes .../r3cev/corda/netmap/SourceSansPro-It.otf | Bin 79724 -> 0 bytes .../corda/netmap/SourceSansPro-Light.otf | Bin 226032 -> 0 bytes .../corda/netmap/SourceSansPro-LightIt.otf | Bin 77816 -> 0 bytes .../corda/netmap/SourceSansPro-Regular.otf | Bin 229588 -> 0 bytes .../corda/netmap/SourceSansPro-Semibold.otf | Bin 232680 -> 0 bytes .../corda/netmap/SourceSansPro-SemiboldIt.otf | Bin 80316 -> 0 bytes .../com/r3cev/corda/netmap/WorldMap.png | Bin 349746 -> 0 bytes .../com/r3cev/corda/netmap/WorldMapSquare.png | Bin 480246 -> 0 bytes .../com/r3cev/corda/netmap/styles.css | 227 -------- settings.gradle | 1 - .../kotlin/com/r3corda/demos/DemoClock.kt | 44 -- src/main/kotlin/com/r3corda/demos/IRSDemo.kt | 499 ------------------ .../kotlin/com/r3corda/demos/RateFixDemo.kt | 94 ---- .../r3corda/demos/api/InterestRateSwapAPI.kt | 123 ----- .../r3corda/demos/api/NodeInterestRates.kt | 321 ----------- .../demos/protocols/AutoOfferProtocol.kt | 91 ---- .../demos/protocols/ExitServerProtocol.kt | 74 --- .../protocols/UpdateBusinessDayProtocol.kt | 68 --- .../com/r3corda/demos/utilities/HttpUtils.kt | 41 -- .../com/r3corda/simulation/IRSSimulation.kt | 133 ----- .../com/r3corda/simulation/Simulation.kt | 338 ------------ .../com/r3corda/simulation/TradeSimulation.kt | 73 --- .../com/r3corda/demos/example-irs-trade.json | 103 ---- .../com/r3corda/demos/example.rates.txt | 228 -------- .../com/r3corda/demos/irswebdemo/.bowerrc | 3 - .../com/r3corda/demos/irswebdemo/.gitignore | 2 - .../com/r3corda/demos/irswebdemo/bower.json | 25 - .../com/r3corda/demos/irswebdemo/css/main.css | 15 - .../com/r3corda/demos/irswebdemo/index.html | 30 -- .../com/r3corda/demos/irswebdemo/js/Deal.js | 79 --- .../com/r3corda/demos/irswebdemo/js/app.js | 24 - .../irswebdemo/js/controllers/CreateDeal.js | 36 -- .../demos/irswebdemo/js/controllers/Deal.js | 9 - .../demos/irswebdemo/js/controllers/Home.js | 23 - .../demos/irswebdemo/js/require-config.js | 28 - .../com/r3corda/demos/irswebdemo/js/routes.js | 33 -- .../demos/irswebdemo/js/services/NodeApi.js | 99 ---- .../js/utils/dayCountBasisLookup.js | 34 -- .../demos/irswebdemo/js/utils/semantic.js | 22 - .../demos/irswebdemo/js/viewmodel/Common.js | 38 -- .../demos/irswebdemo/js/viewmodel/Deal.js | 9 - .../demos/irswebdemo/js/viewmodel/FixedLeg.js | 20 - .../irswebdemo/js/viewmodel/FixedRate.js | 9 - .../irswebdemo/js/viewmodel/FloatingLeg.js | 28 - .../demos/irswebdemo/view/create-deal.html | 186 ------- .../r3corda/demos/irswebdemo/view/deal.html | 206 -------- .../r3corda/demos/irswebdemo/view/home.html | 57 -- .../r3corda/core/testing/IRSSimulationTest.kt | 22 - .../core/testing/NodeInterestRatesTest.kt | 167 ------ 66 files changed, 15 insertions(+), 4699 deletions(-) delete mode 100644 network-simulator/build.gradle delete mode 100644 network-simulator/src/main/kotlin/com/r3cev/corda/netmap/NetworkMapVisualiser.kt delete mode 100644 network-simulator/src/main/kotlin/com/r3cev/corda/netmap/VisualiserUtils.kt delete mode 100644 network-simulator/src/main/kotlin/com/r3cev/corda/netmap/VisualiserView.kt delete mode 100644 network-simulator/src/main/kotlin/com/r3cev/corda/netmap/VisualiserViewModel.kt delete mode 100644 network-simulator/src/main/resources/com/r3cev/corda/netmap/Europe.jpg delete mode 100644 network-simulator/src/main/resources/com/r3cev/corda/netmap/MainWindow.fxml delete mode 100644 network-simulator/src/main/resources/com/r3cev/corda/netmap/R3 logo.png delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SIL Open Font License.txt delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SourceSansPro-Black.otf delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SourceSansPro-BlackIt.otf delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SourceSansPro-Bold.otf delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SourceSansPro-BoldIt.otf delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SourceSansPro-ExtraLight.otf delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SourceSansPro-ExtraLightIt.otf delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SourceSansPro-It.otf delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SourceSansPro-Light.otf delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SourceSansPro-LightIt.otf delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SourceSansPro-Regular.otf delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SourceSansPro-Semibold.otf delete mode 100755 network-simulator/src/main/resources/com/r3cev/corda/netmap/SourceSansPro-SemiboldIt.otf delete mode 100644 network-simulator/src/main/resources/com/r3cev/corda/netmap/WorldMap.png delete mode 100644 network-simulator/src/main/resources/com/r3cev/corda/netmap/WorldMapSquare.png delete mode 100644 network-simulator/src/main/resources/com/r3cev/corda/netmap/styles.css delete mode 100644 src/main/kotlin/com/r3corda/demos/DemoClock.kt delete mode 100644 src/main/kotlin/com/r3corda/demos/IRSDemo.kt delete mode 100644 src/main/kotlin/com/r3corda/demos/RateFixDemo.kt delete mode 100644 src/main/kotlin/com/r3corda/demos/api/InterestRateSwapAPI.kt delete mode 100644 src/main/kotlin/com/r3corda/demos/api/NodeInterestRates.kt delete mode 100644 src/main/kotlin/com/r3corda/demos/protocols/AutoOfferProtocol.kt delete mode 100644 src/main/kotlin/com/r3corda/demos/protocols/ExitServerProtocol.kt delete mode 100644 src/main/kotlin/com/r3corda/demos/protocols/UpdateBusinessDayProtocol.kt delete mode 100644 src/main/kotlin/com/r3corda/demos/utilities/HttpUtils.kt delete mode 100644 src/main/kotlin/com/r3corda/simulation/IRSSimulation.kt delete mode 100644 src/main/kotlin/com/r3corda/simulation/Simulation.kt delete mode 100644 src/main/kotlin/com/r3corda/simulation/TradeSimulation.kt delete mode 100644 src/main/resources/com/r3corda/demos/example-irs-trade.json delete mode 100644 src/main/resources/com/r3corda/demos/example.rates.txt delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/.bowerrc delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/.gitignore delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/bower.json delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/css/main.css delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/index.html delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/Deal.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/app.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/controllers/CreateDeal.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/controllers/Deal.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/controllers/Home.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/require-config.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/routes.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/services/NodeApi.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/utils/dayCountBasisLookup.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/utils/semantic.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/Common.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/Deal.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/FixedLeg.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/FixedRate.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/FloatingLeg.js delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/view/create-deal.html delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/view/deal.html delete mode 100644 src/main/resources/com/r3corda/demos/irswebdemo/view/home.html delete mode 100644 src/test/kotlin/com/r3corda/core/testing/IRSSimulationTest.kt delete mode 100644 src/test/kotlin/com/r3corda/core/testing/NodeInterestRatesTest.kt diff --git a/.idea/modules.xml b/.idea/modules.xml index dec18dacb0..dd99fdb4a4 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -12,11 +12,17 @@ + + + + + + @@ -24,16 +30,22 @@ + + + - - - + + + + + + diff --git a/build.gradle b/build.gradle index 11dbefc97d..d130f3a00a 100644 --- a/build.gradle +++ b/build.gradle @@ -110,7 +110,6 @@ dependencies { compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" compile "org.jetbrains.kotlinx:kotlinx-support-jdk8:0.2" - compile 'com.squareup.okhttp3:okhttp:3.3.1' compile 'co.paralleluniverse:capsule:1.0.3' // Unit testing helpers. diff --git a/network-simulator/build.gradle b/network-simulator/build.gradle deleted file mode 100644 index e147512b57..0000000000 --- a/network-simulator/build.gradle +++ /dev/null @@ -1,59 +0,0 @@ -buildscript { - repositories { - mavenCentral() - maven { - url 'http://oss.sonatype.org/content/repositories/snapshots' - } - } - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - -apply plugin: 'java' -apply plugin: 'kotlin' -apply plugin: 'application' -apply plugin: 'us.kirchmeier.capsule' - -group 'com.r3cev.prototyping' -version '1.0-SNAPSHOT' - -sourceCompatibility = 1.5 - -repositories { - mavenLocal() - mavenCentral() - jcenter() - maven { - url 'http://oss.sonatype.org/content/repositories/snapshots' - } - maven { - url 'https://dl.bintray.com/kotlin/exposed' - } -} - -applicationDefaultJvmArgs = ["-javaagent:${rootProject.configurations.quasar.singleFile}"] -mainClassName = 'com.r3cev.corda.netmap.NetworkMapVisualiserKt' - -dependencies { - compile project(":core") - compile project(":node") - compile project(":contracts") - compile rootProject - - // GraphStream: For visualisation - compile "org.graphstream:gs-core:1.3" - compile "org.graphstream:gs-ui:1.3" - - compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - testCompile group: 'junit', name: 'junit', version: '4.11' -} - -task capsule(type: FatCapsule) { - applicationClass 'com.r3cev.corda.netmap.NetworkExplorerKt' - reallyExecutable - capsuleManifest { - minJavaVersion = '1.8.0' - javaAgents = [rootProject.configurations.quasar.singleFile.name] - } -} diff --git a/network-simulator/src/main/kotlin/com/r3cev/corda/netmap/NetworkMapVisualiser.kt b/network-simulator/src/main/kotlin/com/r3cev/corda/netmap/NetworkMapVisualiser.kt deleted file mode 100644 index a62239c82b..0000000000 --- a/network-simulator/src/main/kotlin/com/r3cev/corda/netmap/NetworkMapVisualiser.kt +++ /dev/null @@ -1,358 +0,0 @@ -/* - * Copyright 2015 Distributed Ledger Group LLC. Distributed as Licensed Company IP to DLG Group Members - * pursuant to the August 7, 2015 Advisory Services Agreement and subject to the Company IP License terms - * set forth therein. - * - * All other rights reserved. - */ - -package com.r3cev.corda.netmap - -import com.r3corda.core.messaging.SingleMessageRecipient -import com.r3corda.core.then -import com.r3corda.core.utilities.ProgressTracker -import com.r3corda.testing.node.InMemoryMessagingNetwork -import com.r3corda.testing.node.MockNetwork -import com.r3corda.simulation.IRSSimulation -import com.r3corda.simulation.Simulation -import com.r3corda.node.services.network.NetworkMapService -import javafx.animation.* -import javafx.application.Application -import javafx.application.Platform -import javafx.beans.property.SimpleDoubleProperty -import javafx.beans.value.WritableValue -import javafx.geometry.Insets -import javafx.geometry.Pos -import javafx.scene.control.* -import javafx.scene.input.KeyCode -import javafx.scene.input.KeyCodeCombination -import javafx.scene.layout.* -import javafx.scene.paint.Color -import javafx.scene.shape.Circle -import javafx.scene.shape.Line -import javafx.scene.shape.Polygon -import javafx.stage.Stage -import javafx.util.Duration -import rx.Scheduler -import rx.schedulers.Schedulers -import java.nio.file.Files -import java.nio.file.Paths -import java.time.format.DateTimeFormatter -import java.time.format.FormatStyle -import java.util.* -import kotlin.concurrent.schedule -import kotlin.concurrent.scheduleAtFixedRate -import kotlin.system.exitProcess -import com.r3cev.corda.netmap.VisualiserViewModel.Style - -fun WritableValue.keyValue(endValue: T, interpolator: Interpolator = Interpolator.EASE_OUT) = KeyValue(this, endValue, interpolator) - -// TODO: This code is all horribly ugly. Refactor to use TornadoFX to clean it up. - -class NetworkMapVisualiser : Application() { - enum class NodeType { - BANK, SERVICE - } - - enum class RunPauseButtonLabel { - RUN, PAUSE; - - override fun toString(): String { - return name.toLowerCase().capitalize() - } - } - - sealed class RunningPausedState { - class Running(val tickTimer: TimerTask): RunningPausedState() - class Paused(): RunningPausedState() - - val buttonLabel: RunPauseButtonLabel - get() { - return when (this) { - is RunningPausedState.Running -> RunPauseButtonLabel.PAUSE - is RunningPausedState.Paused -> RunPauseButtonLabel.RUN - } - } - } - - private val view = VisualiserView() - private val viewModel = VisualiserViewModel() - - val timer = Timer() - val uiThread: Scheduler = Schedulers.from { Platform.runLater(it) } - - override fun start(stage: Stage) { - viewModel.view = view - viewModel.presentationMode = "--presentation-mode" in parameters.raw - buildScene(stage) - viewModel.displayStyle = if ("--circle" in parameters.raw) { Style.CIRCLE } else { viewModel.displayStyle } - - val simulation = viewModel.simulation - // Update the white-backgrounded label indicating what protocol step it's up to. - simulation.allProtocolSteps.observeOn(uiThread).subscribe { step: Pair -> - val (node, change) = step - val label = viewModel.nodesToWidgets[node]!!.statusLabel - if (change is ProgressTracker.Change.Position) { - // Fade in the status label if it's our first step. - if (label.text == "") { - with(FadeTransition(Duration(150.0), label)) { - fromValue = 0.0 - toValue = 1.0 - play() - } - } - label.text = change.newStep.label - if (change.newStep == ProgressTracker.DONE && change.tracker == change.tracker.topLevelTracker) { - runLater(500, -1) { - // Fade out the status label. - with(FadeTransition(Duration(750.0), label)) { - fromValue = 1.0 - toValue = 0.0 - setOnFinished { label.text = "" } - play() - } - } - } - } else if (change is ProgressTracker.Change.Rendering) { - label.text = change.ofStep.label - } - } - // Fire the message bullets between nodes. - simulation.network.messagingNetwork.sentMessages.observeOn(uiThread).subscribe { msg: InMemoryMessagingNetwork.MessageTransfer -> - val senderNode: MockNetwork.MockNode = simulation.network.addressToNode(msg.sender.myAddress) - val destNode: MockNetwork.MockNode = simulation.network.addressToNode(msg.recipients as SingleMessageRecipient) - - if (transferIsInteresting(msg)) { - viewModel.nodesToWidgets[senderNode]!!.pulseAnim.play() - viewModel.fireBulletBetweenNodes(senderNode, destNode, "bank", "bank") - } - } - // Pulse all parties in a trade when the trade completes - simulation.doneSteps.observeOn(uiThread).subscribe { nodes: Collection -> - nodes.forEach { viewModel.nodesToWidgets[it]!!.longPulseAnim.play() } - } - - stage.setOnCloseRequest { exitProcess(0) } - //stage.isMaximized = true - stage.show() - } - - fun runLater(startAfter: Int, delayBetween: Int, body: () -> Unit) { - if (delayBetween != -1) { - timer.scheduleAtFixedRate(startAfter.toLong(), delayBetween.toLong()) { - Platform.runLater { - body() - } - } - } else { - timer.schedule(startAfter.toLong()) { - Platform.runLater { - body() - } - } - } - } - - private fun buildScene(stage: Stage) { - view.stage = stage - view.setup(viewModel.runningPausedState, viewModel.displayStyle, viewModel.presentationMode) - bindSidebar() - bindTopbar() - viewModel.createNodes() - - // Spacebar advances simulation by one step. - stage.scene.accelerators[KeyCodeCombination(KeyCode.SPACE)] = Runnable { onNextInvoked() } - - reloadStylesheet(stage) - - stage.focusedProperty().addListener { value, old, new -> - if (new) { - reloadStylesheet(stage) - } - } - } - - private fun bindTopbar() { - view.resetButton.setOnAction({reset()}) - view.nextButton.setOnAction { - if (!view.simulateInitialisationCheckbox.isSelected && !viewModel.simulation.networkInitialisationFinished.isDone) { - skipNetworkInitialisation() - } else { - onNextInvoked() - } - } - viewModel.simulation.networkInitialisationFinished.then { - view.simulateInitialisationCheckbox.isVisible = false - } - view.runPauseButton.setOnAction { - val oldRunningPausedState = viewModel.runningPausedState - val newRunningPausedState = when (oldRunningPausedState) { - is NetworkMapVisualiser.RunningPausedState.Running -> { - oldRunningPausedState.tickTimer.cancel() - - view.nextButton.isDisable = false - view.resetButton.isDisable = false - - NetworkMapVisualiser.RunningPausedState.Paused() - } - is NetworkMapVisualiser.RunningPausedState.Paused -> { - val tickTimer = timer.scheduleAtFixedRate(viewModel.stepDuration.toMillis().toLong(), viewModel.stepDuration.toMillis().toLong()) { - Platform.runLater { - onNextInvoked() - } - } - - view.nextButton.isDisable = true - view.resetButton.isDisable = true - - if (!view.simulateInitialisationCheckbox.isSelected && !viewModel.simulation.networkInitialisationFinished.isDone) { - skipNetworkInitialisation() - } - - NetworkMapVisualiser.RunningPausedState.Running(tickTimer) - } - } - - view.runPauseButton.text = newRunningPausedState.buttonLabel.toString() - viewModel.runningPausedState = newRunningPausedState - } - view.styleChoice.selectionModel.selectedItemProperty() - .addListener { ov, value, newValue -> viewModel.displayStyle = newValue } - viewModel.simulation.dateChanges.observeOn(uiThread).subscribe { view.dateLabel.text = it.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)) } - } - - private fun reloadStylesheet(stage: Stage) { - stage.scene.stylesheets.clear() - stage.scene.stylesheets.add(NetworkMapVisualiser::class.java.getResource("styles.css").toString()) - } - - private fun bindSidebar() { - viewModel.simulation.allProtocolSteps.observeOn(uiThread).subscribe { step: Pair -> - val (node, change) = step - - if (change is ProgressTracker.Change.Position) { - val tracker = change.tracker.topLevelTracker - if (change.newStep == ProgressTracker.DONE) { - if (change.tracker == tracker) { - // Protocol done; schedule it for removal in a few seconds. We batch them up to make nicer - // animations. - println("Protocol done for ${node.info.legalIdentity.name}") - viewModel.doneTrackers += tracker - } else { - // Subprotocol is done; ignore it. - } - } else if (!viewModel.trackerBoxes.containsKey(tracker)) { - // New protocol started up; add. - val extraLabel = viewModel.simulation.extraNodeLabels[node] - val label = if (extraLabel != null) "${node.info.legalIdentity.name}: $extraLabel" else node.info.legalIdentity.name - val widget = view.buildProgressTrackerWidget(label, tracker.topLevelTracker) - bindProgressTracketWidget(tracker.topLevelTracker, widget) - println("Added: ${tracker}, ${widget}") - viewModel.trackerBoxes[tracker] = widget.vbox - view.sidebar.children += widget.vbox - } - } - } - - Timer().scheduleAtFixedRate(0, 500) { - Platform.runLater { - for (tracker in viewModel.doneTrackers) { - val pane = viewModel.trackerBoxes[tracker]!! - // Slide the other tracker widgets up and over this one. - val slideProp = SimpleDoubleProperty(0.0) - slideProp.addListener { obv -> pane.padding = Insets(0.0, 0.0, slideProp.value, 0.0) } - val timeline = Timeline( - KeyFrame(Duration(250.0), - KeyValue(pane.opacityProperty(), 0.0), - KeyValue(slideProp, -pane.height - 50.0) // Subtract the bottom padding gap. - ) - ) - timeline.setOnFinished { - println("Removed: ${tracker}") - val vbox = viewModel.trackerBoxes.remove(tracker) - view.sidebar.children.remove(vbox) - } - timeline.play() - } - viewModel.doneTrackers.clear() - } - } - } - - private fun bindProgressTracketWidget(tracker: ProgressTracker, widget: TrackerWidget) { - val allSteps: List> = tracker.allSteps - tracker.changes.observeOn(uiThread).subscribe { step: ProgressTracker.Change -> - val stepHeight = widget.cursorBox.height / allSteps.size - if (step is ProgressTracker.Change.Position) { - // Figure out the index of the new step. - val curStep = allSteps.indexOfFirst { it.second == step.newStep } - // Animate the cursor to the right place. - with(TranslateTransition(Duration(350.0), widget.cursor)) { - fromY = widget.cursor.translateY - toY = (curStep * stepHeight) + 22.5 - play() - } - } else if (step is ProgressTracker.Change.Structural) { - val new = view.buildProgressTrackerWidget(widget.label.text, tracker) - val prevWidget = viewModel.trackerBoxes[step.tracker] ?: throw AssertionError("No previous widget for tracker: ${step.tracker}") - val i = (prevWidget.parent as VBox).children.indexOf(viewModel.trackerBoxes[step.tracker]) - (prevWidget.parent as VBox).children[i] = new.vbox - viewModel.trackerBoxes[step.tracker] = new.vbox - } - } - } - - var started = false - private fun startSimulation() { - if (!started) { - viewModel.simulation.start() - started = true - } - } - - private fun reset() { - viewModel.simulation.stop() - viewModel.simulation = IRSSimulation(true, false, null) - started = false - start(view.stage) - } - - private fun skipNetworkInitialisation() { - startSimulation() - while (!viewModel.simulation.networkInitialisationFinished.isDone) { - iterateSimulation() - } - } - - private fun onNextInvoked() { - if (started) { - iterateSimulation() - } else { - startSimulation() - } - } - - private fun iterateSimulation() { - // Loop until either we ran out of things to do, or we sent an interesting message. - while (true) { - val transfer: InMemoryMessagingNetwork.MessageTransfer = viewModel.simulation.iterate() ?: break - if (transferIsInteresting(transfer)) - break - else - System.err.println("skipping boring $transfer") - } - } - - private fun transferIsInteresting(transfer: InMemoryMessagingNetwork.MessageTransfer): Boolean { - // Loopback messages are boring. - if (transfer.sender.myAddress == transfer.recipients) return false - // Network map push acknowledgements are boring. - if (NetworkMapService.PUSH_ACK_PROTOCOL_TOPIC in transfer.message.topicSession.topic) return false - - return true - } -} - -fun main(args: Array) { - Application.launch(NetworkMapVisualiser::class.java, *args) -} diff --git a/network-simulator/src/main/kotlin/com/r3cev/corda/netmap/VisualiserUtils.kt b/network-simulator/src/main/kotlin/com/r3cev/corda/netmap/VisualiserUtils.kt deleted file mode 100644 index 590b4e139f..0000000000 --- a/network-simulator/src/main/kotlin/com/r3cev/corda/netmap/VisualiserUtils.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.r3cev.corda.netmap - -import javafx.scene.paint.Color - -internal -fun colorToRgb(color: Color): String { - val builder = StringBuilder() - - builder.append("rgb(") - builder.append(Math.round(color.red * 256)) - builder.append(",") - builder.append(Math.round(color.green * 256)) - builder.append(",") - builder.append(Math.round(color.blue * 256)) - builder.append(")") - - return builder.toString() -} \ No newline at end of file diff --git a/network-simulator/src/main/kotlin/com/r3cev/corda/netmap/VisualiserView.kt b/network-simulator/src/main/kotlin/com/r3cev/corda/netmap/VisualiserView.kt deleted file mode 100644 index 4dd4470aa1..0000000000 --- a/network-simulator/src/main/kotlin/com/r3cev/corda/netmap/VisualiserView.kt +++ /dev/null @@ -1,304 +0,0 @@ -package com.r3cev.corda.netmap - -import com.r3corda.core.utilities.ProgressTracker -import javafx.animation.KeyFrame -import javafx.animation.Timeline -import javafx.application.Platform -import javafx.collections.FXCollections -import javafx.event.EventHandler -import javafx.geometry.Insets -import javafx.geometry.Pos -import javafx.scene.Group -import javafx.scene.Node -import javafx.scene.Scene -import javafx.scene.control.* -import javafx.scene.image.Image -import javafx.scene.image.ImageView -import javafx.scene.input.ZoomEvent -import javafx.scene.layout.* -import javafx.scene.paint.Color -import javafx.scene.shape.Polygon -import javafx.scene.text.Font -import javafx.stage.Stage -import javafx.util.Duration -import com.r3cev.corda.netmap.VisualiserViewModel.Style - -data class TrackerWidget(val vbox: VBox, val cursorBox: Pane, val label: Label, val cursor: Polygon) - -internal class VisualiserView() { - lateinit var root: Pane - lateinit var stage: Stage - lateinit var splitter: SplitPane - lateinit var sidebar: VBox - lateinit var resetButton: Button - lateinit var nextButton: Button - lateinit var runPauseButton: Button - lateinit var simulateInitialisationCheckbox: CheckBox - lateinit var styleChoice: ChoiceBox