Removed the ExitServerFlow

This commit is contained in:
Shams Asari 2017-04-21 18:04:57 +01:00
parent 160d13b6f7
commit 325f3f791f
4 changed files with 0 additions and 91 deletions

View File

@ -8,7 +8,6 @@ import net.corda.core.messaging.startFlow
import net.corda.core.utilities.loggerFor
import net.corda.irs.contract.InterestRateSwap
import net.corda.irs.flows.AutoOfferFlow
import net.corda.irs.flows.ExitServerFlow
import net.corda.irs.flows.UpdateBusinessDayFlow
import java.net.URI
import java.time.LocalDate
@ -34,9 +33,6 @@ import javax.ws.rs.core.Response
* simulate any associated business processing (currently fixing).
*
* TODO: replace simulated date advancement with business event based implementation
*
* PUT /api/irs/restart - (empty payload) cause the node to restart for API user emergency use in case any servers become unresponsive,
* or if the demodate or population of deals should be reset (will only work while persistence is disabled).
*/
@Path("irs")
class InterestRateSwapAPI(val rpc: CordaRPCOps) {
@ -112,12 +108,4 @@ class InterestRateSwapAPI(val rpc: CordaRPCOps) {
fun fetchDemoDate(): LocalDate {
return LocalDateTime.ofInstant(rpc.currentNodeTime(), ZoneId.systemDefault()).toLocalDate()
}
@PUT
@Path("restart")
@Consumes(MediaType.APPLICATION_JSON)
fun exitServer(): Response {
rpc.startFlow(ExitServerFlow::Broadcast, 83).returnValue.getOrThrow()
return Response.ok().build()
}
}

View File

@ -1,76 +0,0 @@
package net.corda.irs.flows
import co.paralleluniverse.fibers.Suspendable
import co.paralleluniverse.strands.Strand
import net.corda.core.crypto.Party
import net.corda.core.flows.FlowLogic
import net.corda.core.node.CordaPluginRegistry
import net.corda.core.node.NodeInfo
import net.corda.core.node.PluginServiceHub
import net.corda.core.utilities.unwrap
import net.corda.testing.node.MockNetworkMapCache
import java.util.concurrent.TimeUnit
import java.util.function.Function
object ExitServerFlow {
// Will only be enabled if you install the Handler
@Volatile private var enabled = false
// This is not really a HandshakeMessage but needs to be so that the send uses the default session ID. This will
// resolve itself when the flow session stuff is done.
data class ExitMessage(val exitCode: Int)
class Plugin : CordaPluginRegistry() {
override val servicePlugins = listOf(Function(::Service))
}
class Service(services: PluginServiceHub) {
init {
services.registerFlowInitiator(Broadcast::class.java, ::ExitServerHandler)
enabled = true
}
}
private class ExitServerHandler(val otherParty: Party) : FlowLogic<Unit>() {
override fun call() {
// Just to validate we got the message
if (enabled) {
val message = receive<ExitMessage>(otherParty).unwrap { it }
System.exit(message.exitCode)
}
}
}
/**
* This takes a Java Integer rather than Kotlin Int as that is what we end up with in the calling map and currently
* we do not support coercing numeric types in the reflective search for matching constructors.
*/
class Broadcast(val exitCode: Int) : FlowLogic<Boolean>() {
@Suspendable
override fun call(): Boolean {
if (enabled) {
for (recipient in serviceHub.networkMapCache.partyNodes) {
doNextRecipient(recipient)
}
// Sleep a little in case any async message delivery to other nodes needs to happen
Strand.sleep(1, TimeUnit.SECONDS)
System.exit(exitCode)
}
return enabled
}
@Suspendable
private fun doNextRecipient(recipient: NodeInfo) {
if (recipient.address is MockNetworkMapCache.MockAddress) {
// Ignore
} else {
send(recipient.legalIdentity, ExitMessage(exitCode))
}
}
}
}

View File

@ -6,7 +6,6 @@ import net.corda.core.node.CordaPluginRegistry
import net.corda.irs.api.InterestRateSwapAPI
import net.corda.irs.contract.InterestRateSwap
import net.corda.irs.flows.AutoOfferFlow
import net.corda.irs.flows.ExitServerFlow
import net.corda.irs.flows.FixingFlow
import net.corda.irs.flows.UpdateBusinessDayFlow
import java.time.Duration
@ -22,7 +21,6 @@ class IRSPlugin : CordaPluginRegistry() {
override val requiredFlows: Map<String, Set<String>> = mapOf(
AutoOfferFlow.Requester::class.java.name to setOf(InterestRateSwap.State::class.java.name),
UpdateBusinessDayFlow.Broadcast::class.java.name to setOf(LocalDate::class.java.name),
ExitServerFlow.Broadcast::class.java.name to setOf(kotlin.Int::class.java.name),
FixingFlow.FixingRoleDecider::class.java.name to setOf(StateRef::class.java.name, Duration::class.java.name),
FixingFlow.Floater::class.java.name to setOf(Party::class.java.name, FixingFlow.FixingSession::class.java.name))
}

View File

@ -2,5 +2,4 @@
net.corda.irs.plugin.IRSPlugin
net.corda.irs.api.NodeInterestRates$Plugin
net.corda.irs.flows.AutoOfferFlow$Plugin
net.corda.irs.flows.ExitServerFlow$Plugin
net.corda.irs.flows.UpdateBusinessDayFlow$Plugin