Provides an actor description.
Beispiel #1
0
        public CompositeActor(IActor[] actors, IStructSizeCounter counter, Func <Type, int> messageIdGetter)
        {
            if (actors.Length > MaxActors)
            {
                throw new ArgumentException($"Too many actors. Can composite only up to {MaxActors}");
            }

            var messageTypes = actors.Select(a => new ActorDescriptor(a))
                               .SelectMany(descriptor => descriptor.HandledMessageTypes)
                               .Distinct()
                               .ToArray();

            Descriptor = new ActorDescriptor(messageTypes);
            _readers   = actors.Select(a => new MessageReader(a, counter, messageIdGetter)).ToArray();
            _count     = _readers.Length;

            _messageMap = BuildMessageMap(actors, messageIdGetter);
            _batchAware = actors.OfType <IBatchAware>().ToArray();
        }
Beispiel #2
0
        public CompositeActor(IActor[] actors, IStructSizeCounter counter, Func<Type, int> messageIdGetter)
        {
            if (actors.Length > MaxActors)
            {
                throw new ArgumentException($"Too many actors. Can composite only up to {MaxActors}");
            }

            var messageTypes = actors.Select(a => new ActorDescriptor(a))
                .SelectMany(descriptor => descriptor.HandledMessageTypes)
                .Distinct()
                .ToArray();

            Descriptor = new ActorDescriptor(messageTypes);
            _readers = actors.Select(a => new MessageReader(a, counter, messageIdGetter)).ToArray();
            _count = _readers.Length;

            _messageMap = BuildMessageMap(actors, messageIdGetter);
            _batchAware = actors.OfType<IBatchAware>().ToArray();
        }
Beispiel #3
0
 public Runner(IRingBuffer buffer, IStructSizeCounter counter, Func <Type, int> messageIdGetter, int batchSize,
               params IActor[] actors)
 {
     Buffer     = buffer;
     _batchSize = batchSize;
     if (actors.Length > 1)
     {
         var actor = new CompositeActor(actors, counter, messageIdGetter);
         _batchAware = actor;
         _handler    = actor.MessageHandler;
         Descriptor  = actor.Descriptor;
     }
     else
     {
         _handler    = new MessageReader(actors[0], counter, messageIdGetter).MessageHandlerImpl;
         Descriptor  = new ActorDescriptor(actors[0]);
         _batchAware = actors[0] as IBatchAware;
     }
 }
Beispiel #4
0
 public Runner(IRingBuffer buffer, IStructSizeCounter counter, Func<Type, int> messageIdGetter, int batchSize,
     params IActor[] actors)
 {
     Buffer = buffer;
     _batchSize = batchSize;
     if (actors.Length > 1)
     {
         var actor = new CompositeActor(actors, counter, messageIdGetter);
         _batchAware = actor;
         _handler = actor.MessageHandler;
         Descriptor = actor.Descriptor;
     }
     else
     {
         _handler = new MessageReader(actors[0], counter, messageIdGetter).MessageHandlerImpl;
         Descriptor = new ActorDescriptor(actors[0]);
         _batchAware = actors[0] as IBatchAware;
     }
 }
Beispiel #5
0
        private static int[] BuildMessageMap(IActor[] actors, Func <Type, int> messageIdGetter)
        {
            var map = new int[MessageMapSize];

            for (var i = 0; i < actors.Length; i++)
            {
                var messageHashes = new ActorDescriptor(actors[i]).HandledMessageTypes
                                    .Select(messageIdGetter)
                                    .Select(HashMessageId)
                                    .Distinct()
                                    .ToArray();

                foreach (var messageHash in messageHashes)
                {
                    // this may collide because it's a hashtable, but it uses | so the cost of collision is running one actor additionally, if it happend at all
                    map[messageHash] |= GetActorMask(i);
                }
            }

            return(map);
        }
Beispiel #6
0
        private static int[] BuildMessageMap(IActor[] actors, Func<Type, int> messageIdGetter)
        {
            var map = new int[MessageMapSize];

            for (var i = 0; i < actors.Length; i++)
            {
                var messageHashes = new ActorDescriptor(actors[i]).HandledMessageTypes
                    .Select(messageIdGetter)
                    .Select(HashMessageId)
                    .Distinct()
                    .ToArray();

                foreach (var messageHash in messageHashes)
                {
                    // this may collide because it's a hashtable, but it uses | so the cost of collision is running one actor additionally, if it happend at all
                    map[messageHash] |= GetActorMask(i);
                }
            }

            return map;
        }