Example #1
30
 /// <summary>
 ///     Initializes a new instance of the <see cref="RemoteDaemon" /> class.
 /// </summary>
 /// <param name="system">The system.</param>
 /// <param name="path">The path.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="log"></param>
 public RemoteDaemon(ActorSystemImpl system, ActorPath path, InternalActorRef parent, LoggingAdapter log)
     : base(system.Provider, path, parent, log)
 {
     _system = system;
     AddressTerminatedTopic.Get(system).Subscribe(this);
 }
Example #2
0
        public RoutedActorCell(ActorSystem system, InternalActorRef supervisor, Props routerProps, Props routeeProps, ActorPath path,
            Mailbox mailbox)
            : base(system, supervisor, routerProps, path, mailbox)
        {
            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 = this.ActorOf(RouteeProps);
                        routees.Add(new ActorRefRoutee(routee));
                    }
                    AddRoutees(routees.ToArray());
                })
                .With<Group>(r =>
                {
                    var routees = routerConfig.GetRoutees(this).ToArray();
                    AddRoutees(routees);
                });



            Self = new RoutedActorRef(path, this);
        }
 public RootGuardianActorRef(ActorSystem system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, //TODO: switch from  Func<Mailbox> createMailbox to MailboxType mailboxType
     InternalActorRef supervisor, ActorPath path, InternalActorRef deadLetters, IReadOnlyDictionary<string, InternalActorRef> extraNames)
     : base(system,props,dispatcher,createMailbox,supervisor,path)
 {
     _deadLetters = deadLetters;
     _extraNames = extraNames;
 }
Example #4
0
 public RootGuardianActorRef(ActorSystem system, Props props, MessageDispatcher dispatcher, Func <Mailbox> createMailbox, //TODO: switch from  Func<Mailbox> createMailbox to MailboxType mailboxType
                             InternalActorRef supervisor, ActorPath path, InternalActorRef deadLetters, IReadOnlyDictionary <string, InternalActorRef> extraNames)
     : base(system, props, dispatcher, createMailbox, supervisor, path)
 {
     _deadLetters = deadLetters;
     _extraNames  = extraNames;
 }
Example #5
0
 public Remoting(ActorSystem system, RemoteActorRefProvider provider)
     : base(system, provider)
 {
     log = Logging.GetLogger(system, "remoting");
     _eventPublisher = new EventPublisher(system, log, Logging.LogLevelFor(provider.RemoteSettings.RemoteLifecycleEventsLogLevel));
     _transportSupervisor = system.SystemActorOf(Props.Create<TransportSupervisor>(), "transports");
 }
Example #6
0
        public override void Start()
        {
            log.Info("Starting remoting");

            EndpointManager =
                System.SystemActorOf(
                    Props.Create(() => new EndpointManager(Provider.RemoteSettings, log)).WithDeploy(Deploy.Local),
                    EndpointManagerName);


            Task<object> task = EndpointManager.Ask(new Listen());
            if (!task.Wait(30000))
            {
                throw new RemoteTransportException("Transport loading timed out", null);
            }
            if (task.Result == null)
            {
                throw new RemoteTransportException("No transport drivers were loaded.", null);
            }
            var akkaProtocolTransports = (ProtocolTransportAddressPair[]) task.Result;

            Addresses = new HashSet<Address>(akkaProtocolTransports.Select(a => a.Address));
            //   this.transportMapping = akkaProtocolTransports
            //       .ToDictionary(p => p.ProtocolTransport.Transport.SchemeIdentifier,);
            IEnumerable<IGrouping<string, ProtocolTransportAddressPair>> tmp =
                akkaProtocolTransports.GroupBy(t => t.ProtocolTransport.Transport.SchemeIdentifier);
            transportMapping = new Dictionary<string, HashSet<ProtocolTransportAddressPair>>();
            foreach (var g in tmp)
            {
                var set = new HashSet<ProtocolTransportAddressPair>(g);
                transportMapping.Add(g.Key, set);
            }
        }
Example #7
0
 public void RegisterTempActor(InternalActorRef actorRef, ActorPath path)
 {
     if (path.Parent != _tempNode)
     {
         throw new Exception("Cannot RegisterTempActor() with anything not obtained from tempPath()");
     }
     _tempContainer.AddChild(path.Name, actorRef);
 }
Example #8
0
 public ActorCell(ActorSystemImpl system, InternalActorRef self, Props props, MessageDispatcher dispatcher, InternalActorRef parent)
 {
     _self = self;
     _props = props;
     _systemImpl = system;
     Parent = parent;
     Dispatcher = dispatcher;            
 }
Example #9
0
 public void AddChild(string name, InternalActorRef actor)
 {
     children.AddOrUpdate(name, actor, (k, v) =>
     {
         //TODO:  log.debug("{} replacing child {} ({} -> {})", path, name, old, ref)
         return(v);
     });
 }
Example #10
0
 public Message(InternalActorRef recipient, Address recipientAddress, SerializedMessage serializedMessage, ActorRef senderOptional = null, SeqNo seq = null)
 {
     Seq = seq;
     SenderOptional = senderOptional;
     SerializedMessage = serializedMessage;
     RecipientAddress = recipientAddress;
     Recipient = recipient;
 }
Example #11
0
 public ActorCell(ActorSystemImpl system, InternalActorRef self, Props props, MessageDispatcher dispatcher, InternalActorRef parent)
 {
     _self       = self;
     _props      = props;
     _systemImpl = system;
     Parent      = parent;
     Dispatcher  = dispatcher;
 }
 public UnstartedCell(ActorSystem system, RepointableActorRef self, Props props, InternalActorRef supervisor)
 {
     _system     = system;
     _self       = self;
     _props      = props;
     _supervisor = supervisor;
     _timeout    = _system.Settings.UnstartedPushTimeout;
 }
        /// <summary>
        ///     Actors the of.
        /// </summary>
        /// <param name="system">The system.</param>
        /// <param name="props">The props.</param>
        /// <param name="supervisor">The supervisor.</param>
        /// <param name="path">The path.</param>
        /// <param name="systemService">Is this a child actor under the system guardian?</param>
        /// <returns>InternalActorRef.</returns>
        public override InternalActorRef ActorOf(ActorSystem system, Props props, InternalActorRef supervisor,
                                                 ActorPath path, bool systemService = false)
        {
            ActorCell cell    = null;
            Mailbox   mailbox = System.Mailboxes.FromConfig(props.Mailbox);

            Deploy configDeploy = System.Provider.Deployer.Lookup(path);
            var    deploy       = configDeploy ?? props.Deploy ?? Deploy.None;

            if (deploy.Mailbox != null)
            {
                props = props.WithMailbox(deploy.Mailbox);
            }
            if (deploy.Dispatcher != null)
            {
                props = props.WithDispatcher(deploy.Dispatcher);
            }
            if (deploy.Scope is RemoteScope)
            {
            }

            if (string.IsNullOrEmpty(props.Mailbox))
            {
                //   throw new NotSupportedException("Mailbox can not be configured as null or empty");
            }
            if (string.IsNullOrEmpty(props.Dispatcher))
            {
                //TODO: fix this..
                //    throw new NotSupportedException("Dispatcher can not be configured as null or empty");
            }


            if (props.Deploy != null && props.Deploy.Scope is RemoteScope)
            {
                throw new NotSupportedException("LocalActorRefProvider can not deploy remote");
            }

            if (props.RouterConfig is NoRouter || props.RouterConfig == null)
            {
                props = props.WithDeploy(deploy);
                cell  = new ActorCell(system, supervisor, props, path, mailbox);
            }
            else
            {
                //if no Router config value was specified, override with procedural input
                if (deploy.RouterConfig is NoRouter)
                {
                    deploy = deploy.WithRouterConfig(props.RouterConfig);
                }

                //TODO: make this work for remote actor ref provider
                cell = NewRouterCell(system, supervisor, path, props, mailbox, deploy);
            }
            cell.NewActor();
            //   parentContext.Watch(cell.Self);
            return(cell.Self);
        }
 public RepointableActorRef(ActorSystem system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, InternalActorRef supervisor, ActorPath path)
 {
     _system = system;
     _props = props;
     _dispatcher = dispatcher;
     _createMailbox = createMailbox;
     _supervisor = supervisor;
     _path = path;
 }
 public RepointableActorRef(ActorSystem system, Props props, MessageDispatcher dispatcher, Func <Mailbox> createMailbox, InternalActorRef supervisor, ActorPath path)
 {
     _system        = system;
     _props         = props;
     _dispatcher    = dispatcher;
     _createMailbox = createMailbox;
     _supervisor    = supervisor;
     _path          = path;
 }
Example #16
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, InternalActorRef parent,
     Props props, Deploy deploy)
 {
     Remote = remote;
     LocalAddressToUse = localAddressToUse;
     Path = path;
     _parent = parent;
     _props = props;
     _deploy = deploy;
 }
Example #17
0
 /// <summary>
 /// Inheritors should only call this constructor
 /// </summary>
 internal protected LocalActorRef(ActorSystem system, Props props, MessageDispatcher dispatcher, Func <Mailbox> createMailbox, InternalActorRef 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 #18
0
 /// <summary>
 /// Inheritors should only call this constructor
 /// </summary>
 internal protected  LocalActorRef(ActorSystem system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, InternalActorRef 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 #19
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, InternalActorRef 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

        }
Example #20
0
 public ActorCell(ActorSystem system, InternalActorRef supervisor, Props props, ActorPath path, Mailbox mailbox)
 {
     Parent     = supervisor;
     System     = system;
     Self       = new LocalActorRef(path, this);
     Props      = props;
     Dispatcher = System.Dispatchers.FromConfig(props.Dispatcher);
     mailbox.Setup(Dispatcher);
     Mailbox           = mailbox;
     Mailbox.ActorCell = this;
 }
Example #21
0
        public ResizablePoolCell(ActorSystem system, InternalActorRef supervisor, Props routerProps,
            Props routeeProps, ActorPath path, Mailbox mailbox, Pool pool)
            : base(system, supervisor, routerProps, routeeProps, path, mailbox)
        {
            if (pool.Resizer == null)
                throw new ArgumentException("RouterConfig must be a Pool with defined resizer");

            resizer = pool.Resizer;
            this._pool = pool;
            this._resizeCounter = 0;
            this._resizeInProgress = ResizeInProgressState.False;
        }
        public ResizablePoolCell(ActorSystemImpl system, InternalActorRef self, Props routerProps, MessageDispatcher dispatcher, Props routeeProps, InternalActorRef 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 = ResizeInProgressState.False;
        }
Example #23
0
        /// <summary>
        ///     Starts this instance.
        /// </summary>
        private void Start()
        {
            if (Settings.LogDeadLetters > 0)
            {
                _logDeadLetterListener = SystemActorOf <DeadLetterListener>("deadLetterListener");
            }


            if (Settings.LogConfigOnStart)
            {
                Log.Warn(Settings.ToString());
            }
        }
Example #24
0
        private ActorRef ResolveActorRef(InternalActorRef 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(child);
        }
        /// <summary>
        ///     Stops the specified child.
        /// </summary>
        /// <param name="child">The child.</param>
        public void Stop(InternalActorRef child)
        {
            //TODO: in akka this does some wild magic on childrefs and then just call child.stop();

            //ignore this for now
            //if (Children.ContainsKey(child.Path.Name))
            //{
            //    child.Cell.Become(System.DeadLetters.Tell);
            //    LocalActorRef tmp;
            //    var name = child.Path.Name;
            //    this.Children.TryRemove(name, out tmp);
            //    Publish(new Pigeon.Event.Debug(Self.Path.ToString(), Actor.GetType(), string.Format("Child Actor {0} stopped - no longer supervising", child.Path)));
            //}

            child.Stop();
        }
        /// <summary>
        ///     Stops the specified child.
        /// </summary>
        /// <param name="child">The child.</param>
        public void Stop(InternalActorRef child)
        {
            //TODO: in akka this does some wild magic on childrefs and then just call child.stop();

            //ignore this for now
            //if (Children.ContainsKey(child.Path.Name))
            //{
            //    child.Cell.Become(System.DeadLetters.Tell);
            //    LocalActorRef tmp;
            //    var name = child.Path.Name;
            //    this.Children.TryRemove(name, out tmp);
            //    Publish(new Pigeon.Event.Debug(Self.Path.ToString(), Actor.GetType(), string.Format("Child Actor {0} stopped - no longer supervising", child.Path)));
            //}

            child.Stop();
        }
        //TODO: real akka does this in the RoutedActorRef
        //Keep this here for now?
        public static ActorCell NewRouterCell(ActorSystem system, InternalActorRef supervisor, ActorPath path, Props props, Mailbox mailbox, Deploy deploy)
        {
            var routerProps = Props.Empty.WithDeploy(deploy);
            var routeeProps = props.WithRouter(RouterConfig.NoRouter);

            if (routerProps.RouterConfig is Pool)
            {
                var p = routerProps.RouterConfig.AsInstanceOf <Pool>();
                if (p.Resizer != null)
                {
                    //if there is a resizer, use ResizablePoolCell
                    return(new ResizablePoolCell(system, supervisor, routerProps, routeeProps, path, mailbox, p));
                }
            }
            //Use RoutedActorCell for all other routers
            return(new RoutedActorCell(system, supervisor, routerProps, routeeProps, path, mailbox));
        }
        public LocalActorRefProvider(string systemName, Settings settings, EventStream eventStream, Deployer deployer, Func<ActorPath, InternalActorRef> 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";

            //TODO: _guardianSupervisorStrategyConfigurator = dynamicAccess.createInstanceFor[SupervisorStrategyConfigurator](settings.SupervisorStrategyClass, EmptyImmutableSeq).get
            _systemGuardianStrategy = SupervisorStrategy.DefaultStrategy;

        }
        public override InternalActorRef ActorOf(ActorSystem system, Props props, InternalActorRef supervisor,
            ActorPath path)
        {
            Mailbox mailbox = System.Mailboxes.FromConfig(props.Mailbox);

            Deploy configDeploy = System.Provider.Deployer.Lookup(path);
            var deploy = configDeploy ?? props.Deploy ?? Deploy.None;
            if (deploy.Mailbox != null)
                props = props.WithMailbox(deploy.Mailbox);
            if (deploy.Dispatcher != null)
                props = props.WithDispatcher(deploy.Dispatcher);
            if (deploy.Scope is RemoteScope)
            {

            }

            //If this actor is a Router
            if (!(props.RouterConfig is NoRouter || props.RouterConfig == null))
            {
                //if no Router config value was specified, override with procedural input
                if (deploy.RouterConfig is NoRouter)
                {
                    deploy = deploy.WithRouterConfig(props.RouterConfig);
                }
            }
            props = props.WithDeploy(deploy);
            

            if (string.IsNullOrEmpty(props.Mailbox))
            {
                //   throw new NotSupportedException("Mailbox can not be configured as null or empty");
            }
            if (string.IsNullOrEmpty(props.Dispatcher))
            {
                //TODO: fix this..
                //    throw new NotSupportedException("Dispatcher can not be configured as null or empty");
            }


            if (props.Deploy != null && props.Deploy.Scope is RemoteScope)
            {
                return RemoteActorOf(system, props, supervisor, path, mailbox);
            }
            return LocalActorOf(system, props, supervisor, path, mailbox);
        }
Example #30
0
        public LocalActorRefProvider(string systemName, Settings settings, EventStream eventStream, Deployer deployer, Func <ActorPath, InternalActorRef> 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";

            //TODO: _guardianSupervisorStrategyConfigurator = dynamicAccess.createInstanceFor[SupervisorStrategyConfigurator](settings.SupervisorStrategyClass, EmptyImmutableSeq).get
            _systemGuardianStrategy = SupervisorStrategy.DefaultStrategy;
        }
Example #31
0
 public RoutedActorRef(ActorSystem system, Props routerProps, MessageDispatcher routerDispatcher,
     Func<Mailbox> createMailbox, Props routeeProps, InternalActorRef 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);
 }
Example #32
0
        private InternalActorRef CreateNoRouter(ActorSystemImpl system, Props props, InternalActorRef supervisor, ActorPath path,
                                                Deploy deploy, bool async)
        {
            if (props.Deploy != deploy)
            {
                props = props.WithDeploy(deploy);
            }
            var dispatcher = system.Dispatchers.FromConfig(props.Dispatcher);
            var mailbox    = _system.Mailboxes.CreateMailbox(props, null /*dispatcher.Configurator.Config*/);

            //TODO: Should be: system.mailboxes.getMailboxType(props2, dispatcher.configurator.config)
            if (async)
            {
                var reActorRef = new RepointableActorRef(system, props, dispatcher, () => mailbox, supervisor, path);
                reActorRef.Initialize(async: true);
                return(reActorRef);
            }
            return(new LocalActorRef(system, props, dispatcher, () => mailbox, supervisor, path));
        }
Example #33
0
        /*
         * override def getChild(name: Iterator[String]): InternalActorRef = {
         * if (name.isEmpty) this
         * else {
         * val n = name.next()
         * if (n.isEmpty) this
         * else children.get(n) match {
         * case null ⇒ Nobody
         * case some ⇒
         * if (name.isEmpty) some
         * else some.getChild(name)
         * }
         * }
         * }
         */

        public override ActorRef GetChild(IEnumerable <string> name)
        {
            //TODO: I have no clue what the scala version does
            if (!name.Any())
            {
                return(this);
            }

            string n = name.First();

            if (string.IsNullOrEmpty(n))
            {
                return(this);
            }
            InternalActorRef c = children[n];

            if (c == null)
            {
                return(Nobody);
            }
            return(c.GetChild(name.Skip(1)));
        }
Example #34
0
        private InternalActorRef MakeChild(Props props, string name)
        {
            long childUid = NewUid();

            name = GetActorName(name, childUid);
            //reserve the name before we create the actor
            ReserveChild(name);
            try
            {
                ActorPath        childPath = (Self.Path / name).WithUid(childUid);
                InternalActorRef actor     = System.Provider.ActorOf(System, props, Self, childPath);
                //replace the reservation with the real actor
                InitChild(name, actor);
                return(actor);
            }
            catch
            {
                //if actor creation failed, unreserve the name
                UnreserveChild(name);
                throw;
            }
        }
Example #35
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 #36
0
 protected bool TryGetChild(string name, out InternalActorRef child)
 {
     return(_children.TryGetValue(name, out child));
 }
Example #37
0
 public Rewatch(InternalActorRef watchee, InternalActorRef watcher)
     : base(watchee, watcher)
 {
 }
Example #38
0
 /// <summary>This should only be used privately or when creating the root actor. </summary>
 public void InitChild(InternalActorRef actor)
 {
     children.TryUpdate(actor.Path.Name, actor, ActorRef.Reserved);
 }
Example #39
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, InternalActorRef actor)
 {
     _extraNames.Add(name, actor);
 }
Example #40
0
 /// <summary>This should only be used privately or when creating the root actor. </summary>
 public void InitChild(InternalActorRef actor)
 {
     children.TryUpdate(actor.Path.Name, actor, ActorRef.Reserved);
 }
Example #41
0
        public override Task Shutdown()
        {
            if (_endpointManager == null)
            {
                log.Warn("Remoting is not running. Ignoring shutdown attempt");
                return Task.Run(() => { });
            }
            else
            {
                var timeout = Provider.RemoteSettings.ShutdownTimeout;
                Action finalize = () =>
                {
                    _eventPublisher.NotifyListeners(new RemotingShutdownEvent());
                    _endpointManager = null;
                };

                return _endpointManager.Ask<bool>(new EndpointManager.ShutdownAndFlush(), timeout).ContinueWith(result =>
                {
                    if (result.IsFaulted || result.IsCanceled) //Shutdown was not successful
                    {
                        NotifyError("Failure during shutdown of remoting", result.Exception);
                        finalize();
                    }
                    else
                    {
                        if (!result.Result)
                        {
                            log.Warn(
                                "Shutdown finished, but flushing might not have been successful and some messages might have been dropped. " +
                                "Increase akka.remote.flush-wait-on-shutdown to a larger value to avoid this.");
                        }
                        finalize();
                    }
                }, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.AttachedToParent);
            }
        }
Example #42
0
        private InternalActorRef CreateWithRouter(ActorSystemImpl system, Props props, InternalActorRef supervisor,
                                                  ActorPath path, Deploy deploy, bool async)
        {
            //if no Router config value was specified, override with procedural input
            if (deploy.RouterConfig.NoRouter())
            {
                deploy = deploy.WithRouterConfig(props.RouterConfig);
            }

            var routerDispatcher = system.Dispatchers.FromConfig(props.RouterConfig.RouterDispatcher);
            var routerMailbox    = _system.Mailboxes.CreateMailbox(props, null);
            //TODO: Should be val routerMailbox = system.mailboxes.getMailboxType(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 routerProps = Props.Empty.WithDeploy(deploy);
            var routeeProps = props.WithRouter(RouterConfig.NoRouter);

            var routedActorRef = new RoutedActorRef(system, routerProps, routerDispatcher, () => routerMailbox, routeeProps,
                                                    supervisor, path);

            routedActorRef.Initialize(async);
            return(routedActorRef);
        }
Example #43
0
        /// <summary>
        ///     Actors the of.
        /// </summary>
        /// <param name="system">The system.</param>
        /// <param name="props">The props.</param>
        /// <param name="supervisor">The supervisor.</param>
        /// <param name="path">The path.</param>
        /// <returns>InternalActorRef.</returns>
        public override InternalActorRef ActorOf(ActorSystem system, Props props, InternalActorRef supervisor,
            ActorPath path)
        {
            ActorCell cell = null;
            Mailbox mailbox = System.Mailboxes.FromConfig(props.Mailbox);

            Deploy configDeploy = System.Provider.Deployer.Lookup(path);
            var deploy = configDeploy ?? props.Deploy ?? Deploy.None;
            if (deploy.Mailbox != null)
                props = props.WithMailbox(deploy.Mailbox);
            if (deploy.Dispatcher != null)
                props = props.WithDispatcher(deploy.Dispatcher);
            if (deploy.Scope is RemoteScope)
            {

            }

            if (string.IsNullOrEmpty(props.Mailbox))
            {
                //   throw new NotSupportedException("Mailbox can not be configured as null or empty");
            }
            if (string.IsNullOrEmpty(props.Dispatcher))
            {
                //TODO: fix this..
                //    throw new NotSupportedException("Dispatcher can not be configured as null or empty");
            }


            if (props.Deploy != null && props.Deploy.Scope is RemoteScope)
            {
                throw new NotSupportedException("LocalActorRefProvider can not deploy remote");
            }

            if (props.RouterConfig is NoRouter || props.RouterConfig == null)
            {

                props = props.WithDeploy(deploy);
                cell = new ActorCell(system, supervisor, props, path, mailbox);

            }
            else
            {
                //if no Router config value was specified, override with procedural input
                if (deploy.RouterConfig is NoRouter) 
                {
                    deploy = deploy.WithRouterConfig(props.RouterConfig);
                }

                var routerProps =
                    Props.Create<RouterActor>()
                        .WithDeploy(deploy);

                var routeeProps = props.WithRouter(RouterConfig.NoRouter);

                cell = new RoutedActorCell(system, supervisor, routerProps, routeeProps, path, mailbox);

            }
            cell.NewActor();
            //   parentContext.Watch(cell.Self);
            return cell.Self;
        }
 /// <summary>
 ///     Actors the of.
 /// </summary>
 /// <param name="system">The system.</param>
 /// <param name="props">The props.</param>
 /// <param name="supervisor">The supervisor.</param>
 /// <param name="path">The path.</param>
 /// <param name="systemService">Is this a child actor under the system guardian?</param>
 /// <returns>InternalActorRef.</returns>
 public abstract InternalActorRef ActorOf(ActorSystem system, Props props, InternalActorRef supervisor,
                                          ActorPath path, bool systemService = false);
Example #45
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, InternalActorRef actor)
 {
     _extraNames.Add(name, actor);
 }
Example #46
0
        /// <summary>
        /// INTERNAL API
        ///
        /// Convenience method used by remoting when receiving <see cref="ActorSelectionMessage"/> from a remote
        /// actor.
        /// </summary>
        internal static void DeliverSelection(InternalActorRef anchor, ActorRef sender, ActorSelectionMessage sel)
        {
            var actorSelection = new ActorSelection(anchor, sel.Elements);

            actorSelection.Tell(sel.Message, sender);
        }
Example #47
0
        public override void Start()
        {
            log.Info("Starting remoting");

            if (_endpointManager == null)
            {
                _endpointManager =
                System.SystemActorOf(
                    Props.Create(() => new EndpointManager(Provider.Config, log)).WithDeploy(Deploy.Local),
                    EndpointManagerName);

                try
                {
                    var addressPromise = new TaskCompletionSource<IList<ProtocolTransportAddressPair>>();
                    _endpointManager.Tell(new EndpointManager.Listen(addressPromise));

                    addressPromise.Task.Wait(Provider.RemoteSettings.StartupTimeout);
                    var akkaProtocolTransports = addressPromise.Task.Result;

                    Addresses = new HashSet<Address>(akkaProtocolTransports.Select(a => a.Address));
                    //   this.transportMapping = akkaProtocolTransports
                    //       .ToDictionary(p => p.ProtocolTransport.Transport.SchemeIdentifier,);
                    IEnumerable<IGrouping<string, ProtocolTransportAddressPair>> tmp =
                        akkaProtocolTransports.GroupBy(t => t.ProtocolTransport.SchemeIdentifier);
                    _transportMapping = new Dictionary<string, HashSet<ProtocolTransportAddressPair>>();
                    foreach (var g in tmp)
                    {
                        var set = new HashSet<ProtocolTransportAddressPair>(g);
                        _transportMapping.Add(g.Key, set);
                    }

                    _defaultAddress = akkaProtocolTransports.Head().Address;
                    _addresses = new HashSet<Address>(akkaProtocolTransports.Select(x => x.Address));

                    log.Info("Remoting started; listening on addresses : [{0}]", string.Join(",", _addresses.Select(x => x.ToString())));

                    _endpointManager.Tell(new EndpointManager.StartupFinished());
                    _eventPublisher.NotifyListeners(new RemotingListenEvent(_addresses.ToList()));

                }
                catch (TaskCanceledException ex)
                {
                    NotifyError("Startup was cancelled due to timeout", ex);
                    throw;
                }
                catch (TimeoutException ex)
                {
                    NotifyError("Startup timed out", ex);
                    throw;
                }
                catch (Exception ex)
                {
                    NotifyError("Startup failed", ex);
                    throw;
                }
            }
            else
            {
                log.Warn("Remoting was already started. Ignoring start attempt.");
            }
        }
Example #48
0
 public void RegisterTempActor(InternalActorRef actorRef, ActorPath path)
 {
     if(path.Parent != _tempNode)
         throw new Exception("Cannot RegisterTempActor() with anything not obtained from tempPath()");
     _tempContainer.AddChild(path.Name, actorRef);
 }
Example #49
0
 public void SetTempContainer(InternalActorRef tempContainer)
 {
     _tempContainer = tempContainer;
 }
        public InternalActorRef ActorOf(ActorSystemImpl system, Props props, InternalActorRef supervisor, ActorPath path, bool systemService, Deploy deploy, bool lookupDeploy, bool async)
        {
            //TODO: This does not match Akka's ActorOf at all

            Deploy configDeploy = _system.Provider.Deployer.Lookup(path);

            deploy = configDeploy ?? props.Deploy ?? Deploy.None;
            if (deploy.Mailbox != null)
            {
                props = props.WithMailbox(deploy.Mailbox);
            }
            if (deploy.Dispatcher != null)
            {
                props = props.WithDispatcher(deploy.Dispatcher);
            }
            if (deploy.Scope is RemoteScope)
            {
            }

            if (string.IsNullOrEmpty(props.Mailbox))
            {
                //   throw new NotSupportedException("Mailbox can not be configured as null or empty");
            }
            if (string.IsNullOrEmpty(props.Dispatcher))
            {
                //TODO: fix this..
                //    throw new NotSupportedException("Dispatcher can not be configured as null or empty");
            }


            //TODO: how should this be dealt with?
            //akka simply passes the "deploy" var from remote daemon to ActorOf
            //so it atleast seems like they ignore if remote scope is provided here.
            //leaving this for now since it does work

            //if (props.Deploy != null && props.Deploy.Scope is RemoteScope)
            //{
            //    throw new NotSupportedException("LocalActorRefProvider can not deploy remote");
            //}

            if (props.RouterConfig is NoRouter || props.RouterConfig == null)
            {
                props = props.WithDeploy(deploy);
                var dispatcher = system.Dispatchers.FromConfig(props.Dispatcher);
                var mailbox    = _system.Mailboxes.FromConfig(props.Mailbox);
                //TODO: Should be: system.mailboxes.getMailboxType(props2, dispatcher.configurator.config)

                if (async)
                {
                    var reActorRef = new RepointableActorRef(system, props, dispatcher, () => mailbox, supervisor, path);
                    reActorRef.Initialize(async: true);
                    return(reActorRef);
                }
                return(new LocalActorRef(system, props, dispatcher, () => mailbox, supervisor, path));
            }
            else
            {
                //if no Router config value was specified, override with procedural input
                if (deploy.RouterConfig is NoRouter)
                {
                    deploy = deploy.WithRouterConfig(props.RouterConfig);
                }
                var routerDispatcher = system.Dispatchers.FromConfig(props.RouterConfig.RouterDispatcher);
                var routerMailbox    = _system.Mailboxes.FromConfig(props.Mailbox);
                //TODO: Should be val routerMailbox = system.mailboxes.getMailboxType(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 routerProps = Props.Empty.WithDeploy(deploy);
                var routeeProps = props.WithRouter(RouterConfig.NoRouter);

                var routedActorRef = new RoutedActorRef(system, routerProps, routerDispatcher, () => routerMailbox, routeeProps, supervisor, path);
                routedActorRef.Initialize(async);
                return(routedActorRef);
            }
        }
Example #51
0
        public InternalActorRef ActorOf(ActorSystem system, Props props, InternalActorRef supervisor, ActorPath path, bool systemService, Deploy deploy, bool lookupDeploy, bool async)
        {
            //TODO: This does not match Akka's ActorOf at all

            Deploy configDeploy = _system.Provider.Deployer.Lookup(path);
            deploy = configDeploy ?? props.Deploy ?? Deploy.None;
            if(deploy.Mailbox != null)
                props = props.WithMailbox(deploy.Mailbox);
            if(deploy.Dispatcher != null)
                props = props.WithDispatcher(deploy.Dispatcher);
            if(deploy.Scope is RemoteScope)
            {

            }

            if(string.IsNullOrEmpty(props.Mailbox))
            {
                //   throw new NotSupportedException("Mailbox can not be configured as null or empty");
            }
            if(string.IsNullOrEmpty(props.Dispatcher))
            {
                //TODO: fix this..
                //    throw new NotSupportedException("Dispatcher can not be configured as null or empty");
            }


            //TODO: how should this be dealt with?
            //akka simply passes the "deploy" var from remote daemon to ActorOf
            //so it atleast seems like they ignore if remote scope is provided here.
            //leaving this for now since it does work

            //if (props.Deploy != null && props.Deploy.Scope is RemoteScope)
            //{
            //    throw new NotSupportedException("LocalActorRefProvider can not deploy remote");
            //}

            if(props.RouterConfig is NoRouter || props.RouterConfig == null)
            {

                props = props.WithDeploy(deploy);
                var dispatcher = system.Dispatchers.FromConfig(props.Dispatcher);
                var mailbox = _system.Mailboxes.FromConfig(props.Mailbox);
                    //TODO: Should be: system.mailboxes.getMailboxType(props2, dispatcher.configurator.config)

                if (async)
                {
                    var reActorRef=new RepointableActorRef(system, props, dispatcher, () => mailbox, supervisor, path);
                    reActorRef.Initialize(async:true);
                    return reActorRef;
                }
                return new LocalActorRef(system, props, dispatcher, () => mailbox, supervisor, path);
            }
            else
            {
                //if no Router config value was specified, override with procedural input
                if(deploy.RouterConfig is NoRouter)
                {
                    deploy = deploy.WithRouterConfig(props.RouterConfig);
                }
                var routerDispatcher = system.Dispatchers.FromConfig(props.RouterConfig.RouterDispatcher);
                var routerMailbox = _system.Mailboxes.FromConfig(props.Mailbox);
                    //TODO: Should be val routerMailbox = system.mailboxes.getMailboxType(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 routerProps = Props.Empty.WithDeploy(deploy);
                var routeeProps = props.WithRouter(RouterConfig.NoRouter);

                var routedActorRef = new RoutedActorRef(system, routerProps, routerDispatcher, () => routerMailbox, routeeProps,supervisor, path);
                routedActorRef.Initialize(async);
                return routedActorRef;
            }
        }
Example #52
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, InternalActorRef 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
 }
Example #53
0
 public VirtualPathContainer(ActorRefProvider provider, ActorPath path, InternalActorRef parent)
 {
     Path          = path;
     this.parent   = parent;
     this.provider = provider;
 }
Example #54
0
 private void InitChild(string name, InternalActorRef actor)
 {
     children.TryUpdate(name, actor, ActorRef.Reserved);
 }
Example #55
0
 private ActorRef ResolveActorRef(InternalActorRef 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 child;
 }
Example #56
0
 /// <summary>
 ///     Actors the of.
 /// </summary>
 /// <param name="system">The system.</param>
 /// <param name="props">The props.</param>
 /// <param name="supervisor">The supervisor.</param>
 /// <param name="path">The path.</param>
 /// <returns>InternalActorRef.</returns>
 public abstract InternalActorRef ActorOf(ActorSystem system, Props props, InternalActorRef supervisor,
     ActorPath path);
Example #57
0
 /// <summary>
 /// INTERNAL API
 /// 
 /// Convenience method used by remoting when receiving <see cref="ActorSelectionMessage"/> from a remote
 /// actor.
 /// </summary>
 internal static void DeliverSelection(InternalActorRef anchor, ActorRef sender, ActorSelectionMessage sel)
 {
     var actorSelection = new ActorSelection(anchor, sel.Elements);
     actorSelection.Tell(sel.Message, sender);
 }
Example #58
0
 /// <summary>
 ///     Registers the temporary actor.
 /// </summary>
 /// <param name="actorRef">The actor reference.</param>
 /// <param name="path">The path.</param>
 public void RegisterTempActor(InternalActorRef actorRef, ActorPath path)
 {
     TempContainer.AddChild(path.Name, actorRef);
 }
 /// <summary>
 ///     Registers the temporary actor.
 /// </summary>
 /// <param name="actorRef">The actor reference.</param>
 /// <param name="path">The path.</param>
 public void RegisterTempActor(InternalActorRef actorRef, ActorPath path)
 {
     TempContainer.AddChild(path.Name, actorRef);
 }