mirror of
https://github.com/corda/corda.git
synced 2025-01-15 01:10:33 +00:00
Add utility function for creating SLF4J loggers, and close unused I/O streams from forked processes.
This commit is contained in:
parent
bb8aa50d68
commit
166cbbf2e5
@ -2,6 +2,8 @@ package net.corda.demobench
|
|||||||
|
|
||||||
import javafx.scene.image.Image
|
import javafx.scene.image.Image
|
||||||
import net.corda.demobench.views.DemoBenchView
|
import net.corda.demobench.views.DemoBenchView
|
||||||
|
import org.slf4j.Logger
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
import tornadofx.App
|
import tornadofx.App
|
||||||
import tornadofx.addStageIcon
|
import tornadofx.addStageIcon
|
||||||
|
|
||||||
@ -50,3 +52,7 @@ class DemoBench : App(DemoBenchView::class) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Trivial utility function to create SLF4J Logger.
|
||||||
|
*/
|
||||||
|
inline fun <reified T: Any> loggerFor(): Logger = LoggerFactory.getLogger(T::class.java)
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package net.corda.demobench.model
|
package net.corda.demobench.model
|
||||||
|
|
||||||
|
import net.corda.demobench.loggerFor
|
||||||
import org.h2.server.web.LocalWebServer
|
import org.h2.server.web.LocalWebServer
|
||||||
import org.h2.tools.Server
|
import org.h2.tools.Server
|
||||||
import org.h2.util.JdbcUtils
|
import org.h2.util.JdbcUtils
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import kotlin.reflect.jvm.jvmName
|
import kotlin.reflect.jvm.jvmName
|
||||||
|
|
||||||
class DBViewer : AutoCloseable {
|
class DBViewer : AutoCloseable {
|
||||||
private val log = LoggerFactory.getLogger(DBViewer::class.java)
|
private val log = loggerFor<DBViewer>()
|
||||||
|
|
||||||
private val webServer: Server
|
private val webServer: Server
|
||||||
private val pool = Executors.newCachedThreadPool()
|
private val pool = Executors.newCachedThreadPool()
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package net.corda.demobench.model
|
package net.corda.demobench.model
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory
|
import net.corda.demobench.loggerFor
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
class Explorer(val explorerController: ExplorerController) : AutoCloseable {
|
class Explorer(val explorerController: ExplorerController) : AutoCloseable {
|
||||||
private val log = LoggerFactory.getLogger(Explorer::class.java)
|
private val log = loggerFor<Explorer>()
|
||||||
|
|
||||||
private val executor = Executors.newSingleThreadExecutor()
|
private val executor = Executors.newSingleThreadExecutor()
|
||||||
private var process: Process? = null
|
private var process: Process? = null
|
||||||
@ -32,6 +32,11 @@ class Explorer(val explorerController: ExplorerController) : AutoCloseable {
|
|||||||
|
|
||||||
log.info("Launched Node Explorer for '{}'", config.legalName)
|
log.info("Launched Node Explorer for '{}'", config.legalName)
|
||||||
|
|
||||||
|
// Close these streams because no-one is using them.
|
||||||
|
safeClose(p.outputStream)
|
||||||
|
safeClose(p.inputStream)
|
||||||
|
safeClose(p.errorStream)
|
||||||
|
|
||||||
executor.submit {
|
executor.submit {
|
||||||
val exitValue = p.waitFor()
|
val exitValue = p.waitFor()
|
||||||
process = null
|
process = null
|
||||||
@ -46,4 +51,12 @@ class Explorer(val explorerController: ExplorerController) : AutoCloseable {
|
|||||||
process?.destroy()
|
process?.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun safeClose(c: AutoCloseable?) {
|
||||||
|
try {
|
||||||
|
c?.close()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
log.error("Failed to close stream: '{}'", e.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package net.corda.demobench.model
|
package net.corda.demobench.model
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory
|
import net.corda.demobench.loggerFor
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
class WebServer(val webServerController: WebServerController) : AutoCloseable {
|
class WebServer(val webServerController: WebServerController) : AutoCloseable {
|
||||||
private val log = LoggerFactory.getLogger(WebServer::class.java)
|
private val log = loggerFor<WebServer>()
|
||||||
|
|
||||||
private val executor = Executors.newSingleThreadExecutor()
|
private val executor = Executors.newSingleThreadExecutor()
|
||||||
private var process: Process? = null
|
private var process: Process? = null
|
||||||
@ -23,6 +23,11 @@ class WebServer(val webServerController: WebServerController) : AutoCloseable {
|
|||||||
|
|
||||||
log.info("Launched Web Server for '{}'", config.legalName)
|
log.info("Launched Web Server for '{}'", config.legalName)
|
||||||
|
|
||||||
|
// Close these streams because no-one is using them.
|
||||||
|
safeClose(p.outputStream)
|
||||||
|
safeClose(p.inputStream)
|
||||||
|
safeClose(p.errorStream)
|
||||||
|
|
||||||
executor.submit {
|
executor.submit {
|
||||||
val exitValue = p.waitFor()
|
val exitValue = p.waitFor()
|
||||||
process = null
|
process = null
|
||||||
@ -37,4 +42,12 @@ class WebServer(val webServerController: WebServerController) : AutoCloseable {
|
|||||||
process?.destroy()
|
process?.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun safeClose(c: AutoCloseable?) {
|
||||||
|
try {
|
||||||
|
c?.close()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
log.error("Failed to close stream: '{}'", e.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ import com.jediterm.terminal.TtyConnector
|
|||||||
import com.jediterm.terminal.ui.*
|
import com.jediterm.terminal.ui.*
|
||||||
import com.jediterm.terminal.ui.settings.SettingsProvider
|
import com.jediterm.terminal.ui.settings.SettingsProvider
|
||||||
import com.pty4j.PtyProcess
|
import com.pty4j.PtyProcess
|
||||||
import org.slf4j.LoggerFactory
|
import net.corda.demobench.loggerFor
|
||||||
|
|
||||||
import java.awt.*
|
import java.awt.*
|
||||||
import java.nio.charset.StandardCharsets.UTF_8
|
import java.nio.charset.StandardCharsets.UTF_8
|
||||||
@ -13,7 +13,7 @@ import java.util.concurrent.Executors
|
|||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class R3Pty(val name: String, settings: SettingsProvider, dimension: Dimension, val onExit: () -> Unit) : AutoCloseable {
|
class R3Pty(val name: String, settings: SettingsProvider, dimension: Dimension, val onExit: () -> Unit) : AutoCloseable {
|
||||||
private val log = LoggerFactory.getLogger(R3Pty::class.java)
|
private val log = loggerFor<R3Pty>()
|
||||||
|
|
||||||
private val executor = Executors.newSingleThreadExecutor()
|
private val executor = Executors.newSingleThreadExecutor()
|
||||||
|
|
||||||
|
@ -4,12 +4,12 @@ import com.google.common.net.HostAndPort
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.TimeUnit.SECONDS
|
import java.util.concurrent.TimeUnit.SECONDS
|
||||||
import net.corda.core.messaging.CordaRPCOps
|
import net.corda.core.messaging.CordaRPCOps
|
||||||
|
import net.corda.demobench.loggerFor
|
||||||
import net.corda.demobench.model.NodeConfig
|
import net.corda.demobench.model.NodeConfig
|
||||||
import net.corda.node.services.messaging.CordaRPCClient
|
import net.corda.node.services.messaging.CordaRPCClient
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
|
|
||||||
class NodeRPC(config: NodeConfig, start: () -> Unit, invoke: (CordaRPCOps) -> Unit): AutoCloseable {
|
class NodeRPC(config: NodeConfig, start: () -> Unit, invoke: (CordaRPCOps) -> Unit): AutoCloseable {
|
||||||
private val log = LoggerFactory.getLogger(NodeRPC::class.java)
|
private val log = loggerFor<NodeRPC>()
|
||||||
|
|
||||||
companion object Data {
|
companion object Data {
|
||||||
private val ONE_SECOND = SECONDS.toMillis(1)
|
private val ONE_SECOND = SECONDS.toMillis(1)
|
||||||
|
@ -107,6 +107,12 @@ class NodeTerminalView : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We only want to run one web server for each node.
|
||||||
|
* So disable the "launch" button when we have
|
||||||
|
* launched the web server and only reenable it when
|
||||||
|
* the web server has exited.
|
||||||
|
*/
|
||||||
fun configureWebButton(config: NodeConfig) {
|
fun configureWebButton(config: NodeConfig) {
|
||||||
launchWebButton.setOnAction {
|
launchWebButton.setOnAction {
|
||||||
launchWebButton.isDisable = true
|
launchWebButton.isDisable = true
|
||||||
|
Loading…
Reference in New Issue
Block a user