Class responsible for pushing messages from an actor's mailbox into its receive methods. Comes in many different flavors.
Example #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;
 }
Example #2
0
 public ActorCell(ActorSystemImpl system, InternalActorRef self, Props props, MessageDispatcher dispatcher, InternalActorRef parent)
 {
     _self = self;
     _props = props;
     _systemImpl = system;
     Parent = parent;
     Dispatcher = dispatcher;            
 }
 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;
 }
 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);
 }
 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;
 }
Example #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);
 }
Example #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

        }
        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();
        }
Example #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;
 }
Example #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);
 }
Example #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);
 }
Example #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();
        }
Example #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);
        }
Example #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);
         });
 }
Example #17
0
 /// <summary>
 ///     Attaches a MessageDispatcher to the Mailbox.
 /// </summary>
 /// <param name="dispatcher">The dispatcher.</param>
 public void Setup(MessageDispatcher dispatcher)
 {
     this.dispatcher = dispatcher;
 }
Example #18
0
 public ShutdownAction(MessageDispatcher dispatcher)
 {
     _dispatcher = dispatcher;
 }
Example #19
0
 public UnbatchedExecute(MessageDispatcher dispatcher, IRunnable runnable)
 {
     _dispatcher = dispatcher;
     _runnable   = runnable;
 }
Example #20
0
 public UnbatchedExecute(MessageDispatcher dispatcher, IRunnable runnable)
 {
     _dispatcher = dispatcher;
     _runnable = runnable;
 }
Example #21
0
 public void Run()
 {
     try
     {
         _runnable.Run();
     }
     finally
     {
         if(_dispatcher.AddInhabitants(-1L) == 0)
             _dispatcher.IfSensibleToDoSoThenScheduleShutdown();
         _dispatcher = null;
         _runnable = null;
     }
 }
 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))
 {
 }
Example #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);
 }
Example #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);
 }
Example #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);
 }
Example #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);
 }
 public TestActorCell(ActorSystemImpl system, IInternalActorRef self, Props props, MessageDispatcher dispatcher, IInternalActorRef parent)
     : base(system, self, props, dispatcher, parent)
 {
 }
 protected override ActorCell NewActorCell(ActorSystemImpl system, IInternalActorRef self, Props props, MessageDispatcher dispatcher,
     IInternalActorRef supervisor)
 {
     return new TestActorCell((ActorSystemImpl)system, self, props, dispatcher, supervisor);
 }
Example #30
0
 public ShutdownAction(MessageDispatcher dispatcher)
 {
     _dispatcher = dispatcher;
 }
 private InternalTestActorRef(ActorSystemImpl system, Props props, MessageDispatcher dispatcher, MailboxType mailboxType, IInternalActorRef supervisor, ActorPath path)
     : base(system, props, dispatcher, mailboxType, supervisor, path)
 {
 }
Example #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)
 {
     
 }
Example #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"));
        }
 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;
 }