C# Class Akka.Streams.Implementation.Fusing.GraphInterpreter

INTERNAL API From an external viewpoint, the GraphInterpreter takes an assembly of graph processing stages encoded as a Assembly object and provides facilities to execute and interact with this assembly. The lifecycle of the Interpreter is roughly the following: - Boundary logics are attached via AttachDownstreamBoundary and AttachUpstreamBoundary - Init is called - Execute is called whenever there is need for execution, providing an upper limit on the processed events - Finish is called before the interpreter is disposed, preferably after IsCompleted returned true, although in abort cases this is not strictly necessary The Execute method of the interpreter accepts an upper bound on the events it will process. After this limit is reached or there are no more pending events to be processed, the call returns. It is possible to inspect if there are unprocessed events left via the IsSuspended method. IsCompleted returns true once all stages reported completion inside the interpreter. The internal architecture of the interpreter is based on the usage of arrays and optimized for reducing allocations on the hot paths. One of the basic abstractions inside the interpreter is the notion of connection. In the abstract sense a connection represents an output-input port pair (an analogue for a connected RS Publisher-Subscriber pair), while in the practical sense a connection is a number which represents slots in certain arrays. In particular - portStates contains a bitfield that tracks the states of the ports (output-input) corresponding to this connection. This bitfield is used to decode the event that is in-flight. - connectionSlots is a mapping from a connection id to a potential element or exception that accompanies the event encoded in the portStates bitfield - inHandlers is a mapping from a connection id to the InHandlers instance that handles the events corresponding to the input port of the connection - outHandlers is a mapping from a connection id to the OutHandlers instance that handles the events corresponding to the output port of the connection On top of these lookup tables there is an eventQueue, represented as a circular buffer of integers. The integers it contains represents connections that have pending events to be processed. The pending event itself is encoded in the portStates bitfield. This implies that there can be only one event in flight for a given connection, which is true in almost all cases, except a complete-after-push or fail-after-push. The layout of the portStates bitfield is the following: |- state machn.-| Only one bit is hot among these bits 64 32 16 | 8 4 2 1 | +---+---+---|---+---+---+---| | | | | | | | | | | | | | | From the following flags only one is active in any given time. These bits encode | | | | | | | state machine states, and they are "moved" around using XOR masks to keep other bits | | | | | | | intact. | | | | | | | | | | | | | +- InReady: The input port is ready to be pulled | | | | | +----- Pulling: A pull is active, but have not arrived yet (queued) | | | | +--------- Pushing: A push is active, but have not arrived yet (queued) | | | +------------- OutReady: The output port is ready to be pushed | | | | | +----------------- InClosed: The input port is closed and will not receive any events. | | A push might be still in flight which will be then processed first. | +--------------------- OutClosed: The output port is closed and will not receive any events. +------------------------- InFailed: Always set in conjunction with InClosed. Indicates that the close event is a failure Sending an event is usually the following sequence: - An action is requested by a stage logic (push, pull, complete, etc.) - the state machine in portStates is transitioned from a ready state to a pending event - the id of the affected connection is enqueued Receiving an event is usually the following sequence: - id of connection to be processed is dequeued - the type of the event is determined from the bits set on portStates - the state machine in portStates is transitioned to a ready state - using the inHandlers/outHandlers table the corresponding callback is called on the stage logic. Because of the FIFO construction of the queue the interpreter is fair, i.e. a pending event is always executed after a bounded number of other events. This property, together with suspendability means that even infinite cycles can be modeled, or even dissolved (if preempted and a "stealing" external event is injected; for example the non-cycle edge of a balance is pulled, dissolving the original cycle).
Datei anzeigen Open project: rogeralsing/akka.net

Public Properties

Property Type Description
Assembly GraphAssembly
ConnectionSlots object[]
FuzzingMode bool
InHandlers IInHandler[]
IsDebug bool
Log ILoggingAdapter
Logics GraphStageLogic[]
Materializer IMaterializer
OnAsyncInput Action>
OutHandlers IOutHandler[]
PortStates int[]
RunningStagesCount int
SingleNoAttribute Attributes[]

Private Properties

Property Type Description
AfterStageHasRun void
Cancel void
Complete void
CompleteConnection void
Dequeue int
Enqueue void
Fail void
FinalizeStage void
InLogicName string
InOwnerName string
IsStageCompleted bool
OutLogicName string
OutOwnerName string
ProcessEvent void
Pull void
Push void
QueueStatus string
SafeLogics GraphStageLogic
SetKeepGoing void
ShutdownCounters string

Public Methods

Method Description
AttachDownstreamBoundary ( int connection, DownstreamBoundaryStageLogic logic ) : void

Assign the boundary logic to a given connection. This will serve as the interface to the external world (outside the interpreter) to process and inject events.

AttachUpstreamBoundary ( int connection, UpstreamBoundaryStageLogic logic ) : void

Assign the boundary logic to a given connection. This will serve as the interface to the external world (outside the interpreter) to process and inject events.

DumpWaits ( ) : void

Debug utility to dump the "waits-on" relationships in DOT format to the console for analysis of deadlocks. Only invoke this after the interpreter completely settled, otherwise the results might be off. This is a very simplistic tool, make sure you are understanding what you are doing and then it will serve you well.

Execute ( int eventLimit ) : void

Executes pending events until the given limit is met. If there were remaining events, IsSuspended will return true.

Finish ( ) : void

Finalizes the state of all stages by calling GraphStageLogic.PostStop (if necessary).

GraphInterpreter ( GraphAssembly assembly, IMaterializer materializer, ILoggingAdapter log, IInHandler inHandlers, IOutHandler outHandlers, GraphStageLogic logics, Action onAsyncInput, bool fuzzingMode ) : System
Init ( IMaterializer subMaterializer ) : void

Initializes the states of all the stage logics by calling GraphStageLogic.PreStart. The passed-in materializer is intended to be a SubFusingMaterializer that avoids creating new Actors when stages materialize sub-flows.If no such materializer is available, passing in null will reuse the normal materializer for the GraphInterpreter—fusing is only an optimization.

ProcessElement ( int connection ) : void
RunAsyncInput ( GraphStageLogic logic, object evt, Action handler ) : void
SetHandler ( int connection, IInHandler handler ) : void

Dynamic handler changes are communicated from a GraphStageLogic by this method.

SetHandler ( int connection, IOutHandler handler ) : void

Dynamic handler changes are communicated from a GraphStageLogic by this method.

Private Methods

Method Description
AfterStageHasRun ( GraphStageLogic logic ) : void
Cancel ( int connection ) : void
Complete ( int connection ) : void
CompleteConnection ( int stageId ) : void

Register that a connection in which the given stage participated has been completed and therefore the stage itself might stop, too.

Dequeue ( ) : int
Enqueue ( int connection ) : void
Fail ( int connection, Exception reason ) : void
FinalizeStage ( GraphStageLogic logic ) : void
InLogicName ( int connection ) : string
InOwnerName ( int connection ) : string
IsStageCompleted ( GraphStageLogic stage ) : bool

Returns true if the given stage is alredy completed

OutLogicName ( int connection ) : string
OutOwnerName ( int connection ) : string
ProcessEvent ( int connection ) : void

Decodes and processes a single event for the given connection

Pull ( int connection ) : void
Push ( int connection, object element ) : void
QueueStatus ( ) : string
SafeLogics ( int id ) : GraphStageLogic
SetKeepGoing ( GraphStageLogic logic, bool enabled ) : void
ShutdownCounters ( ) : string

Method Details

AttachDownstreamBoundary() public method

Assign the boundary logic to a given connection. This will serve as the interface to the external world (outside the interpreter) to process and inject events.
public AttachDownstreamBoundary ( int connection, DownstreamBoundaryStageLogic logic ) : void
connection int
logic DownstreamBoundaryStageLogic
return void

AttachUpstreamBoundary() public method

Assign the boundary logic to a given connection. This will serve as the interface to the external world (outside the interpreter) to process and inject events.
public AttachUpstreamBoundary ( int connection, UpstreamBoundaryStageLogic logic ) : void
connection int
logic UpstreamBoundaryStageLogic
return void

DumpWaits() public method

Debug utility to dump the "waits-on" relationships in DOT format to the console for analysis of deadlocks. Only invoke this after the interpreter completely settled, otherwise the results might be off. This is a very simplistic tool, make sure you are understanding what you are doing and then it will serve you well.
public DumpWaits ( ) : void
return void

Execute() public method

Executes pending events until the given limit is met. If there were remaining events, IsSuspended will return true.
public Execute ( int eventLimit ) : void
eventLimit int
return void

Finish() public method

Finalizes the state of all stages by calling GraphStageLogic.PostStop (if necessary).
public Finish ( ) : void
return void

GraphInterpreter() public method

public GraphInterpreter ( GraphAssembly assembly, IMaterializer materializer, ILoggingAdapter log, IInHandler inHandlers, IOutHandler outHandlers, GraphStageLogic logics, Action onAsyncInput, bool fuzzingMode ) : System
assembly GraphAssembly
materializer IMaterializer
log ILoggingAdapter
inHandlers IInHandler
outHandlers IOutHandler
logics GraphStageLogic
onAsyncInput Action
fuzzingMode bool
return System

Init() public method

Initializes the states of all the stage logics by calling GraphStageLogic.PreStart. The passed-in materializer is intended to be a SubFusingMaterializer that avoids creating new Actors when stages materialize sub-flows.If no such materializer is available, passing in null will reuse the normal materializer for the GraphInterpreter—fusing is only an optimization.
public Init ( IMaterializer subMaterializer ) : void
subMaterializer IMaterializer
return void

ProcessElement() public method

public ProcessElement ( int connection ) : void
connection int
return void

RunAsyncInput() public method

public RunAsyncInput ( GraphStageLogic logic, object evt, Action handler ) : void
logic GraphStageLogic
evt object
handler Action
return void

SetHandler() public method

Dynamic handler changes are communicated from a GraphStageLogic by this method.
public SetHandler ( int connection, IInHandler handler ) : void
connection int
handler IInHandler
return void

SetHandler() public method

Dynamic handler changes are communicated from a GraphStageLogic by this method.
public SetHandler ( int connection, IOutHandler handler ) : void
connection int
handler IOutHandler
return void

Property Details

Assembly public_oe property

public GraphAssembly Assembly
return GraphAssembly

ConnectionSlots public_oe property

public object[] ConnectionSlots
return object[]

FuzzingMode public_oe property

public bool FuzzingMode
return bool

InHandlers public_oe property

public IInHandler[] InHandlers
return IInHandler[]

IsDebug public_oe static_oe property

public static bool IsDebug
return bool

Log public_oe property

public ILoggingAdapter Log
return ILoggingAdapter

Logics public_oe property

public GraphStageLogic[] Logics
return GraphStageLogic[]

Materializer public_oe property

public IMaterializer Materializer
return IMaterializer

OnAsyncInput public_oe property

public Action> OnAsyncInput
return Action>

OutHandlers public_oe property

public IOutHandler[] OutHandlers
return IOutHandler[]

PortStates public_oe property

public int[] PortStates
return int[]

RunningStagesCount public_oe property

public int RunningStagesCount
return int

SingleNoAttribute public_oe static_oe property

public static Attributes[] SingleNoAttribute
return Attributes[]