protected void Receiving()
{
Receive<EndpointWriter.FlushAndStop>(flush =>
{
//Trying to serve until our last breath
ResendAll();
_writer.Tell(EndpointWriter.FlushAndStop.Instance);
Become(FlushWait);
});
Receive<IsIdle>(idle => { }); // Do not reply, we will Terminate soon, or send a GotUid
Receive<EndpointManager.Send>(send => HandleSend(send));
Receive<Ack>(ack =>
{
// If we are not sure about the UID just ignore the ack. Ignoring is fine.
if (UidConfirmed)
{
try
{
_resendBuffer = _resendBuffer.Acknowledge(ack);
}
catch (Exception ex)
{
throw new HopelessAssociation(_localAddress, _remoteAddress, Uid,
new IllegalStateException($"Error encountered while processing system message acknowledgement buffer: {_resendBuffer} ack: {ack}", ex));
}
ResendNacked();
}
});
Receive<AttemptSysMsgRedelivery>(sysmsg =>
{
if (UidConfirmed) ResendAll();
});
Receive<Terminated>(terminated =>
{
_currentHandle = null;
Context.Parent.Tell(new EndpointWriter.StoppedReading(Self));
if (_resendBuffer.NonAcked.Any() || _resendBuffer.Nacked.Any())
Context.System.Scheduler.ScheduleTellOnce(_settings.SysResendTimeout, Self,
new AttemptSysMsgRedelivery(), Self);
GoToIdle();
});
Receive<GotUid>(g =>
{
_bailoutAt = null;
Context.Parent.Tell(g);
//New system that has the same address as the old - need to start from fresh state
UidConfirmed = true;
if (Uid.HasValue && Uid.Value != g.Uid) Reset();
Uid = g.Uid;
ResendAll();
});
Receive<EndpointWriter.StopReading>(stopped =>
{
_writer.Forward(stopped); //forward the request
});
}