com.r3corda.core.protocols / ProtocolLogic

# ProtocolLogic

`abstract class ProtocolLogic<out T>`

A sub-class of ProtocolLogic implements a protocol flow using direct, straight line blocking code. Thus you can write complex protocol logic in an ordinary fashion, without having to think about callbacks, restarting after a node crash, how many instances of your protocol 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. Dont 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 ProtocolLogic implementation. Very large objects or datasets will hurt performance by increasing the amount of data stored in each checkpoint.

If youd like to use another ProtocolLogic class as a component of your own, construct it on the fly and then pass it to the subProtocol method. It will return the result of that protocol when it completes.

### Constructors

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

### Properties

logger | `val logger: <ERROR CLASS>` 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 protocol is invoked as a sub-protocol of another, then the tracker will be made a child of the current step in the parent. If its null, this protocol doesnt track progress.
psm | `lateinit var psm: ProtocolStateMachine<*>` Reference to the Fiber instance that is the top level controller for the entire flow.
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 protocol has started, which means it cannnot be accessed in the constructor. Either access this lazily or from inside call.

### Functions

call | `abstract fun call(): T` This is where you fill out your business logic.
getCounterpartyMarker | `open fun getCounterpartyMarker(party: Party): Class<*>` Return the marker Class which party has used to register the counterparty protocol that is to execute on the other side. The default implementation returns the class object of this ProtocolLogic, but any Class instance will do as long as the other side registers with it.
receive | `fun <T : Any> receive(otherParty: Party): UntrustworthyData<T>` `fun <T : Any> receive(otherParty: Party, receiveType: Class<T>): UntrustworthyData<T>`
send | `fun send(otherParty: Party, payload: Any): Unit`
sendAndReceive | `fun <T : Any> sendAndReceive(otherParty: Party, payload: Any): UntrustworthyData<T>` `fun <T : Any> sendAndReceive(otherParty: Party, payload: Any, receiveType: Class<T>): UntrustworthyData<T>`
subProtocol | `fun <R> subProtocol(subLogic: ProtocolLogic<R>, shareParentSessions: Boolean = false): R` Invokes the given subprotocol by simply passing through this ProtocolLogics reference to the ProtocolStateMachine and then calling the call method.
track | `fun track(): <ERROR CLASS><String, <ERROR CLASS><String>>?`

### Inheritors

Acceptor | `abstract class Acceptor<T> : ProtocolLogic<Unit>`
Broadcast | `class Broadcast : ProtocolLogic<Boolean>` This takes a Java Integer rather than Kotlin Int as that is what we end up with in the calling map and currently we do not support coercing numeric types in the reflective search for matching constructors.
Broadcast | `class Broadcast : ProtocolLogic<Unit>`
BroadcastTransactionProtocol | `class BroadcastTransactionProtocol : ProtocolLogic<Unit>` Notify all involved parties about a transaction, including storing a copy. Normally this would be called via FinalityProtocol.
Buyer | `class Buyer : ProtocolLogic<SignedTransaction>`
Client | `class Client : ProtocolLogic<LegallyIdentifiable>` A protocol to be used for obtaining a signature from a NotaryService ascertaining the transaction timestamp is correct and none of its inputs have been used in another completed transaction.
FetchDataProtocol | `abstract class FetchDataProtocol<T : NamedByHash, in W : Any> : ProtocolLogic<Result<T>>` An abstract protocol for fetching typed data from a remote peer.
FinalityProtocol | `class FinalityProtocol : ProtocolLogic<Unit>` Finalise a transaction by notarising it, then recording it locally, and then sending it to all involved parties.
FixQueryProtocol | `class FixQueryProtocol : ProtocolLogic<Fix>`
FixSignProtocol | `class FixSignProtocol : ProtocolLogic<LegallyIdentifiable>`
FixingRoleDecider | `class FixingRoleDecider : ProtocolLogic<Unit>` This protocol looks at the deal and decides whether to be the Fixer or Floater role in agreeing a fixing.
Instigator | `abstract class Instigator<out S : ContractState, T> : ProtocolLogic<StateAndRef<S>>`
NotifyTransactionHandler | `class NotifyTransactionHandler : ProtocolLogic<Unit>`
Primary | `abstract class Primary : ProtocolLogic<SignedTransaction>` Abstracted bilateral deal protocol participant that initiates communication/handshake.
RatesFixProtocol | `open class RatesFixProtocol : ProtocolLogic<Unit>` This protocol queries the given oracle for an interest rate fix, and if it is within the given tolerance embeds the fix in the transaction and then proceeds to get the oracle to sign it. Although the call method combines the query and signing step, you can run the steps individually by constructing this object and then using the public methods for each step.
Requester | `class Requester : ProtocolLogic<SignedTransaction>`
ResolveTransactionsProtocol | `class ResolveTransactionsProtocol : ProtocolLogic<List<LedgerTransaction>>` This protocol is used to verify the validity of a transaction by recursively checking the validity of all the dependencies. Once a transaction is checked its inserted into local storage so it can be relayed and wont be checked again.
Secondary | `abstract class Secondary<U> : ProtocolLogic<SignedTransaction>` Abstracted bilateral deal protocol participant that is recipient of initial communication.
Seller | `class Seller : ProtocolLogic<SignedTransaction>`
Service | `class Service : ProtocolLogic<Unit>` Checks that the timestamp command is valid (if present) and commits the input state, or returns a conflict if any of the input states have been previously committed.