FlowSession

A FlowSession is a handle on a communication sequence between two paired flows, possibly running on separate nodes. It is used to send and receive messages between the flows as well as to query information about the counter-flow.

There are two ways of obtaining such a session:

  1. Calling FlowLogic.initiateFlow. This will create a FlowSession object on which the first send/receive operation will attempt to kick off a corresponding InitiatedBy flow on the counterparty's node.

  2. As constructor parameter to InitiatedBy flows. This session is the one corresponding to the initiating flow and may be used for replies.

To port flows using the old Party-based API:

Look for Deprecated usages of send/receive/sendAndReceive/getFlowInfo.

If it's an InitiatingFlow:

Look for the send/receive that kicks off the counter flow. Insert a

val session = initiateFlow(party)

and use this session afterwards for send/receives. For example: send(party, something) will become session.send(something)

If it's an InitiatedBy flow:

Change the constructor to take an otherSideSession: FlowSession instead of a counterparty: Party Then look for usages of the deprecated functions and change them to use the FlowSession For example: send(counterparty, something) will become otherSideSession.send(something)

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
abstract val counterparty: Party

If the destination on the other side of this session is a Party then returns that, otherwise throws IllegalStateException.

Link copied to clipboard
abstract val destination: Destination

The Destination on the other side of this session. In the case of a session created by FlowLogic.initiateFlow this is the same destination as the one passed to that function.

Functions

Link copied to clipboard
abstract fun close()

Closes this session and performs cleanup of any resources tied to this session.

Link copied to clipboard
abstract fun getCounterpartyFlowInfo(maySkipCheckpoint: Boolean): FlowInfo

Returns a FlowInfo object describing the flow counterparty is using. With FlowInfo.flowVersion it provides the necessary information needed for the evolution of flows and enabling backwards compatibility.

Link copied to clipboard
inline fun <R : Any> receive(): UntrustworthyData<R>

Suspends until counterparty sends us a message of type R.

abstract fun <R : Any> receive(receiveType: Class<R>): UntrustworthyData<R>
abstract fun <R : Any> receive(receiveType: Class<R>, maySkipCheckpoint: Boolean): UntrustworthyData<R>

Suspends until counterparty sends us a message of type receiveType.

Link copied to clipboard
abstract fun send(payload: Any)
abstract fun send(payload: Any, maySkipCheckpoint: Boolean)

Queues the given payload for sending to the counterparty and continues without suspending.

Link copied to clipboard
inline fun <R : Any> sendAndReceive(payload: Any): UntrustworthyData<R>

Serializes and queues the given payload object for sending to the counterparty. Suspends until a response is received, which must be of the given R type.

abstract fun <R : Any> sendAndReceive(receiveType: Class<R>, payload: Any): UntrustworthyData<R>
abstract fun <R : Any> sendAndReceive(receiveType: Class<R>, payload: Any, maySkipCheckpoint: Boolean): UntrustworthyData<R>

Serializes and queues the given payload object for sending to the counterparty. 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.