Example #1
0
        private Actor CreateRawActor(
            Definition definition,
            Actor parent,
            Address maybeAddress,
            IMailbox maybeMailbox,
            ISupervisor maybeSupervisor,
            ILogger logger)
        {
            if (IsStopped)
            {
                throw new InvalidOperationException("Actor stage has been stopped.");
            }

            var address = maybeAddress ?? World.AddressFactory.UniqueWith(definition.ActorName);

            if (directory.IsRegistered(address))
            {
                throw new InvalidOperationException("Address already exists: " + address);
            }

            var mailbox = maybeMailbox ?? ActorFactory.ActorMailbox(this, address, definition);

            Actor actor;

            try
            {
                actor = ActorFactory.ActorFor(this, parent, definition, address, mailbox, maybeSupervisor, logger);
            }
            catch (Exception e)
            {
                logger.Log($"Actor instantiation failed because: {e.Message}");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                throw new InvalidOperationException($"Actor instantiation failed because: {e.Message}", e);
            }

            directory.Register(actor.Address, actor);
            actor.LifeCycle.BeforeStart(actor);

            return(actor);
        }
 /// <summary>
 /// Answers a Mailbox for an Actor. If maybeMailbox is allocated answer it; otherwise
 /// answer a newly allocated Mailbox. (INTERNAL ONLY)
 /// </summary>
 /// <param name="definition">the Definition of the newly created Actor</param>
 /// <param name="address">the Address allocated to the Actor</param>
 /// <param name="maybeMailbox">the possible Mailbox</param>
 /// <returns></returns>
 private IMailbox AllocateMailbox(Definition definition, IAddress address, IMailbox maybeMailbox)
 => maybeMailbox ?? ActorFactory.ActorMailbox(this, address, definition);