INTERNAL API
Inheritance: EndpointException
Beispiel #1
0
        private bool WriteSend(EndpointManager.Send send)
        {
            try
            {
                if (_handle == null)
                    throw new EndpointException(
                        "Internal error: Endpoint is in state Writing, but no association handle is present.");
                if (_provider.RemoteSettings.LogSend)
                {
                    _log.Debug("RemoteMessage: {0} to [{1}]<+[{2}] from [{3}]", send.Message,
                        send.Recipient, send.Recipient.Path, send.SenderOption ?? _system.DeadLetters);
                }

                var pdu = _codec.ConstructMessage(send.Recipient.LocalAddressToUse, send.Recipient,
                    SerializeMessage(send.Message), send.SenderOption, send.Seq, _lastAck);

                _remoteMetrics.LogPayloadBytes(send.Message, pdu.Length);

                if (pdu.Length > Transport.MaximumPayloadBytes)
                {
                    var reason = new OversizedPayloadException(
                        string.Format("Discarding oversized payload sent to {0}: max allowed size {1} bytes, actual size of encoded {2} was {3} bytes.",
                            send.Recipient,
                            Transport.MaximumPayloadBytes,
                            send.Message.GetType(),
                            pdu.Length));
                    _log.Error(reason, "Transient association error (association remains live)");
                    return true;
                }
                else
                {
                    var ok = _handle.Write(pdu);

                    if (ok)
                    {
                        _ackDeadline = NewAckDeadline();
                        _lastAck = null;
                        return true;
                    }
                }
                return false;
            }
            catch (SerializationException ex)
            {
                _log.Error(ex, "Transient association error (association remains live)");
                return true;
            }
            catch (EndpointException ex)
            {
                PublishAndThrow(ex, LogLevel.ErrorLevel);
            }
            catch (Exception ex)
            {
                PublishAndThrow(new EndpointException("Failed to write message to the transport", ex),
                    LogLevel.ErrorLevel);
            }

            return false;
        }
Beispiel #2
0
 private void Reading()
 {
     Receive<Disassociated>(disassociated => HandleDisassociated(disassociated.Info));
     Receive<InboundPayload>(inbound =>
     {
         var payload = inbound.Payload;
         if (payload.Length > Transport.MaximumPayloadBytes)
         {
             var reason = new OversizedPayloadException(
                 string.Format("Discarding oversized payload received: max allowed size {0} bytes, actual size {1} bytes.",
                     Transport.MaximumPayloadBytes,
                     payload.Length));
             _log.Error(reason, "Transient error while reading from association (association remains live)");
         }
         else
         {
             var ackAndMessage = TryDecodeMessageAndAck(payload);
             if (ackAndMessage.AckOption != null && _reliableDeliverySupervisor != null)
                 _reliableDeliverySupervisor.Tell(ackAndMessage.AckOption);
             if (ackAndMessage.MessageOption != null)
             {
                 if (ackAndMessage.MessageOption.ReliableDeliveryEnabled)
                 {
                     _ackedReceiveBuffer = _ackedReceiveBuffer.Receive(ackAndMessage.MessageOption);
                     DeliverAndAck();
                 }
                 else
                 {
                     _msgDispatch.Dispatch(ackAndMessage.MessageOption.Recipient,
                         ackAndMessage.MessageOption.RecipientAddress,
                         ackAndMessage.MessageOption.SerializedMessage,
                         ackAndMessage.MessageOption.SenderOptional);
                 }
             }
         }
     });
     Receive<EndpointWriter.StopReading>(stop =>
     {
         SaveState();
         Become(NotReading);
         stop.ReplyTo.Tell(new EndpointWriter.StoppedReading(stop.Writer));
     });
 }
Beispiel #3
0
 protected override void OnReceive(object message)
 {
     if (message is Disassociated)
     {
         HandleDisassociated((message as Disassociated).Info);
     }
     else if (message is InboundPayload)
     {
         var payload = ((InboundPayload)message).Payload;
         if (payload.Length > Transport.MaximumPayloadBytes)
         {
             var reason = new OversizedPayloadException(
                 string.Format("Discarding oversized payload received: max allowed size {0} bytes, actual size {1} bytes.",
                     Transport.MaximumPayloadBytes,
                     payload.Length));
             _log.Error(reason, "Transient error while reading from association (association remains live)");
         }
         else
         {
             var ackAndMessage = TryDecodeMessageAndAck(payload);
             if (ackAndMessage.AckOption != null && _reliableDeliverySupervisor != null)
                 _reliableDeliverySupervisor.Tell(ackAndMessage.AckOption);
             if (ackAndMessage.MessageOption != null)
             {
                 if (ackAndMessage.MessageOption.ReliableDeliveryEnabled)
                 {
                     _ackedReceiveBuffer = _ackedReceiveBuffer.Receive(ackAndMessage.MessageOption);
                     DeliverAndAck();
                 }
                 else
                 {
                     _msgDispatch.Dispatch(ackAndMessage.MessageOption.Recipient,
                         ackAndMessage.MessageOption.RecipientAddress,
                         ackAndMessage.MessageOption.SerializedMessage,
                         ackAndMessage.MessageOption.SenderOptional);
                 }
             }
         }
     }
     else if (message is EndpointWriter.StopReading)
     {
         var stop = message as EndpointWriter.StopReading;
         SaveState();
         Context.Become(NotReading);
         stop.ReplyTo.Tell(new EndpointWriter.StoppedReading(stop.Writer));
     }
     else
     {
         Unhandled(message);
     }
 }