abstract class FetchDataFlow<T : NamedByHash, in W : Any> : FlowLogic<Result<T>>
An abstract flow for fetching typed data from a remote peer.
Given a set of hashes (IDs), either loads them from local disk or asks the remote peer to provide them.
A malicious response in which the data provided by the remote peer does not hash to the requested hash results in DownloadedVsRequestedDataMismatch being thrown. If the remote peer doesn't have an entry, it results in a HashNotFound exception being thrown.
By default this class does not insert data into any local database, if you want to do that after missing items were
fetched then override maybeWriteToDisk. You
T
- The ultimate type of the data being fetched.
W
- The wire type of the data being fetched, for when it isn't the same as the ultimate type.
Request |
data class Request |
Result |
data class Result<out T : NamedByHash> |
DownloadedVsRequestedDataMismatch |
class DownloadedVsRequestedDataMismatch : IllegalArgumentException |
DownloadedVsRequestedSizeMismatch |
class DownloadedVsRequestedSizeMismatch : IllegalArgumentException |
HashNotFound |
class HashNotFound : FlowException |
<init> |
FetchDataFlow(requests: Set<SecureHash>, otherSide: Party)
An abstract flow for fetching typed data from a remote peer. |
otherSide |
val otherSide: Party |
requests |
val requests: Set<SecureHash> |
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. |
call |
open fun call(): Result<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. |
convert |
open fun convert(wire: W): T |
load |
abstract fun load(txid: SecureHash): T? |
maybeWriteToDisk |
open fun maybeWriteToDisk(downloaded: List<T>): Unit |
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 |
open fun <R : Any> receive(receiveType: Class<R>, otherParty: Party): UntrustworthyData<R>
Suspends until the specified otherParty sends us a message of type receiveType. fun <R : Any> receive(otherParty: Party): UntrustworthyData<R>
Suspends until the specified otherParty sends us a message of type R. |
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>, : 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. |
FetchAttachmentsFlow |
class FetchAttachmentsFlow : FetchDataFlow<Attachment, ByteArray>
Given a set of hashes either loads from from local storage or requests them from the other peer. Downloaded attachments are saved to local storage automatically. |
FetchTransactionsFlow |
class FetchTransactionsFlow : FetchDataFlow<SignedTransaction, SignedTransaction>
Given a set of tx hashes (IDs), either loads them from local disk or asks the remote peer to provide them. |