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))); }