Echo.Process

Echo.Process Strategy

Contents

enum DirectiveType Source #

Directive type 'Discriminated union' identifier for the Directive sub-types.

class Directive Source #

Instruction to the Process system of what action to take when a Process crashes. The directive is assigned to a supervisor who apply these actions to the failed Process and optionally other Processes defined by the Strategy.

Fields

field DirectiveType Type Source #

field Directive Resume = new Resume() Source #

Resume with state in tact after a crash

field Directive Stop = new Stop() Source #

Shutdown after a crash

field Directive Escalate = new Escalate() Source #

Escalate the exception to the parent of the crashing process' supervisor after a crash

Properties

property Directive Restart Source #

Re-call the setup function to reset the state after a crash.

Methods

method bool Equals (Directive other) Source #

Equality test

method bool Equals (object obj) Source #

Equality test

method int GetHashCode () Source #

Returns a unique hash-code for this Directive

Parameters

returns

Operators

operator == (Directive lhs, Directive rhs) Source #

Equality operator

operator != (Directive lhs, Directive rhs) Source #

Non-equality operator

class Resume Source #

Directive: Resume with state in tact after a crash

Constructors

constructor Resume () Source #

class Stop Source #

Directive: Shutdown after a crash

Constructors

constructor Stop () Source #

class Restart Source #

Directive: Re-call the setup function to reset the state after a crash.

Constructors

constructor Restart () Source #

class Escalate Source #

Directive: Escalate the exception to the parent of the crashing process' supervisor after a crash

Constructors

constructor Escalate () Source #

class MessageDirective Source #

Message directives This class represents a set of core behaviours for the message that caused a Process to fail.

Fields

field MessageDirectiveType Type Source #

field MessageDirective ForwardToParent = new ForwardToParent() Source #

Forward the failed message to the supervisor (the parent) of the Process that failed. It will join the back of the queue.

Properties

property MessageDirective ForwardToDeadLetters Source #

Forward the failed message onto the Dead Letters process This is the default behaviour

property MessageDirective ForwardToSelf Source #

Forward the failed message back to the Process that failed. It will join the back of the queue.

property MessageDirective StayInQueue Source #

Message remains at the front of the queue for when the process has recovered. Could cause blocking for permanent failures.

Methods

method MessageDirective ForwardTo (ProcessId pid) Source #

Forward the failed message to the Process specified. It will join the back of the queue.

method bool Equals (MessageDirective other) Source #

method bool Equals (object obj) Source #

method int GetHashCode () Source #

Operators

operator == (MessageDirective lhs, MessageDirective rhs) Source #

operator != (MessageDirective lhs, MessageDirective rhs) Source #

class Strategy Source #

Fields

field State<StrategyContext, StrategyContext> Context = get<StrategyContext>() Source #

Get the context state State monad

field State<StrategyContext, Unit> IncFailureCount = MapGlobal(g => g.With(Failures: g.Failures + 1)) Source #

Increase the failure count state

field State<StrategyContext, Unit> ResetFailureCount = MapGlobal(g => g.With(Failures: 0, FirstFailure: DateTime.MaxValue, LastFailure: DateTime.MaxValue)) Source #

Reset the failure count state to zero and set FirstFailure and LastFailure to max-value

field State<StrategyContext, Unit> FailedOnce = MapGlobal(g => g.With(Failures: 1, FirstFailure: DateTime.UtcNow, LastFailure: DateTime.UtcNow)) Source #

Set the failure count to 1 and set FirstFailure and LastFailure to UtcNow

Properties

property State<StrategyContext, Unit> Reset Source #

Resets the global (to the Process) state. This wipes out things like the current retries counter, the time since the last failure, etc.

property State<StrategyContext, Unit> Identity Source #

Identity function for the strategy state monad. Use when you want a no-op

Methods

method State<StrategyContext, A> Return <A> (A value) Source #

method State<StrategyContext, A> Return <A> (Func<StrategyContext, (StrategyContext, A)> f) Source #

method State<StrategyContext, Unit> Return (Func<StrategyContext, StrategyContext> f) Source #

method State<StrategyContext, A> Return <A> (Func<StrategyContext, (TryOption<A>, StrategyContext State)> f) Source #

method State<StrategyContext, Unit> Compose (params State<StrategyContext, Unit>[] stages) Source #

Compose a sequence of state computations

method State<StrategyContext, Unit> OneForOne (params State<StrategyContext, Unit>[] stages) Source #

One-for-one strategy This strategy affects only the process that failed

Parameters

param stages

Set of computations to compose that results in a behaviour for the strategy

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> AllForOne (params State<StrategyContext, Unit>[] stages) Source #

All-for-one strategy This strategy affects the process that failed and its siblings

Parameters

param stages

Set of computations to compose that results in a behaviour for the strategy

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> SetDirective (Option<Directive> directive) Source #

Sets the decision directive. Once set, cant be un-set. If the directive is Stop then the Global state is reset for this strategy (global to the Process)

Parameters

param directive

Directive to set

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> SetFirstFailure (DateTime when) Source #

Sets the first-failure state.

Parameters

param when

Time to set

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> SetLastFailure (DateTime when) Source #

Sets the last-failure state.

Parameters

param when

Time to set

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> SetBackOffAmount (Time step) Source #

Sets the current back off amount

Parameters

param step

Step size for the next Process pause before resuming

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> Pause (Time duration) Source #

Pauses the Process for a fixed amount of time

Parameters

param duration

Duration of the pause before resuming

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> MapGlobal (Func<StrategyState, StrategyState> map) Source #

Maps the global (to the Process) state.

method State<StrategyContext, Unit> Retries (int Count) Source #

Gives the strategy a behaviour that will only fail N times before forcing the Process to stop

Parameters

param Count

Number of times to retry

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> Retries (int Count, Time Duration) Source #

Gives the strategy a behaviour that will only fail N times before forcing the Process to stop. However if a time-peroid of Duration elapses, then the number of failures 'so far' is reset to zero.

This behaviour allows something that's rapidly failing to shutdown, but will allow the occasional failure.

Parameters

param Count

Number of times to retry

param Duration

Time between failures

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> Backoff (Time Min, Time Max, Time Step) Source #

Applies a strategy that causes the Process to 'back off'. That is it will be paused for an amount of time before it can continue doing other operations.

Parameters

param Min

Minimum back-off time

param Max

Maximum back-off time; once this point is reached the Process will stop for good

param Step

The amount to add to the current back-off time for each failure. That allows for the steps to grow gradually larger as the Process keeps failing

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> Backoff (Time Min, Time Max, double Scalar) Source #

Applies a strategy that causes the Process to 'back off'. That is it will be paused for an amount of time before it can continue doing other operations.

Parameters

param Min

Minimum back-off time

param Max

Maximum back-off time; once this point is reached the Process will stop for good

param Scalar

The amount to multiply the previous back-off time amount for each failure. That allows for the steps to grow gradually larger as the Process keeps failing

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> Backoff (Time Duration) Source #

Applies a strategy that causes the Process to 'back off' for a fixed amount of time. That is it will be paused for an amount of time before it can continue doing other operations. This strategy never causes a Process to be stopped.

Parameters

param Duration

Back-off time period

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> Always (Directive directive) Source #

Always return this Directive in the final StrategyDecision

Parameters

param directive

Directive to return

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> Match (params State<Exception, Option<Directive>>[] directives) Source #

Match a range of State computations that take the Exception that caused the failure and map it to an Optional Directive. The first computation to return a Some(Directive) will succeed

Parameters

param directives

Directive maps

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> Redirect (params State<Directive, Option<MessageDirective>>[] directives) Source #

Match a range of State computations that take the currently selected Directive and map it to an Optional MessageDirective. The first computation to return a Some(MessageDirective) will succeed. If a Directive hasn't been chosen by the time this is invoked then RestartNow is used by default.

Parameters

param directives

Directive maps

returns

Strategy computation as a State monad

method State<StrategyContext, Unit> Redirect (MessageDirective defaultDirective) Source #

Provides a message redirection strategy that always uses the same MessageDirective regardless of the Directive provided.

Parameters

param defaultDirective

Default message directive

returns

Strategy computation as a State monad

method State<Exception, Option<Directive>> With <TException> (Func<TException, Directive> map) Source #

where TException : Exception

Used within the Strategy.Match function to match an Exception to a Directive. Use the function's generic type to specify the type of Exception to match.

Parameters

type TException

Type of Exception to match

param map

Map from the TException to a Directive

returns

Strategy computation as a State monad

method State<Exception, Option<Directive>> With <TException> (Directive directive) Source #

where TException : Exception

Used within the Strategy.Match function to match an Exception to a Directive. Use the function's generic type to specify the type of Exception to match.

Parameters

type TException

Type of Exception to match

param directive

Directive to use if the Exception matches TException

returns

Strategy computation as a State monad

method State<Exception, Option<Directive>> Otherwise (Func<Exception, Directive> map) Source #

Used within the Strategy.Match function to provide a default Directive if the Exception that caused the failure doesn't match any of the previous With clauses.

Parameters

param map

Map from the Exception to a Directive

returns

Strategy computation as a State monad

method State<Exception, Option<Directive>> Otherwise (Directive directive) Source #

Used within the Strategy.Match function to provide a default Directive if the Exception that caused the failure doesn't match any of the previous With clauses.

Parameters

param directive

Directive to use

returns

Strategy computation as a State monad

method State<Directive, Option<MessageDirective>> When <TDirective> (Func<TDirective, MessageDirective> map) Source #

where TDirective : Directive

method State<Directive, Option<MessageDirective>> When <TDirective> (MessageDirective directive) Source #

where TDirective : Directive

method State<Directive, Option<MessageDirective>> Otherwise (Func<Directive, MessageDirective> map) Source #

method State<Directive, Option<MessageDirective>> Otherwise (MessageDirective directive) Source #

class StrategyContext Source #

Keeps a running context whilst a strategy computation is running

Fields

field StrategyState Global Source #

field Exception Exception Source #

field object Message Source #

field ProcessId Sender Source #

field ProcessId Self Source #

field ProcessId ParentProcess Source #

field IEnumerable<ProcessId> Siblings = new ProcessId[0] Source #

field IEnumerable<ProcessId> Affects = new ProcessId[0] Source #

field Option<Directive> Directive Source #

field Option<MessageDirective> MessageDirective Source #

field Time Pause Source #

Methods

method StrategyContext With ( StrategyState Global = null, Exception Exception = null, object Message = null, ProcessId? Sender = null, ProcessId? FailedProcess = null, ProcessId? ParentProcess = null, IEnumerable<ProcessId> Siblings = null, IEnumerable<ProcessId> Affects = null, Time? Pause = null, Option<Directive> Directive = default(Option<Directive>), Option<MessageDirective> MessageDirective = default(Option<MessageDirective>) ) Source #

class StrategyDecision Source #

Fields

field Directive ProcessDirective Source #

field MessageDirective MessageDirective Source #

field IEnumerable<ProcessId> Affects Source #

field Time Pause Source #

Constructors

constructor StrategyDecision ( Directive processDirective, MessageDirective messageDirective, IEnumerable<ProcessId> affects, Time pause ) Source #

Methods

method StrategyDecision New ( Directive processDirective, MessageDirective messageDirective, IEnumerable<ProcessId> affects, Time pause ) Source #

class StrategyEvent Source #

Methods

method State<StrategyState, StrategyDecision> Failure ( this State<StrategyContext, Unit> strategy, ProcessId pid, ProcessId sender, ProcessId parent, IEnumerable<ProcessId> siblings, Exception ex, object msg ) Source #

Creates a new State computation that is primed with the data of a particular failure event.

Parameters

param strategy

Strategy as a State computation

param pid

Process ID that failed

param sender

Process that sent the message that cause the failure

param parent

Supervisor of the failed Process

param siblings

The siblings of the failed Process

param ex

Exception

param msg

Message that caused the failure

returns

State computation that can be invoked by passing it an object of StrategyState. This will result in a StateResult that contains the mutated StrategyState and a StrategyDecision. The StrategyDecision contains all the information needed to decide the fate of a Process (and related processes)

class StrategyState Source #

Holds the 'global' state for a strategy. i.e the state that will survive between invocations of the stratgey computation.

Constructors

constructor StrategyState ( Time backoffAmount, int failures, DateTime firstFailure, DateTime lastFailure, HashMap<string, object> metadata ) Source #

Methods

method StrategyState SetMetaData <T> (string key, T value) Source #

Adds or updates an item of meta-data

This is for extending the default strategies behaviours and allows for state to survive in-between Process errors

method StrategyState TrySetMetaData <T> (string key, T value) Source #

Attempts to set a meta-data item. If it is already set, nothing happens.

This is for extending the default strategies behaviours and allows for state to survive in-between Process errors

method StrategyState RemoveMetaData <T> (string key) Source #

Attempts to remove a meta-data item. If it is not set, nothing happens.

This is for extending the default strategies behaviours and allows for state to survive in-between Process errors

method bool MetaDataContains <T> (string key) Source #

Returns True if the meta-data contains the key specified

method StrategyState With ( Time? BackoffAmount = null, int? Failures = null, DateTime? FirstFailure = null, DateTime? LastFailure = null, HashMap<string, object>? Metadata = null ) Source #