public class FlowLogic<T>
A sub-class of class FlowLogic
implements a flow using direct, straight line blocking code. Thus you
can write complex flow logic in an ordinary fashion, without having to think about callbacks, restarting after
a node crash, how many instances of your flow 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. Don't 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 class FlowLogic
implementation. Very large
objects or datasets will hurt performance by increasing the amount of data stored in each checkpoint.
If you'd like to use another FlowLogic class as a component of your own, construct it on the fly and then pass it to the subFlow method. It will return the result of that flow when it completes.
class FlowLogic
,
class FlowLogic
Constructor and Description |
---|
FlowLogic()
A sub-class of
class FlowLogic implements a flow using direct, straight line blocking code. Thus you
can write complex flow logic in an ordinary fashion, without having to think about callbacks, restarting after
a node crash, how many instances of your flow there are running and so on. |
Modifier and Type | Method and Description |
---|---|
T |
call()
This is where you fill out your business logic. The returned object will usually be ignored, but can be
helpful if this flow is meant to be used as a subflow.
|
java.lang.Class<?> |
getCounterpartyMarker(Party party)
|
org.slf4j.Logger |
getLogger()
This is where you should log things to.
|
ProgressTracker |
getProgressTracker()
Override this to provide a
class ProgressTracker . If one is provided and stepped, the framework will do something
helpful with the progress reports. If this flow is invoked as a subflow of another, then the
tracker will be made a child of the current step in the parent. If it's null, this flow doesn't track
progress. |
StateMachineRunId |
getRunId()
Returns a wrapped UUID object that identifies this state machine run (i.e. subflows have the same identifier as their parents).
|
ServiceHub |
getServiceHub()
Provides access to big, heavy classes that may be reconstructed from time to time, e.g. across restarts. It is
only available once the flow has started, which means it cannnot be accessed in the constructor. Either
access this lazily or from inside
FlowLogic.call . |
FlowStateMachine<?> |
getStateMachine()
Internal only. Reference to the Fiber instance that is the top level controller for the entire flow. When
inside a flow this is equivalent to Strand.currentStrand. This is public only because it must be accessed
across module boundaries.
|
<T> UntrustworthyData<T> |
receive(java.lang.Class<T> receiveType,
Party otherParty)
Suspends until the specified otherParty sends us a message of type receiveType.
|
void |
send(Party otherParty,
java.lang.Object payload)
Queues the given payload for sending to the otherParty and continues without suspending.
|
<T> UntrustworthyData<T> |
sendAndReceive(java.lang.Class<T> receiveType,
Party otherParty,
java.lang.Object payload)
Serializes and queues the given payload object for sending to the otherParty. 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.
|
void |
setStateMachine(FlowStateMachine<?> value)
Internal only. Reference to the Fiber instance that is the top level controller for the entire flow. When
inside a flow this is equivalent to Strand.currentStrand. This is public only because it must be accessed
across module boundaries.
|
<R> R |
subFlow(FlowLogic<? extends R> subLogic,
boolean shareParentSessions)
Invokes the given subflow. This function returns once the subflow completes successfully with the result
returned by that subflows
FlowLogic.call method. If the subflow has a progress tracker, it is attached to the
current step in this flow's progress tracker. |
<R> R |
subFlow(FlowLogic<? extends R> subLogic)
Invokes the given subflow. This function returns once the subflow completes successfully with the result
returned by that subflows
FlowLogic.call method. If the subflow has a progress tracker, it is attached to the
current step in this flow's progress tracker. |
kotlin.Pair<java.lang.String,rx.Observable> |
track()
Returns a pair of the current progress step, as a string, and an observable of stringified changes to the
progressTracker.
|
public FlowLogic()
A sub-class of class FlowLogic
implements a flow using direct, straight line blocking code. Thus you
can write complex flow logic in an ordinary fashion, without having to think about callbacks, restarting after
a node crash, how many instances of your flow 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. Don't 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 class FlowLogic
implementation. Very large
objects or datasets will hurt performance by increasing the amount of data stored in each checkpoint.
If you'd like to use another FlowLogic class as a component of your own, construct it on the fly and then pass it to the subFlow method. It will return the result of that flow when it completes.
class FlowLogic
,
class FlowLogic
public org.slf4j.Logger getLogger()
This is where you should log things to.
public StateMachineRunId getRunId()
Returns a wrapped UUID object that identifies this state machine run (i.e. subflows have the same identifier as their parents).
public ServiceHub getServiceHub()
Provides access to big, heavy classes that may be reconstructed from time to time, e.g. across restarts. It is
only available once the flow has started, which means it cannnot be accessed in the constructor. Either
access this lazily or from inside FlowLogic.call
.
FlowLogic.call
public java.lang.Class<?> getCounterpartyMarker(Party party)
public <T> UntrustworthyData<T> sendAndReceive(java.lang.Class<T> receiveType, Party otherParty, java.lang.Object payload)
Serializes and queues the given payload object for sending to the otherParty. 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.
Note that this function is not just a simple send+receive pair: it is more efficient and more correct to use this when you expect to do a message swap than do use send and then receive in turn.
public <T> UntrustworthyData<T> receive(java.lang.Class<T> receiveType, Party otherParty)
Suspends until the specified otherParty sends us a message of type 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.
public void send(Party otherParty, java.lang.Object payload)
Queues the given payload for sending to the otherParty and continues without suspending.
Note that the other party may receive the message at some arbitrary later point or not at all: if otherParty is offline then message delivery will be retried until it comes back or until the message is older than the network's event horizon time.
public <R> R subFlow(FlowLogic<? extends R> subLogic, boolean shareParentSessions)
Invokes the given subflow. This function returns once the subflow completes successfully with the result
returned by that subflows FlowLogic.call
method. If the subflow has a progress tracker, it is attached to the
current step in this flow's progress tracker.
shareParentSessions
- In certain situations the need arises to use the same sessions the parent flow has
already established. However this also prevents the subflow from creating new sessions with those parties.
For this reason the default value is false.FlowLogic.call
public <R> R subFlow(FlowLogic<? extends R> subLogic)
Invokes the given subflow. This function returns once the subflow completes successfully with the result
returned by that subflows FlowLogic.call
method. If the subflow has a progress tracker, it is attached to the
current step in this flow's progress tracker.
FlowLogic.call
public ProgressTracker getProgressTracker()
Override this to provide a class ProgressTracker
. If one is provided and stepped, the framework will do something
helpful with the progress reports. If this flow is invoked as a subflow of another, then the
tracker will be made a child of the current step in the parent. If it's null, this flow doesn't track
progress.
Note that this has to return a tracker before the flow is invoked. You can't change your mind half way through.
class ProgressTracker
public T call()
This is where you fill out your business logic. The returned object will usually be ignored, but can be helpful if this flow is meant to be used as a subflow.
public kotlin.Pair<java.lang.String,rx.Observable> track()
Returns a pair of the current progress step, as a string, and an observable of stringified changes to the progressTracker.
public FlowStateMachine<?> getStateMachine()
Internal only. Reference to the Fiber instance that is the top level controller for the entire flow. When inside a flow this is equivalent to Strand.currentStrand. This is public only because it must be accessed across module boundaries.
public void setStateMachine(FlowStateMachine<?> value)
Internal only. Reference to the Fiber instance that is the top level controller for the entire flow. When inside a flow this is equivalent to Strand.currentStrand. This is public only because it must be accessed across module boundaries.