示例#1
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="name">TBD</param>
 /// <param name="child">TBD</param>
 /// <returns>TBD</returns>
 public bool TryGetSingleChild(string name, out IInternalActorRef child)
 {
     if (name.IndexOf('#') < 0)
     {
         // optimization for the non-uid case
         ChildRestartStats stats;
         if (TryGetChildRestartStatsByName(name, out stats))
         {
             child = stats.Child;
             return(true);
         }
     }
     else
     {
         var nameAndUid = SplitNameAndUid(name);
         ChildRestartStats stats;
         if (TryGetChildRestartStatsByName(nameAndUid.Name, out stats))
         {
             var uid = nameAndUid.Uid;
             if (uid == ActorCell.UndefinedUid || uid == stats.Uid)
             {
                 child = stats.Child;
                 return(true);
             }
         }
     }
     child = ActorRefs.Nobody;
     return(false);
 }
        /// <summary>
        /// Initialized SimulationActorRefs when necessary and LocalActorRefs otherwise.
        /// </summary>
        /// <param name="system"></param>
        /// <param name="props"></param>
        /// <param name="supervisor"></param>
        /// <param name="path"></param>
        /// <param name="systemService"></param>
        /// <param name="deploy"></param>
        /// <param name="lookupDeploy"></param>
        /// <param name="async"></param>
        /// <returns></returns>
        public IInternalActorRef ActorOf(ActorSystemImpl system, Props props, IInternalActorRef supervisor, ActorPath path,
                                         bool systemService, Deploy deploy, bool lookupDeploy, bool async)
        {
            // TODO: This should definitely be moved somewhere else.
            if (!system.Dispatchers.HasDispatcher(CallingThreadDispatcher.Id))
            {
                system.Dispatchers.RegisterConfigurator(
                    CallingThreadDispatcher.Id,
                    new CallingThreadDispatcherConfigurator(system.Settings.Config, system.Dispatchers.Prerequisites)
                    );
            }

            // If the instance that needs to be created is
            // - a SystemService
            // - or a Router
            // just return a regular LocalActorRef, because
            // we currently do not render messages sent to the router or system messages.
            if (systemService || !(props.Deploy.RouterConfig is NoRouter))
            {
                return(_localActorRefProvider.ActorOf(system, props.WithDispatcher(CallingThreadDispatcher.Id), supervisor, path, systemService, deploy, lookupDeploy, async));
            }

            // Create dispatchers and mailboxes according to the configurations.
            var dispatcher  = system.Dispatchers.Lookup(CallingThreadDispatcher.Id);
            var mailboxType = system.Mailboxes.GetMailboxType(props, dispatcher.Configurator.Config);

            return(new SimulationActorRef(SimulationMessageDelegate, system, props, dispatcher, mailboxType, supervisor, path));
        }
示例#3
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)
        //      ...
        //    }
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="system">TBD</param>
        /// <param name="props">TBD</param>
        /// <param name="dispatcher">TBD</param>
        /// <param name="mailboxType">TBD</param>
        /// <param name="supervisor">TBD</param>
        /// <param name="path">TBD</param>
        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 VirtualMemberCallInConstructor
            _cell = NewActorCell(_system, this, _props, _dispatcher,
                                 _supervisor); // _cell needs to be assigned before Init is called.
            _cell.Init(true, MailboxType);
        }
        public void UseActorOnNode(RemoteActorRef actor, Props props, Deploy deploy, IInternalActorRef supervisor)
        {
            _log.Debug("[{0}] Instantiating Remote Actor [{1}]", RootPath, actor.Path);
            IActorRef remoteNode = ResolveActorRef(new RootActorPath(actor.Path.Address) / "remote");

            remoteNode.Tell(new DaemonMsgCreate(props, deploy, actor.Path.ToSerializationFormat(), supervisor));
        }
示例#5
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="watchee">TBD</param>
 protected override void WatchNode(IInternalActorRef watchee)
 {
     if (!_clusterNodes.Contains(watchee.Path.Address))
     {
         base.WatchNode(watchee);
     }
 }
示例#6
0
        /// <summary>
        /// This should only be used privately or when creating the root actor.
        /// </summary>
        /// <param name="actor">TBD</param>
        /// <returns>TBD</returns>
        public ChildRestartStats InitChild(IInternalActorRef actor)
        {
            var name = actor.Path.Name;

            while (true)
            {
                var cc = ChildrenContainer;
                if (cc.TryGetByName(name, out var old))
                {
                    switch (old)
                    {
                    case ChildRestartStats restartStats:
                        return(restartStats);

                    case ChildNameReserved _:
                        var crs = new ChildRestartStats(actor);
                        if (SwapChildrenRefs(cc, cc.Add(name, crs)))
                        {
                            return(crs);
                        }
                        break;
                    }
                }
                else
                {
                    return(null);
                }
            }
        }
示例#7
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="watchee">TBD</param>
        /// <param name="watcher">TBD</param>
        /// <exception cref="InvalidOperationException">TBD</exception>
        protected void AddWatching(IInternalActorRef watchee, IInternalActorRef watcher)
        {
            // TODO: replace with Code Contracts assertion
            if (watcher.Equals(Self))
            {
                throw new InvalidOperationException("Watcher cannot be the RemoteWatcher!");
            }
            Log.Debug("Watching: [{0} -> {1}]", watcher.Path, watchee.Path);

            HashSet <IInternalActorRef> watching;

            if (Watching.TryGetValue(watchee, out watching))
            {
                watching.Add(watcher);
            }
            else
            {
                Watching.Add(watchee, new HashSet <IInternalActorRef> {
                    watcher
                });
            }
            WatchNode(watchee);

            // add watch from self, this will actually send a Watch to the target when necessary
            Context.Watch(watchee);
        }
示例#8
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;
 }
示例#9
0
 private void SendTerminated(bool ifLocal, IInternalActorRef watcher)
 {
     if (((IActorRefScope)watcher).IsLocal == ifLocal && !watcher.Equals(Parent))
     {
         watcher.SendSystemMessage(new DeathWatchNotification(Self, true, false));
     }
 }
示例#10
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="provider">TBD</param>
 /// <param name="path">TBD</param>
 /// <param name="parent">TBD</param>
 /// <param name="log">TBD</param>
 public VirtualPathContainer(IActorRefProvider provider, ActorPath path, IInternalActorRef parent, ILoggingAdapter log)
 {
     _parent   = parent;
     _log      = log;
     _provider = provider;
     _path     = path;
 }
 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;
 }
示例#12
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="system">TBD</param>
 /// <param name="props">TBD</param>
 /// <param name="dispatcher">TBD</param>
 /// <param name="mailboxType">TBD</param>
 /// <param name="supervisor">TBD</param>
 /// <param name="path">TBD</param>
 /// <param name="deadLetters">TBD</param>
 /// <param name="extraNames">TBD</param>
 public RootGuardianActorRef(ActorSystemImpl system, Props props, MessageDispatcher dispatcher, MailboxType mailboxType,
                             IInternalActorRef supervisor, ActorPath path, IInternalActorRef deadLetters, IReadOnlyDictionary <string, IInternalActorRef> extraNames)
     : base(system, props, dispatcher, mailboxType, supervisor, path)
 {
     _deadLetters = deadLetters;
     _extraNames  = extraNames;
 }
示例#13
0
 /// <summary>
 /// This should only be used privately or when creating the root actor.
 /// </summary>
 /// <param name="actor">TBD</param>
 /// <returns>TBD</returns>
 public ChildRestartStats InitChild(IInternalActorRef actor)
 {
     return(UpdateChildrenRefs(cc =>
     {
         IChildStats stats;
         var name = actor.Path.Name;
         if (cc.TryGetByName(name, out stats))
         {
             var old = stats as ChildRestartStats;
             if (old != null)
             {
                 //Do not update. Return old
                 return new Tuple <bool, IChildrenContainer, ChildRestartStats>(false, cc, old);
             }
             if (stats is ChildNameReserved)
             {
                 var crs = new ChildRestartStats(actor);
                 var updatedContainer = cc.Add(name, crs);
                 //Update (if it's still cc) and return the new crs
                 return new Tuple <bool, IChildrenContainer, ChildRestartStats>(true, updatedContainer, crs);
             }
         }
         //Do not update. Return null
         return new Tuple <bool, IChildrenContainer, ChildRestartStats>(false, cc, null);
     }));
 }
示例#14
0
        private void RemoveWatcher(IInternalActorRef watchee, IInternalActorRef watcher)
        {
            while (true)
            {
                var watchedBy = Volatile.Read(ref _watchedBy);
                if (watchedBy == null)
                {
                    SendTerminated(watcher);
                }
                else
                {
                    var watcheeSelf = Equals(watchee, this);
                    var watcherSelf = Equals(watcher, this);

                    if (watcheeSelf && !watcherSelf)
                    {
                        if (!watchedBy.Contains(watcher) && !ReferenceEquals(watchedBy, Interlocked.CompareExchange(ref _watchedBy, watchedBy.Remove(watcher), watchedBy)))
                        {
                            continue;
                        }
                    }
                    else if (!watcheeSelf && watcherSelf)
                    {
                        Publish(new Warning(Path.ToString(), typeof(FunctionRef), $"Externally triggered watch from {watcher} to {watchee} is illegal on FunctionRef"));
                    }
                    else
                    {
                        Publish(new Warning(Path.ToString(), typeof(FunctionRef), $"BUG: illegal Watch({watchee},{watcher}) for {this}"));
                    }
                }

                break;
            }
        }
示例#15
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="RemoteSystemDaemon" /> class.
 /// </summary>
 /// <param name="system">The system.</param>
 /// <param name="path">The path.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="terminator"></param>
 /// <param name="log"></param>
 public RemoteSystemDaemon(ActorSystemImpl system, ActorPath path, IInternalActorRef parent, IActorRef terminator, ILoggingAdapter log)
     : base(system.Provider, path, parent, log)
 {
     _terminator = terminator;
     _system     = system;
     AddressTerminatedTopic.Get(system).Subscribe(this);
 }
示例#16
0
 public Message(IInternalActorRef recipient, Address recipientAddress, SerializedMessage serializedMessage, IActorRef senderOptional = null, SeqNo seq = null)
 {
     Seq               = seq;
     SenderOptional    = senderOptional;
     SerializedMessage = serializedMessage;
     RecipientAddress  = recipientAddress;
     Recipient         = recipient;
 }
示例#17
0
 public DefaultMessageDispatcher(ActorSystem system, RemoteActorRefProvider provider, ILoggingAdapter log)
 {
     this.system = system;
     this.provider = provider;
     this.log = log;
     remoteDaemon = provider.RemoteDaemon;
     settings = provider.RemoteSettings;
 }
示例#18
0
 public void RegisterTempActor(IInternalActorRef actorRef, ActorPath path)
 {
     if (path.Parent != _tempNode)
     {
         throw new Exception("Cannot RegisterTempActor() with anything not obtained from tempPath()");
     }
     _tempContainer.AddChild(path.Name, actorRef);
 }
示例#19
0
 public void AddChild(string name, IInternalActorRef actor)
 {
     _children.AddOrUpdate(name, actor, (k, v) =>
     {
         //TODO:  log.debug("{} replacing child {} ({} -> {})", path, name, old, ref)
         return(v);
     });
 }
示例#20
0
 public void AddChild(string name, IInternalActorRef actor)
 {
     _children.AddOrUpdate(name, actor, (k, v) =>
     {
         Log.Warning("{0} replacing child {1} ({2} -> {3})", name, actor, v, actor);
         return(v);
     });
 }
示例#21
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="system">TBD</param>
 /// <param name="self">TBD</param>
 /// <param name="props">TBD</param>
 /// <param name="supervisor">TBD</param>
 public UnstartedCell(ActorSystemImpl system, RepointableActorRef self, Props props, IInternalActorRef supervisor)
 {
     _system     = system;
     _self       = self;
     _props      = props;
     _supervisor = supervisor;
     _timeout    = _system.Settings.UnstartedPushTimeout;
 }
示例#22
0
 public Message(IInternalActorRef recipient, Address recipientAddress, SerializedMessage serializedMessage, IActorRef senderOptional = null, SeqNo seq = null)
 {
     Seq = seq;
     SenderOptional = senderOptional;
     SerializedMessage = serializedMessage;
     RecipientAddress = recipientAddress;
     Recipient = recipient;
 }
示例#23
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="system">TBD</param>
 /// <param name="self">TBD</param>
 /// <param name="props">TBD</param>
 /// <param name="dispatcher">TBD</param>
 /// <param name="parent">TBD</param>
 public ActorCell(ActorSystemImpl system, IInternalActorRef self, Props props, MessageDispatcher dispatcher, IInternalActorRef parent)
 {
     _self       = self;
     _props      = props;
     _systemImpl = system;
     Parent      = parent;
     Dispatcher  = dispatcher;
 }
示例#24
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;
 }
示例#25
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="system">TBD</param>
 /// <param name="props">TBD</param>
 /// <param name="dispatcher">TBD</param>
 /// <param name="mailboxType">TBD</param>
 /// <param name="supervisor">TBD</param>
 /// <param name="path">TBD</param>
 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;
 }
示例#26
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;
 }
 public void Setup(BenchmarkContext context)
 {
     _actorSystem   = ActorSystem.Create("MessageDispatcher" + Counter.GetAndIncrement(), RemoteHocon);
     _systemAddress = RARP.For(_actorSystem).Provider.DefaultAddress;
     _inboundMessageDispatcherCounter = context.GetCounter(MessageDispatcherThroughputCounterName);
     _message        = SerializedMessage.CreateBuilder().SetSerializerId(0).SetMessage(ByteString.CopyFromUtf8("foo")).Build();
     _dispatcher     = new DefaultMessageDispatcher(_actorSystem, RARP.For(_actorSystem).Provider, _actorSystem.Log);
     _targetActorRef = new BenchmarkActorRef(_inboundMessageDispatcherCounter, RARP.For(_actorSystem).Provider);
 }
 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;
 }
示例#29
0
 public ActorCell(ActorSystemImpl system, IInternalActorRef self, Props props, MessageDispatcher dispatcher, IInternalActorRef parent)
 {
     _self = self;
     _props = props;
     _systemImpl = system;
     Parent = parent;
     Dispatcher = dispatcher;
     
 }
 public void Setup(BenchmarkContext context)
 {
     _actorSystem = ActorSystem.Create("MessageDispatcher" + Counter.GetAndIncrement(), RemoteHocon);
     _systemAddress = RARP.For(_actorSystem).Provider.DefaultAddress;
     _inboundMessageDispatcherCounter = context.GetCounter(MessageDispatcherThroughputCounterName);
     _message = SerializedMessage.CreateBuilder().SetSerializerId(0).SetMessage(ByteString.CopyFromUtf8("foo")).Build();
     _dispatcher = new DefaultMessageDispatcher(_actorSystem, RARP.For(_actorSystem).Provider, _actorSystem.Log);
     _targetActorRef = new BenchmarkActorRef(_inboundMessageDispatcherCounter, RARP.For(_actorSystem).Provider);
 }
示例#31
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);
 }
示例#32
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);
 }
示例#33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoteActorRef"/> class.
 /// </summary>
 /// <param name="remote">The remote.</param>
 /// <param name="localAddressToUse">The local address to use.</param>
 /// <param name="path">The path.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="props">The props.</param>
 /// <param name="deploy">The deploy.</param>
 internal RemoteActorRef(RemoteTransport remote, Address localAddressToUse, ActorPath path, IInternalActorRef parent,
                         Props props, Deploy deploy)
 {
     Remote            = remote;
     LocalAddressToUse = localAddressToUse;
     _path             = path;
     _parent           = parent;
     _props            = props;
     _deploy           = deploy;
 }
示例#34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoteActorRef"/> class.
 /// </summary>
 /// <param name="remote">The remote.</param>
 /// <param name="localAddressToUse">The local address to use.</param>
 /// <param name="path">The path.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="props">The props.</param>
 /// <param name="deploy">The deploy.</param>
 internal RemoteActorRef(RemoteTransport remote, Address localAddressToUse, ActorPath path, IInternalActorRef parent,
     Props props, Deploy deploy)
 {
     Remote = remote;
     LocalAddressToUse = localAddressToUse;
     _path = path;
     _parent = parent;
     _props = props;
     _deploy = deploy;
 }
        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();
        }
示例#36
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

        }
示例#37
0
 public void Setup(BenchmarkContext context)
 {
     _actorSystem   = ActorSystem.Create("MessageDispatcher" + Counter.GetAndIncrement(), RemoteHocon);
     _systemAddress = RARP.For(_actorSystem).Provider.DefaultAddress;
     _inboundMessageDispatcherCounter = context.GetCounter(MessageDispatcherThroughputCounterName);
     _message = new SerializedMessage {
         SerializerId = 0, Message = ByteString.CopyFromUtf8("foo")
     };
     _dispatcher     = new DefaultMessageDispatcher(_actorSystem.AsInstanceOf <ExtendedActorSystem>(), RARP.For(_actorSystem).Provider, _actorSystem.Log);
     _targetActorRef = new BenchmarkActorRef(_inboundMessageDispatcherCounter, RARP.For(_actorSystem).Provider);
 }
        public void UseActorOnNode(RemoteActorRef actor, Props props, Deploy deploy, IInternalActorRef supervisor)
        {
            Akka.Serialization.Serialization.CurrentTransportInformation = new Information
            {
                System  = _system,
                Address = actor.LocalAddressToUse,
            };
            _log.Debug("[{0}] Instantiating Remote Actor [{1}]", RootPath, actor.Path);
            IActorRef remoteNode = ResolveActorRef(new RootActorPath(actor.Path.Address) / "remote");

            remoteNode.Tell(new DaemonMsgCreate(props, deploy, actor.Path.ToSerializationFormat(), supervisor));
        }
示例#39
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);
 }
示例#40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RoutedActorRef"/> class.
 /// </summary>
 /// <param name="system">TBD</param>
 /// <param name="routerProps">TBD</param>
 /// <param name="routerDispatcher">TBD</param>
 /// <param name="routerMailbox">TBD</param>
 /// <param name="routeeProps">TBD</param>
 /// <param name="supervisor">TBD</param>
 /// <param name="path">TBD</param>
 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);
 }
示例#41
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;
 }
示例#42
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RoutedActorCell"/> class.
 /// </summary>
 /// <param name="system">TBD</param>
 /// <param name="self">TBD</param>
 /// <param name="routerProps">TBD</param>
 /// <param name="dispatcher">TBD</param>
 /// <param name="routeeProps">TBD</param>
 /// <param name="supervisor">TBD</param>
 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;
 }
示例#43
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();
        }
示例#44
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);
 }
示例#45
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);
        }
示例#46
0
 /// <summary>
 /// Higher-level providers (or extensions) might want to register new synthetic
 /// top-level paths for doing special stuff. This is the way to do just that.
 /// Just be careful to complete all this before <see cref="ActorSystem.Start"/> finishes,
 /// or before you start your own auto-spawned actors.
 /// </summary>
 public void RegisterExtraName(string name, IInternalActorRef actor)
 {
     _extraNames.Add(name, actor);
 }
示例#47
0
        public void Dispatch(IInternalActorRef recipient, Address recipientAddress, SerializedMessage message,
            IActorRef senderOption = null)
        {
            var payload = MessageSerializer.Deserialize(system, message);
            Type payloadClass = payload == null ? null : payload.GetType();
            var sender = senderOption ?? system.DeadLetters;
            var originalReceiver = recipient.Path;

            var msgLog = string.Format("RemoteMessage: {0} to {1}<+{2} from {3}", payload, recipient, originalReceiver,
                sender);
            // message is intended for the RemoteDaemon, usually a command to create a remote actor
            if (recipient == remoteDaemon)
            {
                if (settings.UntrustedMode) log.Debug("dropping daemon message in untrusted mode");
                else
                {
                    if (settings.LogReceive) log.Debug("received daemon message [{0}]", msgLog);
                    remoteDaemon.Tell(payload);
                }
            }

            //message is intended for a local recipient
            else if ((recipient is ILocalRef || recipient is RepointableActorRef) && recipient.IsLocal)
            {
                if (settings.LogReceive) log.Debug("received local message [{0}]", msgLog);
                payload.Match()
                    .With<ActorSelectionMessage>(sel =>
                    {
                        var actorPath = "/" + string.Join("/", sel.Elements.Select(x => x.ToString()));
                        if (settings.UntrustedMode
                            && (!settings.TrustedSelectionPaths.Contains(actorPath)
                            || sel.Message is IPossiblyHarmful
                            || recipient != provider.Guardian))
                        {
                            log.Debug(
                                "operating in UntrustedMode, dropping inbound actor selection to [{0}], allow it" +
                                "by adding the path to 'akka.remote.trusted-selection-paths' in configuration",
                                actorPath);
                        }
                        else
                        {
                            //run the receive logic for ActorSelectionMessage here to make sure it is not stuck on busy user actor
                            ActorSelection.DeliverSelection(recipient, sender, sel);
                        }
                    })
                    .With<IPossiblyHarmful>(msg =>
                    {
                        if (settings.UntrustedMode)
                        {
                            log.Debug("operating in UntrustedMode, dropping inbound IPossiblyHarmful message of type {0}", msg.GetType());
                        }
                    })
                    .With<ISystemMessage>(msg => { recipient.Tell(msg); })
                    .Default(msg =>
                    {
                        recipient.Tell(msg, sender);
                    });
            }

            // message is intended for a remote-deployed recipient
            else if ((recipient is IRemoteRef || recipient is RepointableActorRef) && !recipient.IsLocal && !settings.UntrustedMode)
            {
                if (settings.LogReceive) log.Debug("received remote-destined message {0}", msgLog);
                if (provider.Transport.Addresses.Contains(recipientAddress))
                {
                    //if it was originally addressed to us but is in fact remote from our point of view (i.e. remote-deployed)
                    recipient.Tell(payload, sender);
                }
                else
                {
                    log.Error(
                        "Dropping message [{0}] for non-local recipient [{1}] arriving at [{2}] inbound addresses [{3}]",
                        payloadClass, recipient, recipientAddress, string.Join(",", provider.Transport.Addresses));
                }
            }
            else
            {
                log.Error(
                        "Dropping message [{0}] for non-local recipient [{1}] arriving at [{2}] inbound addresses [{3}]",
                        payloadClass, recipient, recipientAddress, string.Join(",", provider.Transport.Addresses));
            }
        }
示例#48
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="RemoteSystemDaemon" /> class.
 /// </summary>
 /// <param name="system">The system.</param>
 /// <param name="path">The path.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="terminator"></param>
 /// <param name="log"></param>
 public RemoteSystemDaemon(ActorSystemImpl system, ActorPath path, IInternalActorRef parent,IActorRef terminator, ILoggingAdapter log)
     : base(system.Provider, path, parent, log)
 {
     _terminator = terminator;
     _system = system;
     AddressTerminatedTopic.Get(system).Subscribe(this);
 }
示例#49
0
 private void SendTerminated(bool ifLocal, IInternalActorRef watcher)
 {
     if (((IActorRefScope)watcher).IsLocal == ifLocal && !watcher.Equals(Parent))
     {
         watcher.SendSystemMessage(new DeathWatchNotification(Self, true, false));
     }
 }
 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))
 {
 }
 public TestActorCell(ActorSystemImpl system, IInternalActorRef self, Props props, MessageDispatcher dispatcher, IInternalActorRef parent)
     : base(system, self, props, dispatcher, parent)
 {
 }
示例#52
0
 public SystemGuardianTests()
 {
     _userGuardian = Sys.ActorOf(Props.Create<GuardianActor>()).AsInstanceOf<IInternalActorRef>();
     _systemGuardian = Sys.ActorOf(Props.Create(() => new SystemGuardianActor(_userGuardian))).AsInstanceOf<IInternalActorRef>();
     _systemGuardian.Tell(new Watch(_userGuardian, _systemGuardian));            
 }
 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;
 }
示例#54
0
 public ChildRestartStats(IInternalActorRef child, uint maxNrOfRetriesCount = 0, long restartTimeWindowStartTicks = 0)
 {
     _child = child;
     _maxNrOfRetriesCount = maxNrOfRetriesCount;
     _restartTimeWindowStartTicks = restartTimeWindowStartTicks;
 }
示例#55
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Unwatch" /> class.
 /// </summary>
 /// <param name="watchee">The watchee.</param>
 /// <param name="watcher">The watcher.</param>
 public Unwatch(IInternalActorRef watchee, IInternalActorRef watcher)
 {
     Watchee = watchee;
     Watcher = watcher;
 }
示例#56
0
        public LocalActorRefProvider(string systemName, Settings settings, EventStream eventStream, Deployer deployer, Func<ActorPath, IInternalActorRef> deadLettersFactory)
        {
            _settings = settings;
            _eventStream = eventStream;
            _deployer = deployer ?? new Deployer(settings);
            _rootPath = new RootActorPath(new Address("akka", systemName));
            _log = Logging.GetLogger(eventStream, "LocalActorRefProvider(" + _rootPath.Address + ")");
            if(deadLettersFactory == null)
                deadLettersFactory = p => new DeadLetterActorRef(this, p, _eventStream);
            _deadLetters = deadLettersFactory(_rootPath / "deadLetters");
            _tempNumber = new AtomicCounterLong(1);
            _tempNode = _rootPath / "temp";

            _systemGuardianStrategy = SupervisorStrategy.DefaultStrategy;
            _userGuardianStrategyConfigurator = SupervisorStrategyConfigurator.CreateConfigurator(Settings.SupervisorStrategyClass);
        }
示例#57
0
 public void RegisterTempActor(IInternalActorRef actorRef, ActorPath path)
 {
     if(path.Parent != _tempNode)
         throw new Exception("Cannot RegisterTempActor() with anything not obtained from tempPath()");
     _tempContainer.AddChild(path.Name, actorRef);
 }
示例#58
0
 public void SetTempContainer(IInternalActorRef tempContainer)
 {
     _tempContainer = tempContainer;
 }
示例#59
0
 internal IInternalActorRef ResolveActorRef(IInternalActorRef actorRef, IReadOnlyCollection<string> pathElements)
 {
     if(pathElements.Count == 0)
     {
         _log.Debug("Resolve of empty path sequence fails (per definition)");
         return _deadLetters;
     }
     var child = actorRef.GetChild(pathElements);
     if(child.IsNobody())
     {
         _log.Debug("Resolve of path sequence [/{0}] failed", ActorPath.FormatPathElements(pathElements));
         return new EmptyLocalActorRef(_system.Provider, actorRef.Path / pathElements, _eventStream);
     }
     return (IInternalActorRef)child;
 }
示例#60
0
        public IInternalActorRef ActorOf(ActorSystemImpl system, Props props, IInternalActorRef supervisor, ActorPath path, bool systemService, Deploy deploy, bool lookupDeploy, bool async)
        {
            if (props.Deploy.RouterConfig.NoRouter())
            {
                if (Settings.DebugRouterMisconfiguration)
                {
                    var d = Deployer.Lookup(path);
                    if (d != null && d.RouterConfig != RouterConfig.NoRouter)
                        Log.Warning("Configuration says that [{0}] should be a router, but code disagrees. Remove the config or add a RouterConfig to its Props.",
                                	path);
                }

                var props2 = props;

                // mailbox and dispatcher defined in deploy should override props
                var propsDeploy = lookupDeploy ? Deployer.Lookup(path) : deploy;
                if (propsDeploy != null)
                {
                    if (propsDeploy.Mailbox != Deploy.NoMailboxGiven)
                        props2 = props2.WithMailbox(propsDeploy.Mailbox);
                    if (propsDeploy.Dispatcher != Deploy.NoDispatcherGiven)
                        props2 = props2.WithDispatcher(propsDeploy.Dispatcher);
                }

                if (!system.Dispatchers.HasDispatcher(props2.Dispatcher))
                {
                    throw new ConfigurationException(string.Format("Dispatcher [{0}] not configured for path {1}", props2.Dispatcher, path));
                }

                try
                {
                    // for consistency we check configuration of dispatcher and mailbox locally
                    var dispatcher = _system.Dispatchers.Lookup(props2.Dispatcher);

                    if (async)
                        return
                            new RepointableActorRef(system, props2, dispatcher,
                                () => _system.Mailboxes.CreateMailbox(props2, dispatcher.Configurator.Config), supervisor,
                                path).Initialize(async);
                    return new LocalActorRef(system, props2, dispatcher,
                        () => _system.Mailboxes.CreateMailbox(props2, dispatcher.Configurator.Config), supervisor, path);
                }
                catch (Exception ex)
                {
                    throw new ConfigurationException(
                        string.Format(
                            "Configuration problem while creating {0} with dispatcher [{1}] and mailbox [{2}]", path,
                            props.Dispatcher, props.Mailbox), ex);
                }
            }
            else //routers!!!
            {
                var lookup = (lookupDeploy ? Deployer.Lookup(path) : null) ?? Deploy.None;
                var fromProps = new List<Deploy>() { props.Deploy, deploy, lookup };
                var d = fromProps.Where(x => x != null).Aggregate((deploy1, deploy2) => deploy2.WithFallback(deploy1));
                var p = props.WithRouter(d.RouterConfig);

      
                if (!system.Dispatchers.HasDispatcher(p.Dispatcher))
                    throw new ConfigurationException(string.Format("Dispatcher [{0}] not configured for routees of path {1}", p.Dispatcher, path));
                if (!system.Dispatchers.HasDispatcher(d.RouterConfig.RouterDispatcher))
                    throw new ConfigurationException(string.Format("Dispatcher [{0}] not configured for router of path {1}", p.RouterConfig.RouterDispatcher, path));

                var routerProps = Props.Empty.WithRouter(p.Deploy.RouterConfig).WithDispatcher(p.RouterConfig.RouterDispatcher);
                var routeeProps = props.WithRouter(RouterConfig.NoRouter);

                try
                {
                    var routerDispatcher = system.Dispatchers.Lookup(p.RouterConfig.RouterDispatcher);
                    var routerMailbox = system.Mailboxes.CreateMailbox(routerProps, routerDispatcher.Configurator.Config);

                    // routers use context.actorOf() to create the routees, which does not allow us to pass
                    // these through, but obtain them here for early verification
                    var routeeDispatcher = system.Dispatchers.Lookup(p.Dispatcher);

                    var routedActorRef = new RoutedActorRef(system, routerProps, routerDispatcher, () => routerMailbox, routeeProps,
                        supervisor, path);
                    routedActorRef.Initialize(async);
                    return routedActorRef;
                }
                catch (Exception)
                {
                    throw new ConfigurationException(string.Format("Configuration problem while creating [{0}] with router dispatcher [{1}] and mailbox {2}" +
                                                                   " and routee dispatcher [{3}] and mailbox [{4}].", path, routerProps.Dispatcher, routerProps.Mailbox,
                                                                   routeeProps.Dispatcher, routeeProps.Mailbox));
                }

            }
        }