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.
topic | `abstract val topic: String` The topic to use when communicating with other parties. If more than one topic is required then use sub-protocols. Note that this is temporary until protocol sessions are properly implemented.

### Functions

call | `abstract fun call(): T` This is where you fill out your business logic.
receive | `fun <T : Any> receive(sessionIDForReceive: Long): UntrustworthyData<T>` `fun <T : Any> receive(sessionIDForReceive: Long, receiveType: Class<T>): UntrustworthyData<T>`
send | `fun send(destination: Party, sessionID: Long, payload: Any): Unit`
sendAndReceive | `fun <T : Any> sendAndReceive(destination: Party, sessionIDForSend: Long, sessionIDForReceive: Long, payload: Any): UntrustworthyData<T>`
subProtocol | `fun <R> subProtocol(subLogic: ProtocolLogic<R>): R` Invokes the given subprotocol by simply passing through this ProtocolLogics reference to the ProtocolStateMachine and then calling the call method.

### 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>`
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.
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<S : ContractState, T> : ProtocolLogic<StateAndRef<S>>`
Primary | `abstract class Primary<out U> : 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<Unit>` This protocol fetches each transaction identified by the given hashes from either disk or network, along with all their dependencies, and verifies them together using a single TransactionGroup. If no exception is thrown, then all the transactions have been successfully verified and inserted into the local database.
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.