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>

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.

Properties

counterparty

abstract val counterparty: Party

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

destination

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

close

abstract fun close(): Unit

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

getCounterpartyFlowInfo

abstract fun getCounterpartyFlowInfo(maySkipCheckpoint: Boolean): FlowInfo
abstract fun getCounterpartyFlowInfo(): 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.

receive

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

Suspends until counterparty sends us a message of type R.

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

Suspends until counterparty sends us a message of type receiveType.

send

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

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

sendAndReceive

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, maySkipCheckpoint: Boolean): UntrustworthyData<R>
abstract fun <R : Any> sendAndReceive(receiveType: Class<R>, 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.

Extension Functions

contextLogger

fun Any.contextLogger(): <ERROR CLASS>

When called from a companion object, returns the logger for the enclosing class.