mirror of
https://github.com/corda/corda.git
synced 2025-01-23 12:58:35 +00:00
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.
This commit is contained in:
parent
68f0e5d683
commit
5cf304e8c4
@ -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<InteractiveShell>()
|
||||
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()
|
||||
}
|
||||
|
@ -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<CordaRPCConnection>())
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user