Example #1
0
 public void Process(AsTelegram telegram)
 {
     foreach (var pair in _pairs)
     {
         if (pair.DoesMatch(telegram))
         {
             pair.Action(telegram);
             return;
         }
     }
     Preconditions.Fail("Cannot match telegram " + telegram);
 }
Example #2
0
        public void Update()
        {
            if (_reciever == null)
            {
                _reciever = BuildRecieve(new AsRecieverBuilder());
            }
            var thisFrameIndex    = Time.frameCount;
            var messagesToProcess = _queue.Where(c => c.Timestamp.FrameNo < thisFrameIndex).ToList();

            _queue = new Queue <AsTelegram>(_queue.Where(c => c.Timestamp.FrameNo >= thisFrameIndex).ToList());

            messagesToProcess.ForEach(c =>
            {
                _registry?.RegisterRecievedMessage(this, c);
                _messageBeingRepliedTo = c;
                _reciever.Process(c);
            });

            _messageBeingRepliedTo = null;
            InternalUpdate();
        }
Example #3
0
        protected void SendTelegram(AsAbstractActor destinationActor, object payload)
        {
            var telegram = new AsTelegram()
            {
                Payload   = payload,
                Sender    = this,
                Reciever  = destinationActor,
                Timestamp = new AsTelegramTimestamp()
                {
                    FrameNo      = Time.frameCount,
                    MessageIndex = _lastMessageIndex++
                }
            };

            destinationActor.RecieveTelegram(telegram);
            if (_messageBeingRepliedTo == null)
            {
                _registry?.RegisterInitiatedMessage(this, telegram);
            }
            else
            {
                _registry?.RegisterReplyMessage(this, _messageBeingRepliedTo, telegram);
            }
        }
Example #4
0
 private void RecieveTelegram(AsTelegram telegram)
 {
     _queue.Enqueue(telegram);
 }
Example #5
0
 public override bool DoesMatch(AsTelegram telegram)
 {
     return(true);
 }
Example #6
0
 public override bool DoesMatch(AsTelegram telegram)
 {
     return(telegram.CanCastPayload <T>());
 }
Example #7
0
 public abstract bool DoesMatch(AsTelegram telegram);
Example #8
0
 public bool DoesMatch(AsTelegram telegram)
 {
     return(_matcher.DoesMatch(telegram));
 }