public ItemAndDiscountOutputObject(Item newItem, Transaction transaction, double heightOfEachBox, StackPanel itemOutputPanel, StackPanel couponOutputPanel, UpdateTotals updateFunction, Employee currentUser) { m_item = newItem; m_transaction = transaction; boxHeight = heightOfEachBox; m_itemOutputPanel = itemOutputPanel; m_discountOutputPanel = couponOutputPanel; m_currentUser = currentUser; m_stackOfDiscounts = new StackPanel(); m_updateFunction = updateFunction; ItemDisplayBox itemDisplayBox = new ItemDisplayBox(m_item, m_transaction, RemoveItem, UpdateItemDetails, AddDiscount, m_currentUser); itemDisplayBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; itemDisplayBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; itemDisplayBox.Height = boxHeight; m_itemDescriptionBox = new Grid(); m_itemDescriptionBox.Children.Add(itemDisplayBox); if (m_item.Discounts.Count() == 0) { Grid blankCoupon = new Grid(); blankCoupon.Height = boxHeight; m_stackOfDiscounts.Children.Add(blankCoupon); m_noDiscounts = true; } else { m_noDiscounts = false; foreach (IDiscount discount in m_item.Discounts) { DiscountDisplayBox autoAppliedDiscount = new DiscountDisplayBox(discount, m_item, m_transaction, RemoveDiscount, UpdateItemDetails, m_currentUser); autoAppliedDiscount.Height = boxHeight; m_stackOfDiscounts.Children.Add(autoAppliedDiscount); } } UpdateHeight(); OutputItem(); }
private void TrySend(EPServiceProvider epService, int numThreads, int numEventsPerThread) { epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); // setup statements epService.EPAdministrator.CreateEPL("create window MyWindow#unique(TheString, IntPrimitive) as select * from SupportBean"); epService.EPAdministrator.CreateEPL("insert into MyWindow select * from SupportBean(BoolPrimitive = true)"); epService.EPAdministrator.CreateEPL("on SupportBean(BoolPrimitive = false) sb " + "update MyWindow win set IntBoxed = win.IntBoxed + 1, DoublePrimitive = win.DoublePrimitive + sb.DoublePrimitive" + " where sb.TheString = win.TheString and sb.IntPrimitive = win.IntPrimitive"); // send primer events, initialize totals var totals = new Dictionary <MultiKeyUntyped, UpdateTotals>(); for (int i = 0; i < NUM_STRINGS; i++) { for (int j = 0; j < NUM_INTS; j++) { var primer = new SupportBean(Convert.ToString(i), j); primer.BoolPrimitive = true; primer.IntBoxed = 0; primer.DoublePrimitive = 0; epService.EPRuntime.SendEvent(primer); var key = new MultiKeyUntyped(primer.TheString, primer.IntPrimitive); totals.Put(key, new UpdateTotals(0, 0)); } } // execute long startTime = DateTimeHelper.CurrentTimeMillis; var threadPool = Executors.NewFixedThreadPool(numThreads); var future = new Future <StmtNamedWindowUpdateCallable.UpdateResult> [numThreads]; for (int i = 0; i < numThreads; i++) { future[i] = threadPool.Submit(new StmtNamedWindowUpdateCallable("Thread" + i, epService, numEventsPerThread)); } threadPool.Shutdown(); threadPool.AwaitTermination(10, TimeUnit.SECONDS); long endTime = DateTimeHelper.CurrentTimeMillis; // total up result long deltaCumulative = 0; for (int i = 0; i < numThreads; i++) { StmtNamedWindowUpdateCallable.UpdateResult result = future[i].GetValueOrDefault(); deltaCumulative += result.Delta; foreach (StmtNamedWindowUpdateCallable.UpdateItem item in result.Updates) { var key = new MultiKeyUntyped(item.TheString, item.Intval); UpdateTotals total = totals.Get(key); if (total == null) { throw new EPRuntimeException("Totals not found for key " + key); } total.Num = total.Num + 1; total.Sum = total.Sum + item.DoublePrimitive; } } // compare EventBean[] rows = epService.EPRuntime.ExecuteQuery("select * from MyWindow").Array; Assert.AreEqual(rows.Length, totals.Count); long totalUpdates = 0; foreach (EventBean row in rows) { UpdateTotals total = totals.Get(new MultiKeyUntyped(row.Get("TheString"), row.Get("IntPrimitive"))); Assert.AreEqual(total.Num, row.Get("IntBoxed")); Assert.AreEqual(total.Sum, row.Get("DoublePrimitive")); totalUpdates += total.Num; } Assert.AreEqual(totalUpdates, numThreads * numEventsPerThread); //long deltaTime = endTime - startTime; //Log.Info("Totals updated: " + totalUpdates + " Delta cumu: " + deltaCumulative + " Delta pooled: " + deltaTime); }
private void TrySend(int numThreads, int numEventsPerThread) { Configuration config = SupportConfigFactory.GetConfiguration(); config.AddEventType("SupportBean", typeof(SupportBean)); _engine = EPServiceProviderManager.GetDefaultProvider(config); _engine.Initialize(); // setup statements _engine.EPAdministrator.CreateEPL("create window MyWindow.std:unique(TheString, IntPrimitive) as select * from SupportBean"); _engine.EPAdministrator.CreateEPL("insert into MyWindow select * from SupportBean(BoolPrimitive = true)"); _engine.EPAdministrator.CreateEPL("on SupportBean(BoolPrimitive = false) sb " + "Update MyWindow win set IntBoxed = win.IntBoxed + 1, DoublePrimitive = win.DoublePrimitive + sb.DoublePrimitive" + " where sb.TheString = win.TheString and sb.IntPrimitive = win.IntPrimitive"); // send primer events, initialize totals IDictionary <MultiKeyUntyped, UpdateTotals> totals = new Dictionary <MultiKeyUntyped, UpdateTotals>(); for (int i = 0; i < NUM_STRINGS; i++) { for (int j = 0; j < NUM_INTS; j++) { var primer = new SupportBean(Convert.ToString(i), j); primer.BoolPrimitive = true; primer.IntBoxed = 0; primer.DoublePrimitive = 0; _engine.EPRuntime.SendEvent(primer); var key = new MultiKeyUntyped(primer.TheString, primer.IntPrimitive); totals.Put(key, new UpdateTotals(0, 0)); } } // execute long startTime = PerformanceObserver.MilliTime; var threadPool = Executors.NewFixedThreadPool(numThreads); var future = new Future <StmtNamedWindowUpdateCallable.UpdateResult> [numThreads]; for (int i = 0; i < numThreads; i++) { future[i] = threadPool.Submit(new StmtNamedWindowUpdateCallable("Thread" + i, _engine, numEventsPerThread)); } threadPool.Shutdown(); threadPool.AwaitTermination(TimeSpan.FromSeconds(10)); long endTime = PerformanceObserver.MilliTime; // total up result long deltaCumulative = 0; for (int i = 0; i < numThreads; i++) { StmtNamedWindowUpdateCallable.UpdateResult result = future[i].GetValueOrDefault(); deltaCumulative += result.Delta; foreach (StmtNamedWindowUpdateCallable.UpdateItem item in result.Updates) { var key = new MultiKeyUntyped(item.TheString, item.Intval); var total = totals.Get(key); if (total == null) { throw new ApplicationException("Totals not found for key " + key); } total.Num = total.Num + 1; total.Sum = total.Sum + item.DoublePrimitive; } } // compare EventBean[] rows = _engine.EPRuntime.ExecuteQuery("select * from MyWindow").Array; Assert.AreEqual(rows.Length, totals.Count); long totalUpdates = 0; foreach (EventBean row in rows) { UpdateTotals total = totals.Get(new MultiKeyUntyped(row.Get("TheString"), row.Get("IntPrimitive"))); Assert.AreEqual(total.Num, row.Get("IntBoxed")); Assert.AreEqual(total.Sum, row.Get("DoublePrimitive")); totalUpdates += total.Num; } Assert.AreEqual(totalUpdates, numThreads * numEventsPerThread); //long deltaTime = endTime - startTime; //Console.Out.WriteLine("Totals updated: " + totalUpdates + " Delta cumu: " + deltaCumulative + " Delta pooled: " + deltaTime); }