Minor: remove ANSI progress observer, delete some currently dead code in the shell.

This commit is contained in:
Mike Hearn 2017-03-20 12:14:38 +01:00
parent 262c87a5c6
commit 2cb02c75eb
3 changed files with 7 additions and 75 deletions

View File

@ -122,7 +122,7 @@ object InteractiveShell {
"node" to node, "node" to node,
"services" to node.services, "services" to node.services,
"ops" to node.rpcOps, "ops" to node.rpcOps,
"mapper" to shellObjectMapper "mapper" to yamlInputMapper
)) ))
bootstrap.bootstrap() 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 // Return a standard Corda Jackson object mapper, configured to use YAML by default and with extra
// serializers. // serializers.
//
// TODO: This should become the default renderer rather than something used specifically by commands.
JacksonSupport.createInMemoryMapper(node.services.identityService, YAMLFactory()) 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 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 * 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) @Throws(NoApplicableConstructor::class)
fun runFlowFromString(invoke: (FlowLogic<*>) -> FlowStateMachine<*>, fun runFlowFromString(invoke: (FlowLogic<*>) -> FlowStateMachine<*>,
inputData: String, clazz: Class<out FlowLogic<*>>, 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, // 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. // and keep track of the reasons we failed so we can print them out if no constructors are usable.
val parser = StringToMethodCallParser(clazz, om) val parser = StringToMethodCallParser(clazz, om)
@ -289,12 +283,8 @@ object InteractiveShell {
} }
@JvmStatic @JvmStatic
fun printAndFollowRPCResponse(outputFormat: RpcResponsePrintingFormat, response: Any?, toStream: PrintWriter): CompletableFuture<Unit>? { fun printAndFollowRPCResponse(response: Any?, toStream: PrintWriter): CompletableFuture<Unit>? {
val printerFun = when (outputFormat) { val printerFun = { obj: Any? -> yamlMapper.writeValueAsString(obj) }
RpcResponsePrintingFormat.yaml -> { obj: Any? -> yamlMapper.writeValueAsString(obj) }
RpcResponsePrintingFormat.json -> { obj: Any? -> jsonMapper.writeValueAsString(obj) }
RpcResponsePrintingFormat.tostring -> { obj: Any? -> Emoji.renderIfSupported { obj.toString() } }
}
toStream.println(printerFun(response)) toStream.println(printerFun(response))
toStream.flush() toStream.flush()
return maybeFollow(response, printerFun, toStream) return maybeFollow(response, printerFun, toStream)

View File

@ -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()
}
}
}
}

View File

@ -60,7 +60,7 @@ public class run extends InteractiveShellCommand {
private Object processResult(Object result) { private Object processResult(Object result) {
if (result != null && !(result instanceof kotlin.Unit) && !(result instanceof Void)) { if (result != null && !(result instanceof kotlin.Unit) && !(result instanceof Void)) {
result = printAndFollowRPCResponse(RpcResponsePrintingFormat.yaml, result, out); result = printAndFollowRPCResponse(result, out);
} }
if (result instanceof Future) { if (result instanceof Future) {
Future future = (Future) result; Future future = (Future) result;