core.protocols / ProtocolLogic

# ProtocolLogic

`abstract class ProtocolLogic<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

### Functions

call | `abstract fun call(): T` This is where you fill out your business logic.
receive | `fun <T : Any> receive(topic: String, sessionIDForReceive: Long): UntrustworthyData<T>` `fun <T : Any> receive(topic: String, sessionIDForReceive: Long, clazz: Class<T>): UntrustworthyData<T>`
send | `fun send(topic: String, destination: MessageRecipients, sessionID: Long, obj: Any): Unit`
sendAndReceive | `fun <T : Any> sendAndReceive(topic: String, destination: MessageRecipients, sessionIDForSend: Long, sessionIDForReceive: Long, obj: 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

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<Boolean>`
Buyer | `class Buyer : ProtocolLogic<SignedTransaction>`
FetchDataProtocol | `abstract class FetchDataProtocol<T : NamedByHash, W : Any> : ProtocolLogic<Result<T>>` An abstract protocol for fetching typed data from a remote peer.
Primary | `abstract class Primary<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<T> : 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>`
TimestampingProtocol | `class TimestampingProtocol : ProtocolLogic<LegallyIdentifiable>` The TimestampingProtocol class is the client code that talks to a NodeTimestamperService on some remote node. It is a ProtocolLogic, meaning it can either be a sub-protocol of some other protocol, or be driven independently.
TraderDemoProtocolBuyer | `class TraderDemoProtocolBuyer : ProtocolLogic<Unit>`
TraderDemoProtocolSeller | `class TraderDemoProtocolSeller : ProtocolLogic<Unit>`
Updater | `class Updater : ProtocolLogic<Boolean>`