コード例 #1
0
        /// <inheritdoc />
        public override object FromBinary(byte[] bytes, Type type)
        {
            var selectionEnvelope = Proto.Msg.SelectionEnvelope.Parser.ParseFrom(bytes);
            var message           = _payloadSupport.PayloadFrom(selectionEnvelope.Payload);

            var elements = new SelectionPathElement[selectionEnvelope.Pattern.Count];

            for (var i = 0; i < selectionEnvelope.Pattern.Count; i++)
            {
                var p = selectionEnvelope.Pattern[i];
                if (p.Type == Proto.Msg.Selection.Types.PatternType.ChildName)
                {
                    elements[i] = new SelectChildName(p.Matcher);
                }
                if (p.Type == Proto.Msg.Selection.Types.PatternType.ChildPattern)
                {
                    elements[i] = new SelectChildPattern(p.Matcher);
                }
                if (p.Type == Proto.Msg.Selection.Types.PatternType.Parent)
                {
                    elements[i] = new SelectParent();
                }
            }

            return(new ActorSelectionMessage(message, elements));
        }
コード例 #2
0
 /// <summary>
 ///     Delivers the specified message.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="pathIndex">Index of the path.</param>
 /// <param name="current">The current.</param>
 private void Deliver(object message, ActorRef sender, int pathIndex, ActorRef current)
 {
     if (pathIndex == Elements.Length)
     {
         current.Tell(message, sender);
     }
     else
     {
         SelectionPathElement element = Elements[pathIndex];
         if (current is ActorRefWithCell)
         {
             var withCell = (ActorRefWithCell)current;
             if (element is SelectParent)
             {
                 Deliver(message, sender, pathIndex + 1, withCell.Parent);
             }
             else if (element is SelectChildName)
             {
                 Deliver(message, sender, pathIndex + 1,
                         withCell.GetSingleChild(element.AsInstanceOf <SelectChildName>().Name));
             }
         }
         else
         {
             SelectionPathElement[] rest = Elements.Skip(pathIndex).ToArray();
             current.Tell(new ActorSelectionMessage(message, rest), sender);
         }
     }
 }
コード例 #3
0
        /// <inheritdoc />
        public override object FromBinary(byte[] bytes, Type type)
        {
            var selectionEnvelope = Proto.Msg.SelectionEnvelope.Parser.ParseFrom(bytes);

            var elements = new SelectionPathElement[selectionEnvelope.Pattern.Count];

            for (var i = 0; i < selectionEnvelope.Pattern.Count; i++)
            {
                var p = selectionEnvelope.Pattern[i];
                if (p.Type == Proto.Msg.Selection.Types.PatternType.ChildName)
                {
                    elements[i] = new SelectChildName(p.Matcher);
                }
                if (p.Type == Proto.Msg.Selection.Types.PatternType.ChildPattern)
                {
                    elements[i] = new SelectChildPattern(p.Matcher);
                }
                if (p.Type == Proto.Msg.Selection.Types.PatternType.Parent)
                {
                    elements[i] = new SelectParent();
                }
            }

            object message;

            try
            {
                message = _payloadSupport.PayloadFrom(selectionEnvelope.Payload);
            }
            catch (Exception ex)
            {
                var payload = selectionEnvelope.Payload;

                var manifest = !payload.MessageManifest.IsEmpty
                    ? payload.MessageManifest.ToStringUtf8()
                    : string.Empty;

                throw new SerializationException(
                          $"Failed to deserialize payload object when deserializing {nameof(ActorSelectionMessage)} with " +
                          $"payload [SerializerId={payload.SerializerId}, Manifest={manifest}] addressed to [" +
                          $"{string.Join(",", elements.Select(e => e.ToString()))}]. {GetErrorForSerializerId(payload.SerializerId)}", ex);
            }

            return(new ActorSelectionMessage(message, elements));
        }
コード例 #4
0
ファイル: ActorSelection.cs プロジェクト: wendell620/akka.net
 /// <summary>
 ///     Delivers the specified message.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="pathIndex">Index of the path.</param>
 /// <param name="current">The current.</param>
 private void Deliver(object message, ActorRef sender, int pathIndex, ActorRef current)
 {
     if (pathIndex == Elements.Length)
     {
         current.Tell(message, sender);
     }
     else
     {
         SelectionPathElement element = Elements[pathIndex];
         if (current is ActorRefWithCell)
         {
             var withCell = (ActorRefWithCell)current;
             if (element is SelectParent)
             {
                 Deliver(message, sender, pathIndex + 1, withCell.Parent);
             }
             else if (element is SelectChildName)
             {
                 Deliver(message, sender, pathIndex + 1,
                         withCell.GetSingleChild(element.AsInstanceOf <SelectChildName>().Name));
             }
             else if (element is SelectChildPattern)
             {
                 var pattern  = element as SelectChildPattern;
                 var children = withCell.Children.Where(c => c.Path.Name.Like(pattern.PatternStr));
                 foreach (var matchingChild in children)
                 {
                     Deliver(message, sender, pathIndex + 1, matchingChild);
                 }
             }
         }
         else
         {
             SelectionPathElement[] rest = Elements.Skip(pathIndex).ToArray();
             current.Tell(new ActorSelectionMessage(message, rest), sender);
         }
     }
 }
コード例 #5
0
ファイル: ActorSelection.cs プロジェクト: pdoh00/akka.net
 /// <summary>
 ///     Initializes a new instance of the <see cref="ActorSelection" /> class.
 /// </summary>
 /// <param name="anchor">The anchor.</param>
 /// <param name="path">The path.</param>
 public ActorSelection(ActorRef anchor, SelectionPathElement[] path)
 {
     Anchor = anchor;
     Elements = path;
 }
コード例 #6
0
ファイル: ActorSelection.cs プロジェクト: pdoh00/akka.net
 /// <summary>
 ///     Initializes a new instance of the <see cref="ActorSelectionMessage" /> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="elements">The elements.</param>
 public ActorSelectionMessage(object message, SelectionPathElement[] elements)
 {
     Message = message;
     Elements = elements;
 }
コード例 #7
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ActorSelectionMessage" /> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="elements">The elements.</param>
 public ActorSelectionMessage(object message, SelectionPathElement[] elements, bool wildCardFanOut=false)
 {
     Message = message;
     Elements = elements;
     WildCardFanOut = wildCardFanOut;
 }