Exemple #1
0
        protected override void PreStart()
        {
            ClusterActorDiscovery.Get(Context.System)
            .Discovery.Tell(new ClusterActorDiscoveryMessage.RegisterActor(Self, HostApi.ApiKey));

            base.PreStart();
        }
Exemple #2
0
        protected override void PreStart()
        {
            ClusterActorDiscovery.Get(Context.System)
            .Discovery.Tell(new MonitorActor(HostApi.ApiKey));

            base.PreStart();
        }
Exemple #3
0
            public KillSwitchActor(ActorSystem system)
            {
                _actorDiscovery = ClusterActorDiscovery.Get(system).Discovery;

                Flow <ActorDown>(b =>
                {
                    b.Action(ad =>
                    {
                        Log.Info("Remove Killswitch Actor {Name}", ad.Actor.Path);
                        _actors
                        .FindIndex(ae => ae.Target.Equals(ad.Actor))
                        .When(i => i != -1, i => _actors.RemoveAt(i));
                    });
                });

                Flow <ActorUp>(b =>
                {
                    b.Func(au =>
                    {
                        Log.Info("New killswitch Actor {Name}", au.Actor.Path);
                        return(_actors
                               .AddAnd(ActorElement.New(au.Actor))
                               .To(_ => new RequestRegistration()));
                    })
                    .ToRefFromMsg(au => au.Actor)
                    .Then <RespondRegistration>(b1 =>
                    {
                        b1.Action(r =>
                        {
                            Log.Info("Set Killswitch Actor Type {Type} {Name}", r.RecpientType, Context.Sender.Path);
                            _actors
                            .Find(e => e.Target.Equals(Context.Sender))
                            .When(i => i != null, element => element.RecpientType = r.RecpientType);
                        });
                    });
                });

                Flow <RequestRegistration>(b =>
                                           b.Func(() => new RespondRegistration(KillRecpientType.Seed))
                                           .ToSender());

                Flow <KillClusterMsg>(b => b.Action(RunKillCluster));

                Flow <KillNode>(b =>
                                b.Action(_ =>
                {
                    Log.Info("Leaving Cluster");
                    Cluster.Get(Context.System).LeaveAsync();
                }));

                Flow <ActorUp>(b =>
                               b.Action(au => au.When(u => u.Tag == "None", up =>
                {
                    Log.Info("Incoming kill Watcher {Name}", up.Actor.Path);
                    Context.Watch(up.Actor);
                }))
                               .Then <Terminated>(b1 => b1.Func(t => new ActorDown(t.ActorRef, "None")).ToSelf()));
            }
        protected override void ConfigImpl()
        {
            Receive <SubscribeFeature.InternalEventSubscription>(obs => obs
                                                                 .SelectMany(m => m.State.Entries.Select(entry => (entry, m.Event.Intrest)))
                                                                 .SubscribeWithStatus(p
                                                                                      => p.Intrest.Tell(new HostEntryChanged(p.entry.Value.Name, p.entry.Key, false))));

            Receive <ActorDown>(obs => obs.Where(p => p.State.Entries.ContainsKey(p.Event.Actor.Path))
                                .Select(m =>
            {
                var(actorDown, state, _) = m;
                var(name, actor)         = state.Entries[actorDown.Actor.Path];
                TellSelf(SendEvent.Create(new HostEntryChanged(name, actor.Path, true)));

                return(state with {
                    Entries = state.Entries.Remove(actorDown.Actor.Path)
                });
            }));

            Receive <ActorUp>(obs => obs.Select(m =>
            {
                var(message, state, _) = m;
                message.Actor.Tell(new GetHostName());
                TellSelf(SendEvent.Create(new HostEntryChanged(string.Empty, message.Actor.Path, false)));

                return(state with
                {
                    Entries = state.Entries.SetItem(message.Actor.Path, new HostEntry(string.Empty, message.Actor))
                });
            }));

            Receive <GetHostNameResult>(obs => obs.Where(m => m.State.Entries.ContainsKey(Context.Sender.Path))
                                        .Select(m =>
            {
                var(message, state, _) = m;

                var newEntry = state.Entries[Context.Sender.Path] with {
                    Name = message.Name
                };
                TellSelf(SendEvent.Create(new HostEntryChanged(newEntry.Name, newEntry.Actor.Path, false)));

                return(state with {
                    Entries = state.Entries.SetItem(Context.Sender.Path, newEntry)
                });
            }));

            Receive <IHostApiCommand>(obs => obs
                                      .Select(m => new
            {
                Command = m.Event, Host = m.State.Entries.FirstOrDefault(e => e.Value.Name == m.Event.Target).Value
            })
                                      .SubscribeWithStatus(m =>
            {
                if (m.Host == null)
                {
                    Context.Sender.Tell(m.Command.CreateDefaultFailed());
                }
                else
                {
                    m.Host.Actor.Forward(m.Command);
                }
            }));

            Start.SubscribeWithStatus(c
                                      => ClusterActorDiscovery.Get(c.System).Discovery.Tell(new MonitorActor(HostApi.ApiKey)));
        }
Exemple #5
0
 protected override void PreStart()
 {
     ClusterActorDiscovery.Get(Context.System).Discovery.Tell(new MonitorActor(KillSwitchName));
     base.PreStart();
 }
            protected override void ConfigImpl()
            {
                Receive <ActorDown>(obs => obs.Do(ad => Log.Info($"Remove KillSwitch Actor {ad.Event.Actor.Path}"))
                                    .Select(m =>
                {
                    var(actorDown, state, _) = m;
                    var entry = state.Actors.Find(e => e.Target.Equals(actorDown.Actor));

                    if (entry == null)
                    {
                        return(state);
                    }
                    return(state with {
                        Actors = state.Actors.Remove(entry)
                    });
                }));

                Receive <ActorUp>(obs => obs.Do(au => Log.Info($"New killswitch Actor {au.Event.Actor.Path}"))
                                  .Select(m =>
                {
                    var(actorUp, state, _) = m;
                    actorUp.Actor.Tell(new RequestRegistration());
                    return(state with {
                        Actors = state.Actors.Add(ActorElement.New(actorUp.Actor))
                    });
                }));

                Receive <RespondRegistration>(obs => obs
                                              .Do(r => Log.Info($"Set Killswitch Actor Type {r.Event.RecpientType} {Sender.Path}"))
                                              .Select(r =>
                {
                    var(respondRegistration, state, _) = r;
                    var ele = state.Actors.Find(e => e.Target.Equals(Sender));
                    if (ele == null)
                    {
                        return(state);
                    }

                    return(state with
                    {
                        Actors = state.Actors.Replace(ele,
                                                      ele with {
                            RecpientType = respondRegistration.RecpientType
                        })
                    });
                }));

                Receive <RequestRegistration>(obs => obs.Select(_ => new RespondRegistration(KillRecpientType.Seed))
                                              .ToSender());

                Receive <KillClusterMsg>(obs => obs.SubscribeWithStatus(_ => RunKillCluster()));

                Receive <KillNode>(obs => obs.Do(_ => Log.Info("Leaving Cluster"))
                                   .SubscribeWithStatus(_ => Cluster.Get(Context.System).LeaveAsync()));

                Receive <ActorUp>(obs => obs.Where(m => m.Event.Tag == nameof(KillWatcher))
                                  .Do(up => Log.Info($"Incomming Kill Watcher {up.Event.Actor.Path}"))
                                  .Select(m => m.Event.Actor)
                                  .SubscribeWithStatus(actor => Context.Watch(actor)));

                Receive <Terminated>(obs => obs.Select(t => new ActorDown(t.Event.ActorRef, nameof(KillWatcher)))
                                     .ToSelf());

                Start.Subscribe(_ =>
                {
                    var actorDiscovery = ClusterActorDiscovery.Get(ObservableActor.Context.System).Discovery;

                    actorDiscovery.Tell(new RegisterActor(Self, KillSwitchName));
                    actorDiscovery.Tell(new MonitorActor(nameof(KillSwitchName)));
                });
            }