Inheritance: IActor, IBatchAware
Ejemplo n.º 1
0
        public void DesribesAndDispatchesProperly()
        {
            var a = new AHandler();
            var ab = new ABHandler();
            var actor = new CompositeActor(new IActor[] {a, ab}, new StructSizeCounter(),
                FakeMessageIdGenerator.GetMessageId);
            CollectionAssert.AreEquivalent(new[] {typeof (A), typeof (B)}, actor.Descriptor.HandledMessageTypes);
            var aid = FakeMessageIdGenerator.GetMessageId(typeof (A));
            var bid = FakeMessageIdGenerator.GetMessageId(typeof (B));

            // Ensure counters
            Assert.AreEqual(0, a.ACount);
            Assert.AreEqual(0, ab.ACount);
            Assert.AreEqual(0, ab.BCount);

            // A
            actor.MessageHandler(aid, ByteChunk.Empty);
            Assert.AreEqual(1, a.ACount);
            Assert.AreEqual(1, ab.ACount);
            Assert.AreEqual(0, ab.BCount);

            // B
            actor.MessageHandler(bid, ByteChunk.Empty);
            Assert.AreEqual(1, a.ACount);
            Assert.AreEqual(1, ab.ACount);
            Assert.AreEqual(1, ab.BCount);
        }
Ejemplo n.º 2
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;
     }
 }
Ejemplo n.º 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;
     }
 }