示例#1
0
        public ImpressionRequest(IActorRef webActor, GetBestAdForSpace requestToSend, List<ActorSelection> keywordActors)
        {
            _webActor = webActor;

            foreach (var keywordActor in keywordActors)
                keywordActor.Tell(requestToSend);

            Receive<BidForSpace>(message =>
            {
                if (message.Bid > _bestBidPrice)
                {
                    _bestBidActor?.Tell(new RejectBid());

                    _bestBidPrice = message.Bid;
                    _bestBidActor = Sender;
                    _bestBidAdUrl = message.AdUrl;
                    //Console.WriteLine($"New Best Bid found: {message.Bid} from {message.AdUrl}");
                }
                else
                {
                    Sender.Tell(new RejectBid());
                    //Console.WriteLine($"Inferior Bid rejected: {message.Bid} from {message.AdUrl}");
                }
            });

            Receive<SendBestReceivedBidSoFar>(_ =>
            {
                if (_bestBidPrice == 0)
                    _webActor.Tell("No Ads available");
                else
                {
                    _webActor.Tell($"{_bestBidAdUrl} @ {_bestBidPrice}");
                    _bestBidActor.Tell(new BidAccepted(Context.Parent));
                    Self.Tell(PoisonPill.Instance);
                }
            });

            Receive<PrintStats>(_ => HandlePrintStats());

            Context.System.Scheduler.ScheduleTellOnce(TimeSpan.FromMilliseconds(100), Self, new SendBestReceivedBidSoFar(), Self);
        }
示例#2
0
        // This is the current bottleneck
        public Space(CreateSpace createSpaceMessage)
        {
            _uniqueSpaceName = createSpaceMessage.UniqueSpaceName;
            _size = createSpaceMessage.Size;
            _keywords = createSpaceMessage.Keywords;

            _keywordActors = new List<ActorSelection>();

            foreach (var keyword in _keywords)
            {
                ActorSelection keywordActor = Context.System.ActorSelection($"/user/KeywordsRoot/{keyword}");
                _keywordActors.Add(keywordActor);
            }

            Receive<RequestAd>(message =>
            {
                var request = new GetBestAdForSpace(_uniqueSpaceName, _size); // Create a request for the best ad, send it to our keywords.

                Props props = Props.Create<ImpressionRequest>(Sender, request, _keywordActors);
                IActorRef impressionRequest = Context.ActorOf(props);
            });
        }