public ProcessStateHubActor(IRecycleConfiguration conf) : base(conf)
 {
     ChildActorType = typeof(ProcessStateActor <TState>);
     Receive <GetProcessState>(s =>
     {
         SendToChild(s, GetChildActorName(s.Id), Sender);
     });
 }
Пример #2
0
        public RecycleMonitorActor(IRecycleConfiguration recycleConfiguration, IActorRef watched, IActorRef watcher = null)
        {
            _actorRef = watcher;
            Context.Watch(watched);
            var log                  = Context.GetSeriLogger();
            var schedule             = ScheduleCheck(recycleConfiguration.ChildClearPeriod);
            var isWaitingForShutdown = false;
            var lastActivityTime     = BusinessDateTime.UtcNow;;

            log.Debug("Initialized recycle monitor for {actor}, max inactive time {inactive}, check period is {period}",
                      watched,
                      recycleConfiguration.ChildMaxInactiveTime,
                      recycleConfiguration.ChildClearPeriod);

            Receive <Activity>(a =>
            {
                var now          = BusinessDateTime.UtcNow;
                var inactiveTime = now - lastActivityTime;
                lastActivityTime = now;
                log.Debug($"Received activity after {inactiveTime}");
                if (!isWaitingForShutdown)
                {
                    return;
                }
                log.Debug("Rescheduling schecks after receiving activity after shutdown request");

                isWaitingForShutdown = false;
                schedule             = ScheduleCheck(recycleConfiguration.ChildClearPeriod);
            }, a => Sender.Path == watched.Path);
            Receive <Check>(c =>
            {
                var inactivityDuration = BusinessDateTime.UtcNow - lastActivityTime;
                log.Debug($"inactivity duration: {inactivityDuration}");
                if (inactivityDuration > recycleConfiguration.ChildMaxInactiveTime)
                {
                    log.Debug($"Sending graceful shutdown request to {watched} due to inactivity for {inactivityDuration} with max allowed {recycleConfiguration.ChildMaxInactiveTime}");
                    watched.Tell(Shutdown.Request.Instance);
                    isWaitingForShutdown = true;
                }
                schedule = ScheduleCheck(recycleConfiguration.ChildClearPeriod);
            });
            Receive <Terminated>(t =>
            {
                schedule.Cancel();
                _actorRef?.Tell(Shutdown.Complete.Instance);
                Context.Stop(Self);
            }, t => t.ActorRef.Path == watched.Path);
        }
Пример #3
0
        protected PersistentHubActor(IRecycleConfiguration recycleConfiguration, string counterName)
        {
            _recycleConfiguration = recycleConfiguration;
            _monitor = new ActorMonitor(Context, $"Hub_{counterName}");
            var forwardEntry = new ProcessEntry(Self.Path.Name, "Forwarding to child", "All messages should be forwarded");

            Receive <NotifyOnPersistenceEvents>(m => SendToChild(m, GetChildActorName(m.Id), Sender));
            Receive <ShutdownChild>(m => {
                var childActorName = GetChildActorName(m.ChildId);
                var child          = Context.Child(childActorName);
                if (child == Nobody.Instance)
                {
                    return;
                }
                CreateRecyleMonitor(child, ChildFastShutdownRecycleConfiguration.Instance,
                                    $"Shutdown_RecycleMonitor_{childActorName}");
            });
            Receive <WarmUpChild>(m =>
            {
                var created = InitChild(GetChildActorName(m.Id), out var info);
                Sender.Tell(new WarmUpResult(info, created));
            });

            Receive <CheckHealth>(s => Sender.Tell(new HealthStatus(s.Payload)));
            Receive <IMessageMetadataEnvelop>(messageWithMetadata =>
            {
                var childId = GetChildActorId(messageWithMetadata);
                if (string.IsNullOrEmpty(childId))
                {
                    throw new InvalidOperationException("child id is empty." + messageWithMetadata);
                }

                var name = GetChildActorName(childId);
                if (string.IsNullOrEmpty(childId))
                {
                    throw new InvalidOperationException("child name is empty." + messageWithMetadata);
                }

                messageWithMetadata.Metadata.History.Add(forwardEntry);
                SendToChild(messageWithMetadata, name, Sender);
            });
        }
Пример #4
0
 private void CreateRecyleMonitor(IActorRef child, IRecycleConfiguration recycleConfiguration, string name, IActorRef watcher = null)
 {
     Context.ActorOf(Props.Create(() => new RecycleMonitorActor(recycleConfiguration, child, watcher)), name);
 }
Пример #5
0
 public AggregateHubActor(IRecycleConfiguration conf) : base(conf, typeof(TAggregate).Name)
 {
     ChildActorType = typeof(AggregateActor <TAggregate>);
 }
Пример #6
0
 public ProcessHubActor(IRecycleConfiguration recycleConf, string processName) : base(recycleConf, processName)
 {
     _processName = processName;
 }