示例#1
0
        private static void RunSystem()
        {
            var systemOptions = ActorSystemOptions
                                .UsingName("system-1")
                                .UsingErrorHandler(
                (actorSys, error) => { Console.WriteLine(error); },
                (actorSys, process, msg, error) => { Console.WriteLine(error); });

            var actorSystem = ActorSystem.GetOrAdd(systemOptions);

            var actorOptions = ActorOptions
                               .UsingName("system-1-actor-1");

            var Completed = Task.FromResult(0);

            var sw = new Stopwatch();

            var pid = actorSystem.FromFunction((ctx, message) =>
            {
                var count = Interlocked.Increment(ref counter);

                if (count == 1)
                {
                    sw.Restart();
                }
                else
                {
                    if (count % 1000 == 0)
                    {
                        Console.WriteLine(count);
                    }

                    if (count == loop)
                    {
                        Interlocked.Exchange(ref counter, 0);

                        sw.Stop();
                        Console.WriteLine("Ellapsed time: " + sw.ElapsedMilliseconds);
                        Console.WriteLine("Concurrency: " + (loop * 1000 / sw.ElapsedMilliseconds) + " call per sec");
                    }
                }

                if (message.MessageType == MessageType.FutureMessage)
                {
                    ctx.RespondTo(message, "world " + count.ToString("000"));
                }

                return(Completed);
            },
                                               actorOptions);
        }
示例#2
0
        public static ActorSystem GetOrAdd(ActorSystemOptions options = null)
        {
            options = (options ?? ActorSystemOptions.Default);

            var actorSystemName = options.Name?.Trim();

            if (String.IsNullOrEmpty(actorSystemName))
            {
                throw new ArgumentNullException(nameof(options.Name));
            }

            return(_systemRegistery.GetOrAdd(options.Name,
                                             (sn) => new ActorSystem(options)));
        }
示例#3
0
 private ActorSystem(ActorSystemOptions options)
 {
     Options = options ?? ActorSystemOptions.Default;
     Name    = Options.Name?.Trim();
 }