protected override SupervisorStrategy SupervisorStrategy()
{
return new OneForOneStrategy(ex =>
{
var directive = Directive.Stop;
ex.Match()
.With<InvalidAssociation>(ia =>
{
KeepQuarantinedOr(ia.RemoteAddress, () =>
{
var causedBy = ia.InnerException == null
? ""
: string.Format("Caused by: [{0}]", ia.InnerException);
_log.Warning("Tried to associate with unreachable remote address [{0}]. Address is now gated for {1} ms, all messages to this address will be delivered to dead letters. Reason: [{2}] {3}",
ia.RemoteAddress, _settings.RetryGateClosedFor.TotalMilliseconds, ia.Message, causedBy);
_endpoints.MarkAsFailed(Sender, Deadline.Now + _settings.RetryGateClosedFor);
});
if (ia.DisassociationInfo.HasValue && ia.DisassociationInfo == DisassociateInfo.Quarantined)
Context.System.EventStream.Publish(new ThisActorSystemQuarantinedEvent(ia.LocalAddress, ia.RemoteAddress));
directive = Directive.Stop;
})
.With<ShutDownAssociation>(shutdown =>
{
KeepQuarantinedOr(shutdown.RemoteAddress, () =>
{
_log.Debug("Remote system with address [{0}] has shut down. Address is now gated for {1}ms, all messages to this address will be delivered to dead letters.",
shutdown.RemoteAddress, _settings.RetryGateClosedFor.TotalMilliseconds);
_endpoints.MarkAsFailed(Sender, Deadline.Now + _settings.RetryGateClosedFor);
});
directive = Directive.Stop;
})
.With<HopelessAssociation>(hopeless =>
{
if (hopeless.Uid.HasValue)
{
_log.Error("Association to [{0}] with UID [{1}] is irrecoverably failed. Quarantining address.",
hopeless.RemoteAddress, hopeless.Uid);
if (_settings.QuarantineDuration.HasValue)
{
_endpoints.MarkAsQuarantined(hopeless.RemoteAddress, hopeless.Uid.Value,
Deadline.Now + _settings.QuarantineDuration.Value);
_eventPublisher.NotifyListeners(new QuarantinedEvent(hopeless.RemoteAddress,
hopeless.Uid.Value));
}
}
else
{
_log.Warning("Association to [{0}] with unknown UID is irrecoverably failed. Address cannot be quarantined without knowing the UID, gating instead for {1} ms.",
hopeless.RemoteAddress, _settings.RetryGateClosedFor.TotalMilliseconds);
_endpoints.MarkAsFailed(Sender, Deadline.Now + _settings.RetryGateClosedFor);
}
directive = Directive.Stop;
})
.Default(msg =>
{
if (msg is EndpointDisassociatedException || msg is EndpointAssociationException) { } //no logging
else { _log.Error(ex, ex.Message); }
_endpoints.MarkAsFailed(Sender, Deadline.Now + _settings.RetryGateClosedFor);
directive = Directive.Stop;
});
return directive;
});
}