Пример #1
0
        public void In(Bundle bundle)
        {
            //extract entities out of incoming bundle:
            IList <Entity> entities = bundle.Entities;

            //prepare new sub-bundles:
            Bundle subBundle = new Bundle();
            int    counter   = 0;

            for (int i = 0; i < entities.Count; i++)
            {
                //add carrier to new sub bundle
                subBundle.AddEntity(entities[i]);
                counter++;

                //until the limit for a sub bundle is reached:
                if (counter == SeekSize)
                {
                    //forward sub bundle
                    _successor?.In(subBundle);

                    //reset counter and create new sub bundle
                    counter   = 0;
                    subBundle = new Bundle();
                }
            }
            //for the case that there are no more carriers left, but the last sub bundle has not reached the seeked size
            if (subBundle.Count > 1)
            {
                //forward sub bundle (even it has not the seeked size)
                _successor?.In(subBundle);
            }
        }
 public void In(Bundle bundle)
 {
     _waitingBuffer.Enqueue(bundle);
     if (_waitingBuffer.Count >= Size)
     {
         Bundle b = new Bundle();
         for (int i = 0; i < Size; i++)
         {
             Bundle bb = _waitingBuffer.Dequeue();
             foreach (Entity e in bb.Entities)
             {
                 b.AddEntity(e);
             }
         }
         Successor?.In(b);
     }
 }