mirror of
https://github.com/corda/corda.git
synced 2025-01-31 00:24:59 +00:00
Minor: remove ANSI progress observer, delete some currently dead code in the shell.
This commit is contained in:
parent
262c87a5c6
commit
2cb02c75eb
@ -122,7 +122,7 @@ object InteractiveShell {
|
||||
"node" to node,
|
||||
"services" to node.services,
|
||||
"ops" to node.rpcOps,
|
||||
"mapper" to shellObjectMapper
|
||||
"mapper" to yamlInputMapper
|
||||
))
|
||||
bootstrap.bootstrap()
|
||||
|
||||
@ -155,11 +155,9 @@ object InteractiveShell {
|
||||
}
|
||||
}
|
||||
|
||||
val shellObjectMapper: ObjectMapper by lazy {
|
||||
private val yamlInputMapper: ObjectMapper by lazy {
|
||||
// Return a standard Corda Jackson object mapper, configured to use YAML by default and with extra
|
||||
// serializers.
|
||||
//
|
||||
// TODO: This should become the default renderer rather than something used specifically by commands.
|
||||
JacksonSupport.createInMemoryMapper(node.services.identityService, YAMLFactory())
|
||||
}
|
||||
|
||||
@ -182,12 +180,8 @@ object InteractiveShell {
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: This should become the default renderer rather than something used specifically by commands.
|
||||
private val yamlMapper by lazy { createOutputMapper(YAMLFactory()) }
|
||||
private val jsonMapper by lazy { createOutputMapper(JsonFactory()) }
|
||||
|
||||
enum class RpcResponsePrintingFormat {
|
||||
yaml, json, tostring
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the 'flow' shell command. Takes a name fragment and finds a matching flow, or prints out
|
||||
@ -248,7 +242,7 @@ object InteractiveShell {
|
||||
@Throws(NoApplicableConstructor::class)
|
||||
fun runFlowFromString(invoke: (FlowLogic<*>) -> FlowStateMachine<*>,
|
||||
inputData: String, clazz: Class<out FlowLogic<*>>,
|
||||
om: ObjectMapper = shellObjectMapper): FlowStateMachine<*> {
|
||||
om: ObjectMapper = yamlInputMapper): FlowStateMachine<*> {
|
||||
// For each constructor, attempt to parse the input data as a method call. Use the first that succeeds,
|
||||
// and keep track of the reasons we failed so we can print them out if no constructors are usable.
|
||||
val parser = StringToMethodCallParser(clazz, om)
|
||||
@ -289,12 +283,8 @@ object InteractiveShell {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun printAndFollowRPCResponse(outputFormat: RpcResponsePrintingFormat, response: Any?, toStream: PrintWriter): CompletableFuture<Unit>? {
|
||||
val printerFun = when (outputFormat) {
|
||||
RpcResponsePrintingFormat.yaml -> { obj: Any? -> yamlMapper.writeValueAsString(obj) }
|
||||
RpcResponsePrintingFormat.json -> { obj: Any? -> jsonMapper.writeValueAsString(obj) }
|
||||
RpcResponsePrintingFormat.tostring -> { obj: Any? -> Emoji.renderIfSupported { obj.toString() } }
|
||||
}
|
||||
fun printAndFollowRPCResponse(response: Any?, toStream: PrintWriter): CompletableFuture<Unit>? {
|
||||
val printerFun = { obj: Any? -> yamlMapper.writeValueAsString(obj) }
|
||||
toStream.println(printerFun(response))
|
||||
toStream.flush()
|
||||
return maybeFollow(response, printerFun, toStream)
|
||||
|
@ -1,58 +0,0 @@
|
||||
package net.corda.node.utilities
|
||||
|
||||
import net.corda.core.ThreadBox
|
||||
import net.corda.core.flows.FlowLogic
|
||||
import net.corda.node.services.statemachine.StateMachineManager
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* This observes the [StateMachineManager] and follows the progress of [FlowLogic]s until they complete in the order
|
||||
* they are added to the [StateMachineManager].
|
||||
*/
|
||||
class ANSIProgressObserver(val smm: StateMachineManager) {
|
||||
init {
|
||||
smm.changes.subscribe { change ->
|
||||
when (change.addOrRemove) {
|
||||
AddOrRemove.ADD -> addFlowLogic(change.logic)
|
||||
AddOrRemove.REMOVE -> removeFlowLogic(change.logic)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Content {
|
||||
var currentlyRendering: FlowLogic<*>? = null
|
||||
val pending = ArrayDeque<FlowLogic<*>>()
|
||||
}
|
||||
|
||||
private val state = ThreadBox(Content())
|
||||
|
||||
private fun wireUpProgressRendering() {
|
||||
state.locked {
|
||||
// Repeat if the progress of the ones we pop from the queue are already done
|
||||
do {
|
||||
currentlyRendering = pending.poll()
|
||||
if (currentlyRendering?.progressTracker != null) {
|
||||
ANSIProgressRenderer.progressTracker = currentlyRendering!!.progressTracker
|
||||
}
|
||||
} while (currentlyRendering?.progressTracker?.hasEnded ?: false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeFlowLogic(flowLogic: FlowLogic<*>) {
|
||||
state.locked {
|
||||
pending.remove(flowLogic)
|
||||
if (currentlyRendering == flowLogic) {
|
||||
wireUpProgressRendering()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addFlowLogic(flowLogic: FlowLogic<*>) {
|
||||
state.locked {
|
||||
pending.add(flowLogic)
|
||||
if (currentlyRendering?.progressTracker?.hasEnded ?: true) {
|
||||
wireUpProgressRendering()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -60,7 +60,7 @@ public class run extends InteractiveShellCommand {
|
||||
|
||||
private Object processResult(Object result) {
|
||||
if (result != null && !(result instanceof kotlin.Unit) && !(result instanceof Void)) {
|
||||
result = printAndFollowRPCResponse(RpcResponsePrintingFormat.yaml, result, out);
|
||||
result = printAndFollowRPCResponse(result, out);
|
||||
}
|
||||
if (result instanceof Future) {
|
||||
Future future = (Future) result;
|
||||
|
Loading…
x
Reference in New Issue
Block a user