private void HandleGetListRequest(SupervisorRegistryGetListRequest r)
        {
            // Immutable dictionaries are NOT serializable across the wire.
            //ImmutableDictionary<MicroServices.Area,IActorRef> immutableDictOfSupervisorsActors =
            //    _KnownSupervisorsActors.ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.SupervisorActorReference);
            //Sender.Tell(new SupervisorRegistryGetListResponse(r.Requestor,immutableDictOfSupervisorsActors,r));
            //Sender.Tell(new SupervisorRegistryGetListResponse(r.Requestor,ImmutableDictionary.Create<MicroServices.Area,IActorRef>(),r));
            // This does not work either
            //ImmutableDictionary<MicroServices.Area,SupervisorInfo> immutableDictOfSupervisorsActors =
            //    _KnownSupervisorsActors.ToImmutableDictionary<MicroServices.Area, SupervisorInfo>();

            _logger.Debug("Sending list of supervisors to:{0}", r.Requestor.Path.ToStringWithAddress());

            Dictionary <MicroServices.Area, IActorRef> dictOfSupervisorsActors =
                _KnownSupervisorsActors.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.SupervisorActorReference);

            Sender.Tell(new SupervisorRegistryGetListResponse(r.Requestor, dictOfSupervisorsActors, r));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method sets the actor so that it can "boot" itself up.
        /// </summary>
        private void Initializing()
        {
            _logger.Debug("Initializing.");

            //Attempt to get a list of supervisors from the SupervisorRegistry
            _logger.Info("Requesting supervisor list from:{0}", _SupervisorRegistry.Path.ToStringWithAddress());
            SupervisorRegistryGetListRequest request = new SupervisorRegistryGetListRequest(Self);

            _SupervisorRegistry.Tell(request);

            var timeout = Context.System.Scheduler.ScheduleTellOnceCancelable(1000, Self, new SupervisorRegistryGetListEvent(request, null, false), Self);

            Receive <SupervisorRegistryGetListResponse>(r => {
                timeout.Cancel();
                _logger.Info("Received supervisor list from:{0}", _SupervisorRegistry.Path.ToStringWithAddress());
                Self.Tell(new SupervisorRegistryGetListEvent(request, r, true));
            });

            //Context.System.EventStream.Subscribe(Self, typeof(DeadLetter));

            //Receive<DeadLetter>(d => {
            //    if (d != null)
            //    {
            //        _logger.Debug(d?.Sender?.Path.ToStringWithAddress());
            //        _logger.Debug(d?.Recipient?.Path.ToStringWithAddress());
            //        _logger.Debug(d?.Message?.ToString());
            //    }
            //});

            Receive <SupervisorRegistryGetListEvent>(e =>
            {
                if (e.Success)
                {
                    // Save the list for internal use
                    _AreaToSupervisorActors = e.ResponseGetList.AreaToSupervisorActorRef;

                    // Instantiate helper actors that will process messages for each area
                    InstantiateMessageProcessingHelperActors();

                    Become(Ready);
                }
                else
                {
                    _logger.Warning("Cannot retrieve list of supervisors. Unable to initialize.  {0} retries.", _FetchSupervisorListRetryCount);

                    // retry the request and increase the timeout
                    _FetchSupervisorListRetryCount++;

                    // Set up the timeout adding a second each time it fails capping at 60 secs
                    int currentTimeoutTimeMilliSeconds = 1000 * _FetchSupervisorListRetryCount <= 1000 * 60 ? 1000 * _FetchSupervisorListRetryCount : 60000;
                    timeout = Context.System.Scheduler.ScheduleTellOnceCancelable(currentTimeoutTimeMilliSeconds, Self, new SupervisorRegistryGetListEvent(request, null, false), Self);

                    // Send the request again
                    _SupervisorRegistry.Tell(request);
                }
            });

            // This catch all will log if there are any weird unhandled messages.
            ReceiveAny(o =>
            {
                Stash.Stash();

                _logger.Debug("{1} Got unhandled message From:{0}", Sender.Path.ToStringWithAddress(), _ActorType);
            });
            _logger.Debug("Initialized.");
        }
 public SupervisorRegistryGetListEvent(SupervisorRegistryGetListRequest requestGetList, SupervisorRegistryGetListResponse responseGetList, bool success)
 {
     GetListRequest  = requestGetList;
     ResponseGetList = responseGetList;
     Success         = success;
 }
Ejemplo n.º 4
0
 public SupervisorRegistryGetListTimeout(SupervisorRegistryGetListRequest request)
 {
     Request = request;
 }
Ejemplo n.º 5
0
 public SupervisorRegistryGetListResponse(IActorRef requestor, Dictionary <MicroServices.Area, IActorRef> areaToSupervisorActorRef, SupervisorRegistryGetListRequest originalRequest)
     : base(requestor, areaToSupervisorActorRef, originalRequest)
 {
     AreaToSupervisorActorRef = areaToSupervisorActorRef;
 }