Java code can now extend core FlowLogics which don't return anything (by using Void? instead of Unit)

This commit is contained in:
Shams Asari 2017-02-21 11:55:45 +00:00
parent 24ae89db18
commit ade32b16cb
3 changed files with 27 additions and 4 deletions

View File

@ -115,8 +115,10 @@ abstract class AbstractStateReplacementFlow {
}
}
// Type parameter should ideally be Unit but that prevents Java code from subclassing it (https://youtrack.jetbrains.com/issue/KT-15964).
// We use Void? instead of Unit? as that's what you'd use in Java.
abstract class Acceptor<in T>(val otherSide: Party,
override val progressTracker: ProgressTracker = tracker()) : FlowLogic<Unit>() {
override val progressTracker: ProgressTracker = tracker()) : FlowLogic<Void?>() {
companion object {
object VERIFYING : ProgressTracker.Step("Verifying state replacement proposal")
object APPROVING : ProgressTracker.Step("State replacement approved")
@ -126,7 +128,7 @@ abstract class AbstractStateReplacementFlow {
@Suspendable
@Throws(StateReplacementException::class)
override fun call() {
override fun call(): Void? {
progressTracker.currentStep = VERIFYING
val maybeProposal: UntrustworthyData<Proposal<T>> = receive(otherSide)
val stx: SignedTransaction = maybeProposal.unwrap {
@ -135,6 +137,7 @@ abstract class AbstractStateReplacementFlow {
it.stx
}
approve(stx)
return null
}
@Suspendable

View File

@ -85,15 +85,17 @@ object NotaryFlow {
*
* Additional transaction validation logic can be added when implementing [receiveAndVerifyTx].
*/
// See AbstractStateReplacementFlow.Acceptor for why it's Void?
abstract class Service(val otherSide: Party,
val timestampChecker: TimestampChecker,
val uniquenessProvider: UniquenessProvider) : FlowLogic<Unit>() {
val uniquenessProvider: UniquenessProvider) : FlowLogic<Void?>() {
@Suspendable
override fun call() {
override fun call(): Void? {
val (id, inputs, timestamp) = receiveAndVerifyTx()
validateTimestamp(timestamp)
commitInputStates(inputs, id)
signAndSendResponse(id)
return null
}
/**

View File

@ -0,0 +1,18 @@
package net.corda.flows;
import net.corda.core.crypto.Party;
import net.corda.core.utilities.ProgressTracker;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class AbstractStateReplacementFlowTest {
// Acceptor used to have a type parameter of Unit which prevented Java code from subclassing it (https://youtrack.jetbrains.com/issue/KT-15964).
private static class TestAcceptorCanBeInheritedInJava extends AbstractStateReplacementFlow.Acceptor {
public TestAcceptorCanBeInheritedInJava(@NotNull Party otherSide, @NotNull ProgressTracker progressTracker) {
super(otherSide, progressTracker);
}
@Override
protected void verifyProposal(@NotNull AbstractStateReplacementFlow.Proposal proposal) {}
}
}