public Adept(IRepositoryService repoService, AdeptOptions options) { _repoService = repoService; var leaderAddress = Context.ActorSelection(options.LeaderActorPath); Receive <InitHandshake>(_ => leaderAddress.Tell(new HandshakeMessage())); Receive <HandshakeSuccessMessage>(_ => { _leader = Sender; Console.WriteLine($"Handshake success from {Sender.Path}"); Console.WriteLine("Waiting for job."); }); Receive <CloneThisRepoMessage>(m => { if (!Sender.Equals(_leader)) { Sender.Tell("Go away impostor!"); } _repoService.FetchFilesAsync(MapToSettings(m)); _leader.Tell(new CloningDoneMessage()); }); Receive <StartWorkingMessage>(m => { Console.WriteLine($"Will mutate file: {m.File}"); // TODO: delegate work to a child Thread.Sleep(5000); _leader.Tell(new TestingResults($"I found this {Guid.NewGuid()}")); }); Receive <NoWorkForYouMessage>(_ => { Console.WriteLine("No work for me :("); }); }
static void Main(string[] args) { var config = ConfigurationFactory.ParseString(@" akka { actor { provider = remote } remote { dot-netty.tcp { port = 0 hostname = localhost } } } " ); var container = new Ninject.StandardKernel(); container.Bind <IRepositoryService>().To(typeof(PublicGitRepositoryService)); var adeptOptions = new AdeptOptions { LeaderActorPath = "akka.tcp://CoMutatorNetwork@localhost:8081/user/Leader" }; container.Bind <AdeptOptions>().ToConstant(adeptOptions); using (var system = ActorSystem.Create("Adept", config)) { var propsResolver = new NinjectDependencyResolver(container, system); var adept = system.ActorOf(system.DI().Props <Adept>()); adept.Tell(new InitHandshake()); Console.Read(); } }