Class SupervisorStrategy
Base class for supervision strategies
Inheritance
Implements
Inherited Members
Namespace: Akka.Actor
Assembly: Akka.dll
Syntax
public abstract class SupervisorStrategy : ISurrogated
Fields
| Improve this Doc View SourceDefaultDecider
When supervisorStrategy is not specified for an actor this
Decider is used by default in the supervisor strategy.
The child will be stopped when ActorInitializationException,
ActorKilledException, or DeathPactException is
thrown. It will be restarted for other Exception
types.
The error is escalated if it's a Exception
, i.e. Error
.
Declaration
public static IDecider DefaultDecider
Field Value
Type | Description |
---|---|
IDecider | Directive. |
DefaultStrategy
When supervisorStrategy is not specified for an actor this is used by default. OneForOneStrategy with decider defined in DefaultDecider.
Declaration
public static readonly SupervisorStrategy DefaultStrategy
Field Value
Type | Description |
---|---|
SupervisorStrategy |
StoppingStrategy
This strategy resembles Erlang in that failing children are always terminated (one-for-one).
Declaration
public static readonly OneForOneStrategy StoppingStrategy
Field Value
Type | Description |
---|---|
OneForOneStrategy |
Properties
| Improve this Doc View SourceDecider
TBD
Declaration
public abstract IDecider Decider { get; }
Property Value
Type | Description |
---|---|
IDecider |
LoggingEnabled
Determines if failures are logged
Declaration
protected bool LoggingEnabled { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
| Improve this Doc View SourceHandle(IActorRef, Exception)
Determines which Directive this strategy uses to handle exception
that occur in the child
actor.
Declaration
protected abstract Directive Handle(IActorRef child, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
IActorRef | child | The child actor where the exception occurred. |
Exception | exception | The exception that was thrown. |
Returns
Type | Description |
---|---|
Directive | The directive used to handle the exception. |
HandleChildTerminated(IActorContext, IActorRef, IEnumerable<IInternalActorRef>)
This method is called after the child has been removed from the set of children. It does not need to do anything special. Exceptions thrown from this method do NOT make the actor fail if this happens during termination.
Declaration
public abstract void HandleChildTerminated(IActorContext actorContext, IActorRef child, IEnumerable<IInternalActorRef> children)
Parameters
Type | Name | Description |
---|---|---|
IActorContext | actorContext | TBD |
IActorRef | child | TBD |
IEnumerable<Akka.Actor.IInternalActorRef> | children | TBD |
HandleFailure(ActorCell, IActorRef, Exception, ChildRestartStats, IReadOnlyCollection<ChildRestartStats>)
This is the main entry point: in case of a child’s failure, this method
must try to handle the failure by resuming, restarting or stopping the
child (and returning true
), or it returns false
to escalate the
failure, which will lead to this actor re-throwing the exception which
caused the failure. The exception will not be wrapped.
This method calls SupervisorStrategy, which will
log the failure unless it is escalated. You can customize the logging by
setting SupervisorStrategy to false
and
do the logging inside the decider
or override the LogFailure
method.
Declaration
public bool HandleFailure(ActorCell actorCell, IActorRef child, Exception cause, ChildRestartStats stats, IReadOnlyCollection<ChildRestartStats> children)
Parameters
Type | Name | Description |
---|---|---|
ActorCell | actorCell | The actor cell. |
IActorRef | child | The child actor. |
Exception | cause | The cause. |
ChildRestartStats | stats | The stats for the failed child. |
IReadOnlyCollection<ChildRestartStats> | children | TBD |
Returns
Type | Description |
---|---|
Boolean |
|
LogFailure(IActorContext, IActorRef, Exception, Directive)
Logs the failure.
Declaration
protected virtual void LogFailure(IActorContext context, IActorRef child, Exception cause, Directive directive)
Parameters
Type | Name | Description |
---|---|---|
IActorContext | context | The actor cell. |
IActorRef | child | The child. |
Exception | cause | The cause. |
Directive | directive | The directive. |
ProcessFailure(IActorContext, Boolean, IActorRef, Exception, ChildRestartStats, IReadOnlyCollection<ChildRestartStats>)
This method is called to act on the failure of a child: restart if the flag is true, stop otherwise.
Declaration
public abstract void ProcessFailure(IActorContext context, bool restart, IActorRef child, Exception cause, ChildRestartStats stats, IReadOnlyCollection<ChildRestartStats> children)
Parameters
Type | Name | Description |
---|---|---|
IActorContext | context | The actor context. |
Boolean | restart | if set to |
IActorRef | child | The child actor |
Exception | cause | The exception that caused the child to fail. |
ChildRestartStats | stats | The stats for the child that failed. The ActorRef to the child can be obtained via the Child property |
IReadOnlyCollection<ChildRestartStats> | children | The stats for all children |
RestartChild(IActorRef, Exception, Boolean)
Restarts the child.
Declaration
protected void RestartChild(IActorRef child, Exception cause, bool suspendFirst)
Parameters
Type | Name | Description |
---|---|---|
IActorRef | child | The child. |
Exception | cause | The cause. |
Boolean | suspendFirst | if set to |
ResumeChild(IActorRef, Exception)
Resumes the previously failed child. Suspend/resume needs to be done in matching pairs, otherwise actors will wake up too soon or never at all.
note
Never apply this to a child which is not the currently failing child.
Declaration
protected void ResumeChild(IActorRef child, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
IActorRef | child | The child actor that is being resumed. |
Exception | exception | The exception that caused the child actor to fail. |
ToSurrogate(ActorSystem)
Creates a surrogate representation of the current SupervisorStrategy.
Declaration
public abstract ISurrogate ToSurrogate(ActorSystem system)
Parameters
Type | Name | Description |
---|---|---|
ActorSystem | system | The actor system that owns this router. |
Returns
Type | Description |
---|---|
ISurrogate | The surrogate representation of the current SupervisorStrategy. |