private void TrySendCountFollowedBy(int numThreads, int numEvents, ConfigurationEngineDefaults.ThreadingConfig.Locking locking) { var config = SupportConfigFactory.GetConfiguration(); config.EngineDefaults.Threading.InsertIntoDispatchLocking = locking; config.EngineDefaults.Threading.InsertIntoDispatchTimeout = 5000; // 5 second timeout // This should fail all test in this class // config.EngineDefaults.Threading.InsertIntoDispatchPreserveOrder = false; var engine = EPServiceProviderManager.GetDefaultProvider(config); engine.Initialize(); // setup statements var stmtInsert = engine.EPAdministrator.CreateEPL("insert into MyStream select count(*) as cnt from " + typeof(SupportBean).FullName); stmtInsert.Events += ((sender, e) => Log.Debug(".Update cnt=" + e.NewEvents[0].Get("cnt"))); var listeners = new SupportUpdateListener[numEvents]; for (var i = 0; i < numEvents; i++) { var text = "select * from pattern [MyStream(cnt=" + (i + 1) + ") -> MyStream(cnt=" + (i + 2) + ")]"; var stmt = engine.EPAdministrator.CreateEPL(text); listeners[i] = new SupportUpdateListener(); stmt.Events += listeners[i].Update; } // execute var threadPool = Executors.NewFixedThreadPool(numThreads); var future = new Future <bool> [numThreads]; var sharedStartLock = ReaderWriterLockManager.CreateLock(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); using (sharedStartLock.AcquireWriteLock()) { for (var i = 0; i < numThreads; i++) { future[i] = threadPool.Submit(new SendEventRWLockCallable( i, sharedStartLock.ReadLock, engine, EnumerationGenerator.Create(numEvents))); } Thread.Sleep(100); } threadPool.Shutdown(); threadPool.AwaitTermination(new TimeSpan(0, 0, 10)); for (var i = 0; i < numThreads; i++) { Assert.IsTrue((bool)future[i].GetValueOrDefault()); } // assert result for (var i = 0; i < numEvents - 1; i++) { Assert.AreEqual(1, listeners[i].NewDataList.Count, "Listener not invoked: #" + i); } }
/// <summary> /// Ctor. /// </summary> /// <param name="name">the factory name</param> /// <param name="stateless">if set to <c>true</c> [stateless].</param> /// <param name="msecWait">the number of milliseconds latches will await maximually</param> /// <param name="locking">the blocking strategy to employ</param> /// <param name="timeSourceService">time source provider</param> public InsertIntoLatchFactory( String name, bool stateless, long msecWait, ConfigurationEngineDefaults.ThreadingConfig.Locking locking, TimeSourceService timeSourceService) { _name = name; _msecWait = msecWait; _timeSourceService = timeSourceService; _stateless = stateless; _useSpin = (locking == ConfigurationEngineDefaults.ThreadingConfig.Locking.SPIN); // construct a completed latch as an initial root latch if (_useSpin) { _currentLatchSpin = new InsertIntoLatchSpin(this); } else { _currentLatchWait = new InsertIntoLatchWait(this); } }
public ExecNamedWindowOnUpdateWMultiDispatch(bool useDefault, bool?preserve, ConfigurationEngineDefaults.ThreadingConfig.Locking?locking) { this.useDefault = useDefault; this.preserve = preserve.GetValueOrDefault(); this.locking = locking.GetValueOrDefault(); }
/// <summary> /// Ctor. /// </summary> /// <param name="name">the factory name</param> /// <param name="enabled"></param> /// <param name="msecWait">the number of milliseconds latches will await maximually</param> /// <param name="locking">the blocking strategy to employ</param> /// <param name="timeSourceService">time source provider</param> /// <param name="initializenow"></param> public NamedWindowConsumerLatchFactory(string name, bool enabled, long msecWait, ConfigurationEngineDefaults.ThreadingConfig.Locking locking, TimeSourceService timeSourceService, bool initializenow) { Name = name; Enabled = enabled; MsecWait = msecWait; TimeSourceService = timeSourceService; UseSpin = enabled && (locking == ConfigurationEngineDefaults.ThreadingConfig.Locking.SPIN); // construct a completed latch as an initial root latch if (initializenow && UseSpin) { _currentLatchSpin = new NamedWindowConsumerLatchSpin(this); } else if (initializenow && enabled) { _currentLatchWait = new NamedWindowConsumerLatchWait(this); } }
private static IBlockingQueue <Runnable> MakeQueue(int?threadPoolTimerExecCapacity, ConfigurationEngineDefaults.ThreadingConfig.Locking blocking) { if ((threadPoolTimerExecCapacity == null) || (threadPoolTimerExecCapacity <= 0) || (threadPoolTimerExecCapacity == int.MaxValue)) { return(blocking == ConfigurationEngineDefaults.ThreadingConfig.Locking.SPIN ? (IBlockingQueue <Runnable>) new ImperfectBlockingQueue <Runnable>() : (IBlockingQueue <Runnable>) new LinkedBlockingQueue <Runnable>()); } return(blocking == ConfigurationEngineDefaults.ThreadingConfig.Locking.SPIN ? (IBlockingQueue <Runnable>) new ImperfectBlockingQueue <Runnable>(threadPoolTimerExecCapacity.Value) : (IBlockingQueue <Runnable>) new BoundBlockingQueue <Runnable>(threadPoolTimerExecCapacity.Value)); }
private void TrySendCountFollowedBy(int numThreads, int numEvents, ConfigurationEngineDefaults.ThreadingConfig.Locking locking) { Configuration config = SupportConfigFactory.GetConfiguration(); config.EngineDefaults.Threading.InsertIntoDispatchLocking = locking; config.EngineDefaults.Threading.InsertIntoDispatchTimeout = 5000; // 5 second timeout // This should fail all test in this class // config.EngineDefaults.Threading.InsertIntoDispatchPreserveOrder = false; EPServiceProvider engine = EPServiceProviderManager.GetProvider( SupportContainer.Instance, this.GetType().Name, config); engine.Initialize(); // setup statements EPStatement stmtInsert = engine.EPAdministrator.CreateEPL("insert into MyStream select count(*) as cnt from " + typeof(SupportBean).FullName); stmtInsert.Events += (sender, args) => Log.Debug(".update cnt=" + args.NewEvents[0].Get("cnt")); var listeners = new SupportUpdateListener[numEvents]; for (int i = 0; i < numEvents; i++) { string text = "select * from pattern [MyStream(cnt=" + (i + 1) + ") -> MyStream(cnt=" + (i + 2) + ")]"; EPStatement stmt = engine.EPAdministrator.CreateEPL(text); listeners[i] = new SupportUpdateListener(); stmt.Events += listeners[i].Update; } // execute var threadPool = Executors.NewFixedThreadPool(numThreads); var future = new Future <bool> [numThreads]; var sharedStartLock = SupportContainer.Instance.RWLockManager().CreateDefaultLock(); using (sharedStartLock.WriteLock.Acquire()) { for (int i = 0; i < numThreads; i++) { future[i] = threadPool.Submit( new SendEventRWLockCallable(i, sharedStartLock.WriteLock, engine, new GeneratorIterator(numEvents))); } Thread.Sleep(100); } threadPool.Shutdown(); threadPool.AwaitTermination(10, TimeUnit.SECONDS); for (int i = 0; i < numThreads; i++) { Assert.IsTrue(future[i].GetValueOrDefault()); } // assert result for (int i = 0; i < numEvents - 1; i++) { Assert.AreEqual(1, listeners[i].NewDataList.Count, "Listener not invoked: #" + i); } engine.Dispose(); }