private void HandleInboundAssociation(InboundAssociation ia)
{
var readonlyEndpoint = endpoints.ReadOnlyEndpointFor(ia.Association.RemoteAddress);
var handle = ia.Association.AsInstanceOf <AkkaProtocolHandle>();
if (readonlyEndpoint != null)
{
if (pendingReadHandoffs.ContainsKey(readonlyEndpoint))
{
pendingReadHandoffs[readonlyEndpoint].Disassociate();
}
pendingReadHandoffs.AddOrSet(readonlyEndpoint, handle);
readonlyEndpoint.Tell(new EndpointWriter.TakeOver(handle));
}
else
{
if (endpoints.IsQuarantined(handle.RemoteAddress, (int)handle.HandshakeInfo.Uid))
{
handle.Disassociate(DisassociateInfo.Quarantined);
}
else
{
endpoints.WritableEndpointWithPolicyFor(handle.RemoteAddress).Match()
.With <Pass>(pass =>
{
if (!pass.Uid.HasValue)
{
if (stashedInbound.ContainsKey(pass.Endpoint))
{
stashedInbound[pass.Endpoint].Add(ia);
}
else
{
stashedInbound.AddOrSet(pass.Endpoint, new List <InboundAssociation>()
{
ia
});
}
}
else
{
if (handle.HandshakeInfo.Uid == pass.Uid)
{
if (pendingReadHandoffs.ContainsKey(pass.Endpoint))
{
pendingReadHandoffs[pass.Endpoint].Disassociate();
}
pendingReadHandoffs.AddOrSet(pass.Endpoint, handle);
pass.Endpoint.Tell(new EndpointWriter.StoppedReading(pass.Endpoint));
}
else
{
Context.Stop((InternalActorRef)pass.Endpoint);
endpoints.UnregisterEndpoint(pass.Endpoint);
pendingReadHandoffs.Remove(pass.Endpoint);
CreateAndRegisterEndpoint(handle, pass.Uid);
}
}
})
.Default(state =>
{
CreateAndRegisterEndpoint(handle, null);
});
}
}
}