corda / net.corda.core.flows / FlowLogic

# FlowLogic

`abstract class FlowLogic<out T>`

A sub-class of FlowLogic implements a flow using direct, straight line blocking code. Thus you can write complex flow logic in an ordinary fashion, without having to think about callbacks, restarting after a node crash, how many instances of your flow there are running and so on.

Invoking the network will cause the call stack to be suspended onto the heap and then serialized to a database using the Quasar fibers framework. Because of this, if you need access to data that might change over time, you should request it just-in-time via the serviceHub property which is provided. Don't try and keep data you got from a service across calls to send/receive/sendAndReceive because the world might change in arbitrary ways out from underneath you, for instance, if the node is restarted or reconfigured!

Additionally, be aware of what data you pin either via the stack or in your FlowLogic implementation. Very large objects or datasets will hurt performance by increasing the amount of data stored in each checkpoint.

If you'd like to use another FlowLogic class as a component of your own, construct it on the fly and then pass it to the subFlow method. It will return the result of that flow when it completes.

### Constructors

<init> | `FlowLogic()` A sub-class of FlowLogic implements a flow using direct, straight line blocking code. Thus you can write complex flow logic in an ordinary fashion, without having to think about callbacks, restarting after a node crash, how many instances of your flow there are running and so on.

### Properties

logger | `val logger: Logger` This is where you should log things to.
progressTracker | `open val progressTracker: ProgressTracker?` Override this to provide a ProgressTracker. If one is provided and stepped, the framework will do something helpful with the progress reports. If this flow is invoked as a subflow of another, then the tracker will be made a child of the current step in the parent. If it's null, this flow doesn't track progress.
runId | `val runId: StateMachineRunId` Returns a wrapped UUID object that identifies this state machine run (i.e. subflows have the same identifier as their parents).
serviceHub | `val serviceHub: ServiceHub` Provides access to big, heavy classes that may be reconstructed from time to time, e.g. across restarts. It is only available once the flow has started, which means it cannnot be accessed in the constructor. Either access this lazily or from inside call.
stateMachine | `var stateMachine: FlowStateMachine<*>` Internal only. Reference to the Fiber instance that is the top level controller for the entire flow. When inside a flow this is equivalent to Strand.currentStrand. This is public only because it must be accessed across module boundaries.

### Functions

call | `abstract fun call(): T` This is where you fill out your business logic. The returned object will usually be ignored, but can be helpful if this flow is meant to be used as a subflow.
getCounterpartyMarker | `open fun getCounterpartyMarker(party: Party): Class<*>` Return the marker Class which party has used to register the counterparty flow that is to execute on the other side. The default implementation returns the class object of this FlowLogic, but any Class instance will do as long as the other side registers with it.
receive | `fun <R : Any> receive(otherParty: Party): UntrustworthyData<R>` Suspends until the specified otherParty sends us a message of type R. `open fun <R : Any> receive(receiveType: Class<R>, otherParty: Party): UntrustworthyData<R>` Suspends until the specified otherParty sends us a message of type receiveType.
send | `open fun send(otherParty: Party, payload: Any): Unit` Queues the given payload for sending to the otherParty and continues without suspending.
sendAndReceive | `fun <R : Any> sendAndReceive(otherParty: Party, payload: Any): UntrustworthyData<R>` Serializes and queues the given payload object for sending to the otherParty. Suspends until a response is received, which must be of the given R type. `open fun <R : Any> sendAndReceive(receiveType: Class<R>, otherParty: Party, payload: Any): UntrustworthyData<R>` Serializes and queues the given payload object for sending to the otherParty. Suspends until a response is received, which must be of the given receiveType. Remember that when receiving data from other parties the data should not be trusted until it's been thoroughly verified for consistency and that all expectations are satisfied, as a malicious peer may send you subtly corrupted data in order to exploit your code.
subFlow | `open fun <R> subFlow(subLogic: FlowLogic<R>, shareParentSessions: Boolean = false): R` Invokes the given subflow. This function returns once the subflow completes successfully with the result returned by that subflows call method. If the subflow has a progress tracker, it is attached to the current step in this flow's progress tracker.
track | `fun track(): Pair<String, Observable<String>>?` Returns a pair of the current progress step, as a string, and an observable of stringified changes to the progressTracker.
waitForLedgerCommit | `fun waitForLedgerCommit(hash: SecureHash): SignedTransaction` Suspends the flow until the transaction with the specified ID is received, successfully verified and sent to the vault for processing. Note that this call suspends until the transaction is considered valid by the local node, but that doesn't imply the vault will consider it relevant.

### Inheritors

AbstractCashFlow | `abstract class AbstractCashFlow : FlowLogic<SignedTransaction>` Initiates a flow that produces an Issue/Move or Exit Cash transaction.
Acceptor | `abstract class Acceptor<in T> : FlowLogic<Void?>`
BroadcastTransactionFlow | `class BroadcastTransactionFlow : FlowLogic<Unit>` Notify the specified parties about a transaction. The remote peers will download this transaction and its dependency graph, verifying them all. The flow returns when all peers have acknowledged the transactions as valid. Normally you wouldn't use this directly, it would be called via FinalityFlow.
Buyer | `class Buyer : FlowLogic<SignedTransaction>`
Client | `class Client : FlowLogic<List<WithKey>>` A flow to be used by a party for obtaining signature(s) from a NotaryService ascertaining the transaction timestamp is correct and none of its inputs have been used in another completed transaction.
FetchDataFlow | `abstract class FetchDataFlow<T : NamedByHash, in W : Any> : FlowLogic<Result<T>>` An abstract flow for fetching typed data from a remote peer.
FinalityFlow | `class FinalityFlow : FlowLogic<List<SignedTransaction>>` Verifies the given transactions, then sends them to the named notaries. If the notary agrees that the transactions are acceptable then they are from that point onwards committed to the ledger, and will be written through to the vault. Additionally they will be distributed to the parties reflected in the participants list of the states.
Instigator | `abstract class Instigator<out S : ContractState, out T : ContractState, out M> : FlowLogic<StateAndRef<T>>` The Instigator assembles the transaction for state replacement and sends out change proposals to all participants (Acceptor) of that state. If participants agree to the proposed change, they each sign the transaction. Finally, Instigator sends the transaction containing all participants' signatures to the notary for signature, and then back to each participant so they can record it and use the new updated state for future transactions.
IssuanceRequester | `class IssuanceRequester : FlowLogic<SignedTransaction>` IssuanceRequester should be used by a client to ask a remote node to issue some FungibleAsset with the given details. Returns the transaction created by the Issuer to move the cash to the Requester.
Issuer | `class Issuer : FlowLogic<SignedTransaction>` Issuer refers to a Node acting as a Bank Issuer of FungibleAsset, and processes requests from a IssuanceRequester client. Returns the generated transaction representing the transfer of the Issued to the issue requester.
NotifyTransactionHandler | `class NotifyTransactionHandler : FlowLogic<Unit>`
Primary | `abstract class Primary : FlowLogic<SignedTransaction>` Abstracted bilateral deal flow participant that initiates communication/handshake.
ResolveTransactionsFlow | `class ResolveTransactionsFlow : FlowLogic<List<LedgerTransaction>>` This flow is used to verify the validity of a transaction by recursively checking the validity of all the dependencies. Once a transaction is checked it's inserted into local storage so it can be relayed and won't be checked again.
RunScheduled | `class RunScheduled : FlowLogic<Unit>`
Secondary | `abstract class Secondary<U> : FlowLogic<SignedTransaction>` Abstracted bilateral deal flow participant that is recipient of initial communication.
Seller | `class Seller : FlowLogic<SignedTransaction>`
Service | `abstract class Service : FlowLogic<Void?>` A flow run by a notary service that handles notarisation requests.