Пример #1
0
        internal static ActorProtocolActor <T>[] AllOf(Actor actor, T[] protocolActors)
        {
            var all = new ActorProtocolActor <T> [protocolActors.Length];

            for (int idx = 0; idx < protocolActors.Length; ++idx)
            {
                all[idx] = new ActorProtocolActor <T>(actor, protocolActors[idx]);
            }
            return(all);
        }
Пример #2
0
        /// <summary>
        /// Answers a <c>Protocols</c> that provides one or more supported <paramref name="protocols"/> for the
        /// newly created <c>Actor</c> according to <paramref name="definition"/>.
        /// </summary>
        /// <param name="definition">The <c>Definition</c> providing parameters to the <c>Actor</c>.</param>
        /// <param name="protocols">The array of protocol that the <c>Actor</c> supports.</param>
        /// <returns>A <see cref="Protocols"/> instance.</returns>
        public Protocols ActorFor(Definition definition, Type[] protocols)
        {
            var all = ActorProtocolFor(
                definition,
                protocols,
                definition.ParentOr(World.DefaultParent),
                definition.Supervisor,
                definition.LoggerOr(World.DefaultLogger));

            return(new Protocols(ActorProtocolActor <object> .ToActors(all)));
        }
Пример #3
0
        internal static object[] ToActors(ActorProtocolActor <object>[]?all)
        {
            if (all == null)
            {
                return(new object[0]);
            }

            var actors = new object[all.Length];

            for (int idx = 0; idx < all.Length; ++idx)
            {
                actors[idx] = all[idx].ProtocolActor;
            }
            return(actors);
        }
Пример #4
0
        internal static object[] ToTestActors(ActorProtocolActor <T>[]?all, Type[] protocols)
        {
            if (all == null)
            {
                return(new object[0]);
            }

            var testActors = new object[all.Length];

            for (int idx = 0; idx < all.Length; ++idx)
            {
                testActors[idx] = all[idx].ToTestActor(protocols[idx]);
            }

            return(testActors);
        }
Пример #5
0
        internal Protocols TestActorFor(Definition definition, Type[] protocols)
        {
            var redefinition = Definition.Has(
                definition.Type,
                definition.Parameters(),
                TestMailbox.Name,
                definition.ActorName);

            var all = ActorProtocolFor(
                redefinition,
                protocols,
                definition.ParentOr(World.DefaultParent),
                null,
                null,
                definition.Supervisor,
                definition.LoggerOr(World.DefaultLogger));

            return(new Protocols(ActorProtocolActor <object> .ToTestActors(all, protocols)));
        }
Пример #6
0
 internal ActorProtocolActor <object>[] ActorProtocolFor(
     Definition definition,
     Type[] protocols,
     Actor parent,
     Address maybeAddress,
     IMailbox maybeMailbox,
     ISupervisor maybeSupervisor,
     ILogger logger)
 {
     try
     {
         var actor          = CreateRawActor(definition, parent, maybeAddress, maybeMailbox, maybeSupervisor, logger);
         var protocolActors = ActorProxyFor(protocols, actor, actor.LifeCycle.Environment.Mailbox);
         return(ActorProtocolActor <object> .AllOf(actor, protocolActors));
     }
     catch (Exception e)
     {
         World.DefaultLogger.Log($"vlingo/actors: FAILED: {e.Message}", e);
         return(null);
     }
 }
Пример #7
0
        /// <summary>
        /// Answers the ActorProtocolActor[] for the newly created Actor instance. (INTERNAL ONLY)
        /// </summary>
        /// <param name="protocols"></param>
        /// <param name="definition"></param>
        /// <param name="parent"></param>
        /// <param name="maybeAddress"></param>
        /// <param name="maybeMailbox"></param>
        /// <param name="maybeSupervisor"></param>
        /// <param name="logger"></param>
        /// <returns></returns>
        internal ActorProtocolActor <object>[] ActorProtocolFor(
            Type[] protocols,
            Definition definition,
            Actor parent,
            IAddress maybeAddress,
            IMailbox maybeMailbox,
            ISupervisor maybeSupervisor,
            ILogger logger)
        {
            AssertProtocolCompliance(protocols);
            try
            {
                var actor          = CreateRawActor(definition, parent, maybeAddress, maybeMailbox, maybeSupervisor, logger);
                var protocolActors = ActorProxyFor(protocols, actor, actor.LifeCycle.Environment.Mailbox);
                return(ActorProtocolActor <object> .AllOf(protocolActors, actor));
            }
            catch (Exception e)
            {
                World.DefaultLogger.Error($"vlingo-net/actors: FAILED: {e.Message}", e);
            }

            return(null);
        }
Пример #8
0
        /// <summary>
        /// Answers a <code>Protocols</code> that provides one or more supported <paramref name="protocols"/> for the
        /// newly created <code>Actor</code> according to <paramref name="definition"/>.
        /// </summary>
        /// <param name="protocols">Array of protocols that the <code>Actor</code> supports.</param>
        /// <param name="definition">The definition providing parameters to the <code>Actor</code>.</param>
        /// <param name="parent">The actor that is this actor's parent.</param>
        /// <param name="maybeSupervisor">The possible supervisor of this actor.</param>
        /// <param name="logger">The logger of this actor.</param>
        /// <returns></returns>
        public Protocols ActorFor(Type[] protocols, Definition definition, Actor parent, ISupervisor?maybeSupervisor, ILogger logger)
        {
            var all = ActorProtocolFor(protocols, definition, parent, maybeSupervisor, logger);

            return(new Protocols(ActorProtocolActor <object> .ToActors(all)));
        }