Exemple #1
0
        public TestActor <T> TestActorFor <T>(Definition definition)
        {
            var redefinition = Definition.Has(
                definition.Type,
                definition.Parameters(),
                TestMailbox.Name,
                definition.ActorName);

            try
            {
                return(ActorProtocolFor <T>(
                           redefinition,
                           definition.ParentOr(World.DefaultParent),
                           null,
                           null,
                           definition.Supervisor,
                           definition.LoggerOr(World.DefaultLogger)).ToTestActor());
            }
            catch (Exception e)
            {
                World.DefaultLogger.Log($"vlingo-net/actors: FAILED: {e.Message}", e);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                return(null);
            }
        }
Exemple #2
0
 /// <summary>
 /// Starts the <c>PrivateRootActor</c>. When the <c>PrivateRootActor</c> starts it will in turn
 /// start the <c>PublicRootActor</c>.
 /// </summary>
 /// <param name="stage">The <c>Stage</c> in which to start the <c>PrivateRootActor</c>.</param>
 /// <param name="logger">The default <c>ILogger</c> for this <c>World</c> and <c>Stage</c>.</param>
 private void StartRootFor(Stage stage, ILogger logger)
 => stage.ActorProtocolFor <IStoppable>(
     Definition.Has <PrivateRootActor>(Definition.NoParameters, PrivateRootName),
     null,
     AddressFactory.From(PrivateRootId, PrivateRootName),
     null,
     null,
     logger);
Exemple #3
0
 /// <summary>
 /// Registers the <paramref name="supervisorClass"/> plugin by <paramref name="name"/> that will serve as the default supervise for all <c>Actor</c>
 /// that are not supervised by a specific supervisor.
 /// </summary>
 /// <param name="stageName">The <c>string</c> of the <c>Stage</c> in which the <paramref name="supervisorClass"/> is be registered.</param>
 /// <param name="name">The <c>string</c> name of the supervisor to register.</param>
 /// <param name="supervisorClass">The <c>Type</c> (which should be a subclass of <c>Actor</c>) to register as a supervisor.</param>
 public void RegisterDefaultSupervisor(string stageName, string name, Type?supervisorClass)
 {
     try
     {
         var actualStageName = stageName.Equals("default") ? DefaultStage : stageName;
         var stage           = StageNamed(actualStageName);
         defaultSupervisor = stage.ActorFor <ISupervisor>(Definition.Has(supervisorClass, Definition.NoParameters, name));
     }
     catch (Exception e)
     {
         DefaultLogger.Error($"vlingo-net/actors: World cannot register default supervisor override: {supervisorClass!.Name}", e);
     }
 }
Exemple #4
0
 /// <summary>
 /// Registers the<paramref name="supervisorClass"/> plugin by <paramref name="name"/> that will supervise all <c>Actor</c> that implement the <paramref name="supervisedProtocol"/>.
 /// </summary>
 /// <param name="stageName">The <c>string</c> of the <c>Stage</c> in which the <paramref name="supervisorClass"/> is be registered.</param>
 /// <param name="name">The <c>string</c> name of the supervisor to register.</param>
 /// <param name="supervisedProtocol">The protocol for which the supervisor will supervise.</param>
 /// <param name="supervisorClass">The <c>Type</c> (which should be a subclass of <c>Actor</c>) to register as a supervisor.</param>
 public void RegisterCommonSupervisor(string stageName, string name, Type?supervisedProtocol, Type?supervisorClass)
 {
     try
     {
         var actualStageName = stageName.Equals("default") ? DefaultStage : stageName;
         var stage           = StageNamed(actualStageName);
         var common          = stage.ActorFor <ISupervisor>(Definition.Has(supervisorClass, Definition.NoParameters, name));
         stage.RegisterCommonSupervisor(supervisedProtocol, common);
     }
     catch (Exception e)
     {
         DefaultLogger.Error($"vlingo-net/actors: World cannot register common supervisor: {supervisedProtocol!.Name}", e);
     }
 }
Exemple #5
0
 public virtual void RegisterDefaultSupervisor(string stageName, string name, Type supervisorClass)
 {
     try
     {
         var actualStageName = stageName.Equals("default") ? DefaultStage : stageName;
         var stage           = StageNamed(actualStageName);
         defaultSupervisor = stage.ActorFor <ISupervisor>(Definition.Has(supervisorClass, Definition.NoParameters, name));
     }
     catch (Exception e)
     {
         DefaultLogger.Log($"vlingo-net/actors: World cannot register default supervisor override: {supervisorClass.Name}", e);
         Console.WriteLine(e.Message);
         Console.WriteLine(e.StackTrace);
     }
 }
Exemple #6
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)));
        }
Exemple #7
0
        public PrivateRootActor()
        {
            SupervisionStrategy = new PrivateRootActorSupervisionStrategy();

            Stage.World.SetPrivateRoot(SelfAs <IStoppable>());

            Stage.ActorProtocolFor <INoProtocol>(
                Definition.Has <PublicRootActor>(Definition.NoParameters, World.PublicRootName),
                this,
                Stage.World.AddressFactory.From(World.PublicRootId, World.PublicRootName),
                null,
                null,
                Logger);

            Stage.ActorProtocolFor <IDeadLetters>(
                Definition.Has <DeadLettersActor>(Definition.NoParameters, World.DeadLettersName),
                this,
                Stage.World.AddressFactory.From(World.DeadLettersId, World.DeadLettersName),
                null,
                null,
                Logger);
        }
Exemple #8
0
        protected internal override void BeforeStart()
        {
            base.BeforeStart();

            Stage.World.SetPrivateRoot(SelfAs <IStoppable>());

            Stage.ActorProtocolFor <INoProtocol>(
                Definition.Has <PublicRootActor>(Definition.NoParameters, World.PublicRootName),
                this,
                Stage.World.AddressFactory.From(World.PublicRootId, World.PublicRootName),
                null,
                null,
                Logger);

            Stage.ActorProtocolFor <IDeadLetters>(
                Definition.Has <DeadLettersActor>(Definition.NoParameters, World.DeadLettersName),
                this,
                Stage.World.AddressFactory.From(World.DeadLettersId, World.DeadLettersName),
                null,
                null,
                Logger);
        }
Exemple #9
0
        /// <summary>
        /// Start the directory scan process in search for a given Actor instance. (INTERNAL ONLY)
        /// </summary>
        internal void StartDirectoryScanner()
        {
            _directoryScanner = ActorFor <IDirectoryScanner>(
                Definition.Has <DirectoryScannerActor>(
                    Definition.Parameters(_directory)),
                World.AddressFactory.UniqueWith($"DirectoryScanner::{Name}"));

            var evictionConfiguration = World.Configuration.DirectoryEvictionConfiguration;

            if (evictionConfiguration != null && evictionConfiguration.IsEnabled)
            {
                World.DefaultLogger.Debug($"Scheduling directory eviction for stage: {Name} with: {evictionConfiguration}");
                var evictorActor = ActorFor <IScheduled <object> >(
                    Definition.Has(() => new DirectoryEvictor(evictionConfiguration, Directory)),
                    World.AddressFactory.UniqueWith($"EvictorActor::{Name}"));

                var evictorActorInterval = Properties.GetLong(
                    "stage.evictor.interval", Math.Min(15_000L, evictionConfiguration.LruThresholdMillis));

                Scheduler.Schedule(evictorActor, null !, TimeSpan.FromMilliseconds(evictorActorInterval), TimeSpan.FromMilliseconds(evictorActorInterval));
            }
        }
Exemple #10
0
 internal void StartDirectoryScanner()
 {
     directoryScanner = ActorFor <IDirectoryScanner>(
         Definition.Has <DirectoryScannerActor>(
             Definition.Parameters(directory)));
 }
Exemple #11
0
 public T ActorFor <T>(Expression <Func <T> > factory, IAddress address)
 => ActorFor <T>(Definition.Has(factory), address);
Exemple #12
0
 public T ActorFor <T>(Expression <Func <T> > factory, string mailboxName, string actorName, IAddress address, ILogger logger)
 => ActorFor <T>(Definition.Has(factory, mailboxName, actorName), address, logger);
Exemple #13
0
 protected internal T ChildActorFor <T>(Expression <Func <T> > factory)
 => ChildActorFor <T>(Definition.Has(factory));
Exemple #14
0
 public T ActorFor <T>(Expression <Func <T> > factory, string actorName) => ActorFor <T>(Definition.Has(factory, actorName));
Exemple #15
0
 public T ActorFor <T>(Expression <Func <T> > factory) => ActorFor <T>(Definition.Has(factory));
Exemple #16
0
 /// <summary>
 /// Answers a <c>Protocols</c> that provides one or more supported <paramref name="protocols"/> for the
 /// newly created <c>Actor</c> with the provided <paramref name="parameters"/>.
 /// </summary>
 /// <param name="protocols">The array of protocol that the <c>Actor</c> supports.</param>
 /// <param name="type">The type of the <c>Actor</c> to create.</param>
 /// <param name="parameters">The constructor parameters.</param>
 /// <returns>A <see cref="Protocols"/> instance.</returns>
 public Protocols ActorFor(Type[] protocols, Type type, params object[] parameters)
 => ActorFor(protocols, Definition.Has(type, parameters.ToList()));
Exemple #17
0
 public T ActorFor <T>(Expression <Func <T> > factory, ILogger logger)
 => ActorFor <T>(Definition.Has(factory), logger);
Exemple #18
0
 /// <summary>
 /// Answers the <code>T</code> protocol of the newly created <code>Actor</code> that implements the <code>protocol</code>.
 /// </summary>
 /// <typeparam name="T">The protocol type</typeparam>
 /// <param name="type">The type of <code>Actor</code> to create</param>
 /// <param name="parameters">Constructor parameters for the <code>Actor</code></param>
 /// <returns></returns>
 public T ActorFor <T>(Type type, params object[] parameters)
 => ActorFor <T>(Definition.Has(type, parameters.ToList()));
Exemple #19
0
 internal T ActorFor <T>(Expression <Func <T> > factory, Actor?parent, ISupervisor?maybeSupervisor, ILogger logger)
 => ActorFor <T>(Definition.Has(factory), parent, maybeSupervisor, logger);
Exemple #20
0
 public TestActor <T>?TestActorFor <T>(Type actorType, params object[] parameters)
 => TestActorFor <T>(Definition.Has(actorType, parameters.ToList()));