public Task <IInventoryServiceCompletedMessage> PlaceHoldAsync(RealTimeInventory product, int holdQuantity) { var request = new PlaceHoldMessage(product.ProductId, holdQuantity); if (DontUseActorSystem) { return(PerformOperation(request, product.PlaceHoldAsync(TestInventoryStorage, request.ProductId, request.Update), TestInventoryStorage .ReadInventoryAsync(request.ProductId) .Result.Result)); } return(inventoryActor.Ask <IInventoryServiceCompletedMessage>(request, GENERAL_WAIT_TIME)); }
public ProductInventoryActor(IInventoryStorage inventoryStorage, IActorRef InventoryQueryActorRef, string id, bool withCache, IPerformanceService performanceService) { PerformanceService = performanceService; _id = id; _withCache = withCache; InventoryStorage = inventoryStorage; RealTimeInventory = RealTimeInventory.InitializeFromStorage(InventoryStorage, id); NotificationActorRef = InventoryQueryActorRef; ReceiveAsync <GetInventoryMessage>(async message => { if (!CanProcessMessage(message.ProductId, message)) { return; } if (_withCache == false) { var result = await RealTimeInventory.ReadInventoryFromStorageAsync(InventoryStorage, message.ProductId); RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory; } else { RealTimeInventory = RealTimeInventory.ToSuccessOperationResult().ProcessAndSendResult(message, (rti) => new GetInventoryCompletedMessage(rti, true), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory; } }); ReceiveAsync <ReserveMessage>(async message => { if (!CanProcessMessage(message.ProductId, message)) { return; } var result = await RealTimeInventory.ReserveAsync(InventoryStorage, message.ProductId, message.Update); RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory; }); ReceiveAsync <UpdateQuantityMessage>(async message => { if (!CanProcessMessage(message.ProductId, message)) { return; } var result = await RealTimeInventory.UpdateQuantityAsync(InventoryStorage, message.ProductId, message.Update); RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory; }); ReceiveAsync <UpdateAndHoldQuantityMessage>(async message => { if (!CanProcessMessage(message.ProductId, message)) { return; } var updateandHoldResultesult = await RealTimeInventory.UpdateQuantityAndHoldAsync(InventoryStorage, message.ProductId, message.Update); RealTimeInventory = updateandHoldResultesult.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory; }); ReceiveAsync <PlaceHoldMessage>(async message => { if (!CanProcessMessage(message.ProductId, message)) { return; } var result = await RealTimeInventory.PlaceHoldAsync(InventoryStorage, message.ProductId, message.Update); RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory; }); ReceiveAsync <PurchaseMessage>(async message => { if (!CanProcessMessage(message.ProductId, message)) { return; } var result = await RealTimeInventory.PurchaseAsync(InventoryStorage, message.ProductId, message.Update); RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory; }); ReceiveAsync <PurchaseFromHoldsMessage>(async message => { if (!CanProcessMessage(message.ProductId, message)) { return; } var result = await RealTimeInventory.PurchaseFromHoldsAsync(InventoryStorage, message.ProductId, message.Update).ConfigureAwait(false); RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory; }); ReceiveAsync <FlushStreamsMessage>(async message => { var result = await RealTimeInventory.InventoryStorageFlushAsync(InventoryStorage, _id); Sender.Tell(result.Data); }); ReceiveAsync <ResetInventoryQuantityReserveAndHoldMessage>(async message => { if (!CanProcessMessage(message.ProductId, message)) { return; } var updateandHoldResultesult = await RealTimeInventory.ResetInventoryQuantityReserveAndHoldAsync(InventoryStorage, message.ProductId, message.Update, message.Reservations, message.Holds); RealTimeInventory = updateandHoldResultesult.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory; }); #if DEBUG // Context.System.Scheduler.ScheduleTellRepeatedly(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(5), Nobody.Instance, RealTimeInventory, Self); #endif }