From 5cf304e8c4f3cd089c1b40dfac0c1e347bd71068 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Wed, 17 May 2017 00:19:48 +0100 Subject: [PATCH] Disable the DemoBench tab if the node exits abnormally. (#692) * Log a message when the CRaSH shell exits. * Disable the DemoBench tab if the node exits abnormally. --- .../net/corda/node/shell/InteractiveShell.kt | 3 +++ .../kotlin/net/corda/demobench/rpc/NodeRPC.kt | 10 ++++++--- .../net/corda/demobench/views/NodeTabView.kt | 7 ++++++- .../corda/demobench/views/NodeTerminalView.kt | 21 ++++++++++++------- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/shell/InteractiveShell.kt b/node/src/main/kotlin/net/corda/node/shell/InteractiveShell.kt index 4e65947d11..6ff7a61d67 100644 --- a/node/src/main/kotlin/net/corda/node/shell/InteractiveShell.kt +++ b/node/src/main/kotlin/net/corda/node/shell/InteractiveShell.kt @@ -15,6 +15,7 @@ import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowStateMachine import net.corda.core.messaging.CordaRPCOps import net.corda.core.utilities.Emoji +import net.corda.core.utilities.loggerFor import net.corda.jackson.JacksonSupport import net.corda.jackson.StringToMethodCallParser import net.corda.node.internal.Node @@ -70,6 +71,7 @@ import kotlin.concurrent.thread // TODO: Make it notice new shell commands added after the node started. object InteractiveShell { + private val log = loggerFor() private lateinit var node: Node /** @@ -129,6 +131,7 @@ object InteractiveShell { thread(name = "Command line shell terminator", isDaemon = true) { // Wait for the shell to finish. jlineProcessor.closed() + log.info("Command shell has exited") terminal.restore() node.stop() } diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt index 43ec90a4cd..e3d1f95c13 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt @@ -17,8 +17,8 @@ class NodeRPC(config: NodeConfig, start: (NodeConfig, CordaRPCOps) -> Unit, invo } private val rpcClient = CordaRPCClient(HostAndPort.fromParts("localhost", config.rpcPort)) + private var rpcConnection: CordaRPCConnection? = null private val timer = Timer() - private val connections = Collections.synchronizedCollection(ArrayList()) init { val setupTask = object : TimerTask() { @@ -26,7 +26,7 @@ class NodeRPC(config: NodeConfig, start: (NodeConfig, CordaRPCOps) -> Unit, invo try { val user = config.users.elementAt(0) val connection = rpcClient.start(user.username, user.password) - connections.add(connection) + rpcConnection = connection val ops = connection.proxy // Cancel the "setup" task now that we've created the RPC client. @@ -53,7 +53,11 @@ class NodeRPC(config: NodeConfig, start: (NodeConfig, CordaRPCOps) -> Unit, invo override fun close() { timer.cancel() - connections.forEach(CordaRPCConnection::close) + try { + rpcConnection?.close() + } catch (e: Exception) { + log.error("Failed to close RPC connection (Error: {})", e.message) + } } } diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt index 709badd91f..6026e066a6 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt @@ -270,8 +270,13 @@ class NodeTabView : Fragment() { nodeTab.text = config.legalName.commonName nodeTerminalView.open(config) { exitCode -> Platform.runLater { - if (exitCode == 0) + if (exitCode == 0) { nodeTab.requestClose() + } else { + // The node did not shut down cleanly. Keep the + // terminal open but ensure that it is disabled. + nodeTerminalView.shutdown() + } nodeController.dispose(config) main.forceAtLeastOneTab() } diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTerminalView.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTerminalView.kt index 7e9f7212e4..7a44b60604 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTerminalView.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTerminalView.kt @@ -229,16 +229,21 @@ class NodeTerminalView : Fragment() { } } + fun shutdown() { + header.isDisable = true + subscriptions.forEach { + // Don't allow any exceptions here to halt tab destruction. + try { it.unsubscribe() } catch (e: Exception) {} + } + webServer.close() + explorer.close() + viewer.close() + rpc?.close() + } + fun destroy() { if (!isDestroyed) { - subscriptions.forEach { - // Don't allow any exceptions here to halt tab destruction. - try { it.unsubscribe() } catch (e: Exception) {} - } - webServer.close() - explorer.close() - viewer.close() - rpc?.close() + shutdown() pty?.close() isDestroyed = true }