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);
        }