corda / net.corda.core.flows / FlowSession

FlowSession

@DoNotImplement abstract class 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

<init>

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.

FlowSession()

Properties

counterparty

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

abstract val counterparty: Party

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.

abstract val destination: Destination

Functions

close

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

abstract fun close(): Unit

getCounterpartyFlowInfo

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.

abstract fun getCounterpartyFlowInfo(maySkipCheckpoint: Boolean): FlowInfo
abstract fun getCounterpartyFlowInfo(): FlowInfo

receive

Suspends until counterparty sends us a message of type R.

fun <R : Any> receive(): UntrustworthyData<R>

Suspends until counterparty sends us a message of type receiveType.

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

send

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

abstract fun send(payload: Any, maySkipCheckpoint: Boolean): Unit
abstract fun send(payload: Any): Unit

sendAndReceive

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.

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 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.

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