protected override void OnReceive(object message) { message.Match() .With <Listen>(listen => Listens.ContinueWith <NoSerializationVerificationNeeded>(listens => { if (listens.IsFaulted) { return(new ListensFailure(listen.AddressesPromise, listens.Exception)); } else { return(new ListensResult(listen.AddressesPromise, listens.Result)); } }, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.AttachedToParent) .PipeTo(Self)) .With <ListensResult>(listens => { _transportMapping = (from mapping in listens.Results group mapping by mapping.Item1.Address into g select new { address = g.Key, transports = g.ToList() }).Select(x => { if (x.transports.Count > 1) { throw new RemoteTransportException( string.Format("There are more than one transports listening on local address {0}", x.address)); } return(new KeyValuePair <Address, AkkaProtocolTransport>(x.address, x.transports.Head().Item1.ProtocolTransport)); }).ToDictionary(x => x.Key, v => v.Value); //Register a listener to each transport and collect mapping to addresses var transportsAndAddresses = listens.Results.Select(x => { x.Item2.SetResult(new ActorAssociationEventListener(Self)); return(x.Item1); }).ToList(); listens.AddressesPromise.SetResult(transportsAndAddresses); }) .With <ListensFailure>(failure => failure.AddressesPromise.SetException(failure.Cause)) .With <InboundAssociation>(ia => Context.System.Scheduler.ScheduleOnce(TimeSpan.FromMilliseconds(10), Self, ia)) .With <ManagementCommand>(mc => Sender.Tell(new ManagementCommandAck(status: false))) .With <StartupFinished>(sf => Context.Become(Accepting)) .With <ShutdownAndFlush>(sf => { Sender.Tell(true); Context.Stop(Self); }); }
protected override void OnReceive(object message) { message.Match() /* * the first command the EndpointManager receives. * instructs the EndpointManager to fire off its "Listens" command, which starts * up all inbound transports and binds them to specific addresses via configuration. * those results will then be piped back to Remoting, who waits for the results of * listen.AddressPromise. * */ .With <Listen>(listen => Listens.ContinueWith <INoSerializationVerificationNeeded>(listens => { if (listens.IsFaulted) { return(new ListensFailure(listen.AddressesPromise, listens.Exception)); } else { return(new ListensResult(listen.AddressesPromise, listens.Result)); } }, TaskContinuationOptions.ExecuteSynchronously) .PipeTo(Self)) .With <ListensResult>(listens => { _transportMapping = (from mapping in listens.Results group mapping by mapping.Item1.Address into g select new { address = g.Key, transports = g.ToList() }).Select(x => { if (x.transports.Count > 1) { throw new RemoteTransportException( string.Format("There are more than one transports listening on local address {0}", x.address)); } return(new KeyValuePair <Address, AkkaProtocolTransport>(x.address, x.transports.Head().Item1.ProtocolTransport)); }).ToDictionary(x => x.Key, v => v.Value); //Register a listener to each transport and collect mapping to addresses var transportsAndAddresses = listens.Results.Select(x => { x.Item2.SetResult(new ActorAssociationEventListener(Self)); return(x.Item1); }).ToList(); listens.AddressesPromise.SetResult(transportsAndAddresses); }) .With <ListensFailure>(failure => failure.AddressesPromise.SetException(failure.Cause)) // defer the inbound association until we can enter "Accepting" behavior .With <InboundAssociation>(ia => Context.System.Scheduler.ScheduleTellOnce(TimeSpan.FromMilliseconds(10), Self, ia, Self)) .With <ManagementCommand>(mc => Sender.Tell(new ManagementCommandAck(status: false))) // transports are all started. Ready to start accepting inbound associations. .With <StartupFinished>(sf => Context.Become(Accepting)) .With <ShutdownAndFlush>(sf => { Sender.Tell(true); Context.Stop(Self); }); }