Class responsible for pushing messages from an actor's mailbox into its receive methods. Comes in many different flavors.
Пример #1
0
 public RootGuardianActorRef(ActorSystemImpl system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, //TODO: switch from  Func<Mailbox> createMailbox to MailboxType mailboxType
     IInternalActorRef supervisor, ActorPath path, IInternalActorRef deadLetters, IReadOnlyDictionary<string, IInternalActorRef> extraNames)
     : base(system,props,dispatcher,createMailbox,supervisor,path)
 {
     _deadLetters = deadLetters;
     _extraNames = extraNames;
 }
Пример #2
0
 public ActorCell(ActorSystemImpl system, InternalActorRef self, Props props, MessageDispatcher dispatcher, InternalActorRef parent)
 {
     _self = self;
     _props = props;
     _systemImpl = system;
     Parent = parent;
     Dispatcher = dispatcher;            
 }
Пример #3
0
 public RepointableActorRef(ActorSystemImpl system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, IInternalActorRef supervisor, ActorPath path)
 {
     _system = system;
     _props = props;
     _dispatcher = dispatcher;
     _createMailbox = createMailbox;
     _supervisor = supervisor;
     _path = path;
 }
Пример #4
0
 public LocalSnapshotStore()
 {
     var config = Context.System.Settings.Config.GetConfig("akka.persistence.snapshot-store.local");
     _snapshotDirectory = new DirectoryInfo(config.GetString("dir"));
     ResolveDispatcher(config);
     _saving = new SortedSet<SnapshotMetadata>(SnapshotMetadata.TimestampComparer);
     _serialization = Context.System.Serialization;
     _streamDispatcher = ResolveDispatcher(config);
 }
Пример #5
0
 public RepointableActorRef(ActorSystemImpl system, Props props, MessageDispatcher dispatcher, MailboxType mailboxType, IInternalActorRef supervisor, ActorPath path)
 {
     System = system;
     Props = props;
     Dispatcher = dispatcher;
     MailboxType = mailboxType;
     Supervisor = supervisor;
     _path = path;
 }
Пример #6
0
 /// <summary>
 /// Inheritors should only call this constructor
 /// </summary>
 internal protected  LocalActorRef(ActorSystem system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, IInternalActorRef supervisor, ActorPath path, Func<LocalActorRef, ActorCell> createActorCell) //TODO: switch from  Func<Mailbox> createMailbox to MailboxType mailboxType      
 {
     _system = system;
     _props = props;
     _dispatcher = dispatcher;
     _createMailbox = createMailbox;
     _supervisor = supervisor;
     _path = path;
     _cell = createActorCell(this);
 }
Пример #7
0
        //This mimics what's done in Akka`s construction of an LocalActorRef.
        //The actorCell is created in the overridable newActorCell() during creation of the instance.
        //Since we don't want calls to virtual members in C# we must supply it. 
        //
        //This is the code from Akka:
        //    private[akka] class LocalActorRef private[akka] (
        //        _system: ActorSystemImpl,
        //        _props: Props,
        //        _dispatcher: MessageDispatcher,
        //        _mailboxType: MailboxType,
        //        _supervisor: InternalActorRef,
        //        override val path: ActorPath) extends ActorRefWithCell with LocalRef {
        //      private val actorCell: ActorCell = newActorCell(_system, this, _props, _dispatcher, _supervisor)
        //      actorCell.init(sendSupervise = true, _mailboxType)
        //      ...
        //    }
        public LocalActorRef(ActorSystemImpl system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, IInternalActorRef supervisor, ActorPath path) //TODO: switch from  Func<Mailbox> createMailbox to MailboxType mailboxType      
            : this(system, props, dispatcher, createMailbox, supervisor, path, self =>
            {
                var cell= new ActorCell(system, self, props, dispatcher, supervisor);
                cell.Init(sendSupervise: true, createMailbox: createMailbox);
                return cell;
            })
        {
            //Intentionally left blank

        }
Пример #8
0
        public ResizablePoolCell(ActorSystemImpl system, IInternalActorRef self, Props routerProps, MessageDispatcher dispatcher, Props routeeProps, IInternalActorRef supervisor, Pool pool)
            : base(system,self, routerProps,dispatcher, routeeProps, supervisor)
        {
            if (pool.Resizer == null) throw new ArgumentException("RouterConfig must be a Pool with defined resizer");

            resizer = pool.Resizer;
            _routerProps = routerProps;
            _pool = pool;
            _resizeCounter = new AtomicCounterLong(0);
            _resizeInProgress = new AtomicBoolean();
        }
Пример #9
0
 public RoutedActorCell(
     ActorSystemImpl system,
     IInternalActorRef self,
     Props routerProps,
     MessageDispatcher dispatcher,
     Props routeeProps,
     IInternalActorRef supervisor)
     : base(system, self, routerProps, dispatcher, supervisor)
 {
     RouteeProps = routeeProps;
     RouterConfig = routerProps.RouterConfig;
     Router = null;
 }
Пример #10
0
 public RoutedActorRef(
     ActorSystemImpl system,
     Props routerProps,
     MessageDispatcher routerDispatcher,
     MailboxType routerMailbox,
     Props routeeProps,
     IInternalActorRef supervisor,
     ActorPath path)
     : base(system, routerProps, routerDispatcher, routerMailbox, supervisor, path)
 {
     _routeeProps = routeeProps;
     routerProps.RouterConfig.VerifyConfig(path);
 }
Пример #11
0
 public void Setup(BenchmarkContext context)
 {
     _configurator = Configurator();
     _dispatcher = _configurator.Dispatcher();
     _dispatcherCounter = context.GetCounter(DispatcherCounterName);
     ScheduledWork = () =>
     {
         _dispatcherCounter.Increment();
         if (Interlocked.Increment(ref _messagesSeen) == ScheduleCount)
         {
             EventBlock.Set();
         }
     };
     Warmup(_dispatcher);
 }
 public void Setup(BenchmarkContext context)
 {
     Sys = ActorSystem.Create("Sys");
     Prereqs = new DefaultDispatcherPrerequisites(Sys.EventStream, Sys.Scheduler, Sys.Settings, Sys.Mailboxes);
     _configurator = Configurator();
     _dispatcher = _configurator.Dispatcher();
     _dispatcherCounter = context.GetCounter(DispatcherCounterName);
     ScheduledWork = () =>
     {
         _dispatcherCounter.Increment();
         if (Interlocked.Increment(ref _messagesSeen) == ScheduleCount)
         {
             EventBlock.Set();
         }
     };
     Warmup(_dispatcher);
 }
Пример #13
0
 public RoutedActorRef(ActorSystemImpl system, Props routerProps, MessageDispatcher routerDispatcher,
     Func<Mailbox> createMailbox, Props routeeProps, IInternalActorRef supervisor, ActorPath path)
     : base(system, routerProps, routerDispatcher, createMailbox, supervisor, path)
 {
     _system = system;
     _routerProps = routerProps;
     _routerDispatcher = routerDispatcher;
     _createMailbox = createMailbox;
     _routeeProps = routeeProps;
     _supervisor = supervisor;
     //TODO: Implement:
     // // verify that a BalancingDispatcher is not used with a Router
     // if (!(routerProps.RouterConfig is NoRouter) && routerDispatcher is BalancingDispatcher)
     // {
     //     throw new ConfigurationException("Configuration for " + this +
     //                                 " is invalid - you can not use a 'BalancingDispatcher' as a Router's dispatcher, you can however use it for the routees.");
     // }
     // routerProps.RouterConfig.VerifyConfig(path);
 }
        protected override void Warmup(MessageDispatcher dispatcher)
        {
            var warmupCount = 10L;
            var warmupsThusFar = 0L;
            Action warmupWork = () =>
            {
                if (Interlocked.Increment(ref warmupsThusFar) == warmupCount)
                {
                    EventBlock.Set();
                }
            };


            for (var i = 0; i < warmupCount;)
            {
                dispatcher.Schedule(warmupWork);
                ++i;
            }
            EventBlock.Wait();
            EventBlock.Reset();
        }
Пример #15
0
        //This mimics what's done in Akka`s construction of an LocalActorRef.
        //The actorCell is created in the overridable newActorCell() during creation of the instance.
        //Since we don't want calls to virtual members in C# we must supply it. 
        //
        //This is the code from Akka:
        //    private[akka] class LocalActorRef private[akka] (
        //        _system: ActorSystemImpl,
        //        _props: Props,
        //        _dispatcher: MessageDispatcher,
        //        _mailboxType: MailboxType,
        //        _supervisor: InternalActorRef,
        //        override val path: ActorPath) extends ActorRefWithCell with LocalRef {
        //      private val actorCell: ActorCell = newActorCell(_system, this, _props, _dispatcher, _supervisor)
        //      actorCell.init(sendSupervise = true, _mailboxType)
        //      ...
        //    }
        public LocalActorRef(ActorSystemImpl system, Props props, MessageDispatcher dispatcher, MailboxType mailboxType, IInternalActorRef supervisor, ActorPath path) 
        {
            _system = system;
            _props = props;
            _dispatcher = dispatcher;
            MailboxType = mailboxType;
            _supervisor = supervisor;
            _path = path;

           /*
            * Safe publication of this class’s fields is guaranteed by Mailbox.SetActor()
            * which is called indirectly from ActorCell.init() (if you’re wondering why
            * this is at all important, remember that under the CLR readonly fields are only
            * frozen at the _end_ of the constructor, but we are publishing “this” before
            * that is reached).
            * This means that the result of NewActorCell needs to be written to the field
            * _cell before we call init and start, since we can start using "this"
            * object from another thread as soon as we run init.
            */
            // ReSharper disable once VirtualMemberCallInContructor 
            _cell = NewActorCell(_system, this, _props, _dispatcher, _supervisor); // _cell needs to be assigned before Init is called. 
            _cell.Init(true, MailboxType);
        }
Пример #16
0
 public RoutedActorCell(ActorSystemImpl system, InternalActorRef self, Props routerProps, MessageDispatcher dispatcher, Props routeeProps, InternalActorRef supervisor)
     : base(system, self, routerProps, dispatcher, supervisor)
 {
     _routeeProps = routeeProps;
     _routerConfig = routerProps.RouterConfig;
     _router = _routerConfig.CreateRouter(system);
     _routerConfig.Match()
         .With<Pool>(r =>
         {
             var routees = new List<Routee>();
             for(int i = 0; i < r.NrOfInstances; i++)
             {
                 var routee = ActorOf(_routeeProps);
                 routees.Add(new ActorRefRoutee(routee));
             }
             AddRoutees(routees.ToArray());
         })
         .With<Group>(r =>
         {
             var routees = _routerConfig.GetRoutees(this).ToArray();
             AddRoutees(routees);
         });
 }
Пример #17
0
 /// <summary>
 ///     Attaches a MessageDispatcher to the Mailbox.
 /// </summary>
 /// <param name="dispatcher">The dispatcher.</param>
 public void Setup(MessageDispatcher dispatcher)
 {
     this.dispatcher = dispatcher;
 }
Пример #18
0
 public ShutdownAction(MessageDispatcher dispatcher)
 {
     _dispatcher = dispatcher;
 }
Пример #19
0
 public UnbatchedExecute(MessageDispatcher dispatcher, IRunnable runnable)
 {
     _dispatcher = dispatcher;
     _runnable   = runnable;
 }
Пример #20
0
 public UnbatchedExecute(MessageDispatcher dispatcher, IRunnable runnable)
 {
     _dispatcher = dispatcher;
     _runnable = runnable;
 }
Пример #21
0
 public void Run()
 {
     try
     {
         _runnable.Run();
     }
     finally
     {
         if(_dispatcher.AddInhabitants(-1L) == 0)
             _dispatcher.IfSensibleToDoSoThenScheduleShutdown();
         _dispatcher = null;
         _runnable = null;
     }
 }
Пример #22
0
 private InternalTestActorRef(ActorSystem system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, IInternalActorRef supervisor, ActorPath path) //TODO: switch from  Func<Mailbox> createMailbox to MailboxType mailboxType      
     : base(system, props, dispatcher, createMailbox, supervisor, path, actorRef => NewActorCell(system, actorRef, props, dispatcher, supervisor, createMailbox))
 {
 }
Пример #23
0
 /// <summary>Initializes a new instance of the <see cref="Dispatchers" /> class.</summary>
 /// <param name="system">The system.</param>
 /// <param name="prerequisites">The prerequisites required for some <see cref="MessageDispatcherConfigurator"/> instances.</param>
 public Dispatchers(ActorSystem system, IDispatcherPrerequisites prerequisites)
 {
     _system = system;
     Prerequisites = prerequisites;
     _cachingConfig = new CachingConfig(prerequisites.Settings.Config);
     _defaultGlobalDispatcher = Lookup(DefaultDispatcherId);
 }
Пример #24
0
 /// <summary>
 ///     Attaches a MessageDispatcher to the Mailbox.
 /// </summary>
 /// <param name="dispatcher">The dispatcher.</param>
 public void Setup(MessageDispatcher dispatcher)
 {
     this.dispatcher = dispatcher;
 }
 public RootGuardianActorRef_Tests()
 {
     _dispatcher = Sys.Dispatchers.Lookup(CallingThreadDispatcher.Id);
 }
Пример #26
0
 /// <summary>Initializes a new instance of the <see cref="Dispatchers" /> class.</summary>
 /// <param name="system">The system.</param>
 public Dispatchers(ActorSystem system)
 {
     _system = system;
     _defaultGlobalDispatcher = FromConfig(DefaultDispatcherId);
 }
Пример #27
0
 /// <summary>Initializes a new instance of the <see cref="Dispatchers" /> class.</summary>
 /// <param name="system">The system.</param>
 public Dispatchers(ActorSystem system)
 {
     _system = system;
     _defaultGlobalDispatcher = FromConfig(DefaultDispatcherId);
 }
Пример #28
0
 public TestActorCell(ActorSystemImpl system, IInternalActorRef self, Props props, MessageDispatcher dispatcher, IInternalActorRef parent)
     : base(system, self, props, dispatcher, parent)
 {
 }
Пример #29
0
 protected override ActorCell NewActorCell(ActorSystemImpl system, IInternalActorRef self, Props props, MessageDispatcher dispatcher,
     IInternalActorRef supervisor)
 {
     return new TestActorCell((ActorSystemImpl)system, self, props, dispatcher, supervisor);
 }
Пример #30
0
 public ShutdownAction(MessageDispatcher dispatcher)
 {
     _dispatcher = dispatcher;
 }
Пример #31
0
 private InternalTestActorRef(ActorSystemImpl system, Props props, MessageDispatcher dispatcher, MailboxType mailboxType, IInternalActorRef supervisor, ActorPath path)
     : base(system, props, dispatcher, mailboxType, supervisor, path)
 {
 }
Пример #32
0
 /// <summary>
 /// Warms up <see cref="dispatcher"/> prior to the benchmark running,
 /// so we can exclude initialization overhead from the results of the benchmark.
 /// </summary>
 /// <param name="dispatcher">The <see cref="MessageDispatcher"/> implementaiton we'll be testing.</param>
 /// <remarks>Does nothing by default (includes overhead)</remarks>
 protected virtual void Warmup(MessageDispatcher dispatcher)
 {
     
 }
Пример #33
0
        /// <summary>
        /// Used to configure and produce <see cref="Dispatcher"/> instances for use with actors.
        /// </summary>
        /// <param name="config">The configuration for this dispatcher.</param>
        /// <param name="prerequisites">System pre-reqs needed to run this dispatcher.</param>
        public DispatcherConfigurator(Config config, IDispatcherPrerequisites prerequisites)
            : base(config, prerequisites)
        {
            // Need to see if a non-zero value is available for this setting
            TimeSpan deadlineTime = config.GetTimeSpan("throughput-deadline-time");
            long? deadlineTimeTicks = null;
            if (deadlineTime.Ticks > 0)
                deadlineTimeTicks = deadlineTime.Ticks;

            _instance = new Dispatcher(this, config.GetString("id"), 
                config.GetInt("throughput"),
                deadlineTimeTicks,
                ConfigureExecutor(),
                config.GetTimeSpan("shutdown-timeout"));
        }
Пример #34
0
 protected static ActorCell NewActorCell(ActorSystem system, LocalActorRef actorRef, Props props, MessageDispatcher dispatcher, IInternalActorRef supervisor, Func<Mailbox> createMailbox)
 {
     var cell = new TestActorCell((ActorSystemImpl)system, actorRef, props, dispatcher, supervisor);
     cell.Init(sendSupervise: true, createMailbox: createMailbox);
     return cell;
 }