mirror of
https://github.com/corda/corda.git
synced 2025-06-17 14:48:16 +00:00
Refactor then/success/failure (#984)
to make ListenableFuture replacement less fiddly.
This commit is contained in:
@ -4,13 +4,11 @@ import com.codahale.metrics.JmxReporter
|
||||
import com.google.common.util.concurrent.Futures
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import com.google.common.util.concurrent.SettableFuture
|
||||
import net.corda.core.flatMap
|
||||
import net.corda.core.*
|
||||
import net.corda.core.messaging.RPCOps
|
||||
import net.corda.core.minutes
|
||||
import net.corda.core.node.ServiceHub
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.seconds
|
||||
import net.corda.core.success
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import net.corda.core.utilities.parseNetworkHostAndPort
|
||||
@ -298,27 +296,29 @@ open class Node(override val configuration: FullNodeConfiguration,
|
||||
override fun start(): Node {
|
||||
super.start()
|
||||
|
||||
networkMapRegistrationFuture.success(serverThread) {
|
||||
// Begin exporting our own metrics via JMX. These can be monitored using any agent, e.g. Jolokia:
|
||||
//
|
||||
// https://jolokia.org/agent/jvm.html
|
||||
JmxReporter.
|
||||
forRegistry(services.monitoringService.metrics).
|
||||
inDomain("net.corda").
|
||||
createsObjectNamesWith { _, domain, name ->
|
||||
// Make the JMX hierarchy a bit better organised.
|
||||
val category = name.substringBefore('.')
|
||||
val subName = name.substringAfter('.', "")
|
||||
if (subName == "")
|
||||
ObjectName("$domain:name=$category")
|
||||
else
|
||||
ObjectName("$domain:type=$category,name=$subName")
|
||||
}.
|
||||
build().
|
||||
start()
|
||||
networkMapRegistrationFuture.thenMatch({
|
||||
serverThread.execute {
|
||||
// Begin exporting our own metrics via JMX. These can be monitored using any agent, e.g. Jolokia:
|
||||
//
|
||||
// https://jolokia.org/agent/jvm.html
|
||||
JmxReporter.
|
||||
forRegistry(services.monitoringService.metrics).
|
||||
inDomain("net.corda").
|
||||
createsObjectNamesWith { _, domain, name ->
|
||||
// Make the JMX hierarchy a bit better organised.
|
||||
val category = name.substringBefore('.')
|
||||
val subName = name.substringAfter('.', "")
|
||||
if (subName == "")
|
||||
ObjectName("$domain:name=$category")
|
||||
else
|
||||
ObjectName("$domain:type=$category,name=$subName")
|
||||
}.
|
||||
build().
|
||||
start()
|
||||
|
||||
(startupComplete as SettableFuture<Unit>).set(Unit)
|
||||
}
|
||||
(startupComplete as SettableFuture<Unit>).set(Unit)
|
||||
}
|
||||
}, {})
|
||||
shutdownHook = addShutdownHook {
|
||||
stop()
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ open class NodeStartup(val args: Array<String>) {
|
||||
node.start()
|
||||
printPluginsAndServices(node)
|
||||
|
||||
node.networkMapRegistrationFuture.success {
|
||||
node.networkMapRegistrationFuture.thenMatch({
|
||||
val elapsed = (System.currentTimeMillis() - startTime) / 10 / 100.0
|
||||
// TODO: Replace this with a standard function to get an unambiguous rendering of the X.500 name.
|
||||
val name = node.info.legalIdentity.name.orgName ?: node.info.legalIdentity.name.commonName
|
||||
@ -111,14 +111,14 @@ open class NodeStartup(val args: Array<String>) {
|
||||
|
||||
// Don't start the shell if there's no console attached.
|
||||
val runShell = !cmdlineOptions.noLocalShell && System.console() != null
|
||||
node.startupComplete then {
|
||||
node.startupComplete.then {
|
||||
try {
|
||||
InteractiveShell.startShell(cmdlineOptions.baseDirectory, runShell, cmdlineOptions.sshdServer, node)
|
||||
} catch(e: Throwable) {
|
||||
logger.error("Shell failed to start", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {})
|
||||
node.run()
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ class NodeMessagingClient(override val config: NodeConfiguration,
|
||||
|
||||
// Create a queue, consumer and producer for handling P2P network messages.
|
||||
p2pConsumer = makeP2PConsumer(session, true)
|
||||
networkMapRegistrationFuture.success {
|
||||
networkMapRegistrationFuture.thenMatch({
|
||||
state.locked {
|
||||
log.info("Network map is complete, so removing filter from P2P consumer.")
|
||||
try {
|
||||
@ -194,7 +194,7 @@ class NodeMessagingClient(override val config: NodeConfiguration,
|
||||
}
|
||||
p2pConsumer = makeP2PConsumer(session, false)
|
||||
}
|
||||
}
|
||||
}, {})
|
||||
|
||||
rpcServer = RPCServer(rpcOps, NODE_USER, NODE_USER, locator, userService, config.myLegalName)
|
||||
|
||||
|
@ -195,7 +195,7 @@ class StateMachineManager(val serviceHub: ServiceHubInternal,
|
||||
fun start() {
|
||||
restoreFibersFromCheckpoints()
|
||||
listenToLedgerTransactions()
|
||||
serviceHub.networkMapCache.mapServiceRegistered.then(executor) { resumeRestoredFibers() }
|
||||
serviceHub.networkMapCache.mapServiceRegistered.then { executor.execute(this::resumeRestoredFibers) }
|
||||
}
|
||||
|
||||
private fun listenToLedgerTransactions() {
|
||||
|
@ -25,7 +25,7 @@ class FlowWatchPrintingSubscriber(private val toStream: RenderPrintWriter) : Sub
|
||||
init {
|
||||
// The future is public and can be completed by something else to indicate we don't wish to follow
|
||||
// anymore (e.g. the user pressing Ctrl-C).
|
||||
future then { unsubscribe() }
|
||||
future.then { unsubscribe() }
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
|
@ -394,7 +394,7 @@ object InteractiveShell {
|
||||
init {
|
||||
// The future is public and can be completed by something else to indicate we don't wish to follow
|
||||
// anymore (e.g. the user pressing Ctrl-C).
|
||||
future then { unsubscribe() }
|
||||
future.then { unsubscribe() }
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
|
Reference in New Issue
Block a user