public void Unload(string ruleId)
        {
            InternalValidate(ruleId);

            // check if the rule has associated module rules
            // NOTE this may need to be a checksum instead of the id
            if (LoadedModules.ContainsKey(ruleId))
            {
                LoadedModules[ruleId].UseCount--;

                if (LoadedModules[ruleId].UseCount <= 0)
                {
                    string id = LoadedModules[ruleId].Id;
                    _engine.EPAdministrator.DeploymentAdmin.Undeploy(id);
                    LoadedModules.Remove(ruleId);
                }
            }

            EPStatement statement = _engine.EPAdministrator.GetStatement(ruleId);

            if (statement == null)
            {
                return;
            }

            statement.Stop();
            statement.RemoveAllEventHandlers();
            statement.Dispose();
        }
Example #2
0
 private void Die()
 {
     _newLimitListener?.RemoveAllEventHandlers();
     _initialPriceListener?.RemoveAllEventHandlers();
     _lowPriceListener?.RemoveAllEventHandlers();
     _highPriceListener?.RemoveAllEventHandlers();
 }
Example #3
0
        public bool Call()
        {
            SupportMTUpdateListener listenerIsolated   = new SupportMTUpdateListener();
            SupportMTUpdateListener listenerUnisolated = new SupportMTUpdateListener();
            EPStatement             stmt = _engine.EPAdministrator.CreateEPL("select * from SupportBean");

            try
            {
                for (int i = 0; i < _loopCount; i++)
                {
                    EPServiceProviderIsolated isolated = _engine.GetEPServiceIsolated("i1");
                    isolated.EPAdministrator.AddStatement(stmt);

                    listenerIsolated.Reset();
                    stmt.Events += listenerIsolated.Update;
                    Object theEvent = new SupportBean();
                    //Console.Out.WriteLine("Sensing event : " + event + " by thread " + Thread.CurrentThread.ManagedThreadId);
                    isolated.EPRuntime.SendEvent(theEvent);
                    FindEvent(listenerIsolated, i, theEvent);
                    stmt.RemoveAllEventHandlers();

                    isolated.EPAdministrator.RemoveStatement(stmt);

                    stmt.Events += listenerUnisolated.Update;
                    theEvent     = new SupportBean();
                    _engine.EPRuntime.SendEvent(theEvent);
                    FindEvent(listenerUnisolated, i, theEvent);
                    stmt.RemoveAllEventHandlers();
                }
            }
            catch (Exception ex)
            {
                Log.Fatal("Error in thread " + _threadNum, ex);
                return(false);
            }
            return(true);
        }
Example #4
0
 private void Die()
 {
     if (_newLimitListener != null)
     {
         _newLimitListener.RemoveAllEventHandlers();
     }
     if (_initialPriceListener != null)
     {
         _initialPriceListener.RemoveAllEventHandlers();
     }
     if (_lowPriceListener != null)
     {
         _lowPriceListener.RemoveAllEventHandlers();
     }
     if (_highPriceListener != null)
     {
         _highPriceListener.RemoveAllEventHandlers();
     }
 }
        private void RunAssertionStatementStateChange()
        {
            EPServiceProvider stateChangeEngine = EPServiceProviderManager.GetProvider(
                SupportContainer.Instance, this.GetType().Name + "_statechange",
                SupportConfigFactory.GetConfiguration());
            EPServiceProviderSPI spi = (EPServiceProviderSPI)stateChangeEngine;

            var observer = new SupportStmtLifecycleObserver();

            spi.StatementLifecycleSvc.LifecycleEvent += observer.Observe;
            var listener = new SupportStatementStateListener();

            stateChangeEngine.StatementCreate      += listener.OnStatementCreate;
            stateChangeEngine.StatementStateChange += listener.OnStatementStateChange;

            EPStatement stmt = stateChangeEngine.EPAdministrator.CreateEPL("select * from " + typeof(SupportBean).FullName);

            Assert.AreEqual("CREATE;STATECHANGE;", observer.EventsAsString);
            Assert.AreEqual(stmt, listener.AssertOneGetAndResetCreatedEvents());
            Assert.AreEqual(stmt, listener.AssertOneGetAndResetStateChangeEvents());

            observer.Flush();
            stmt.Stop();
            Assert.AreEqual("STATECHANGE;", observer.EventsAsString);
            Assert.AreEqual(stmt.Name, observer.Events[0].Statement.Name);
            Assert.AreEqual(stmt, listener.AssertOneGetAndResetStateChangeEvents());

            observer.Flush();
            stmt.Events += (sender, args) => { };
            Assert.AreEqual("LISTENER_ADD;", observer.EventsAsString);
            Assert.IsNotNull(observer.LastContext);
            Assert.IsTrue(observer.LastContext[0] is UpdateEventHandler);

            observer.Flush();
            stmt.RemoveAllEventHandlers();
            Assert.AreEqual(StatementLifecycleEvent.LifecycleEventType.LISTENER_REMOVE_ALL.ToString() + ";", observer.EventsAsString);

            stmt.Dispose();
            Assert.AreEqual(stmt, listener.AssertOneGetAndResetStateChangeEvents());

            stateChangeEngine.Dispose();
        }
Example #6
0
        public MatchMakingMonitor(EPServiceProvider epService, MobileUserBean mobileUser, MatchAlertListener matchAlertListener)
        {
            _epService          = epService;
            _matchAlertListener = matchAlertListener;
            _mobileUserId       = mobileUser.UserId;

            // Create patterns that listen to other users
            SetupPatterns(mobileUser);

            // Listen to my own location changes so my data is up-to-date
            EPStatement locationChange = _epService.EPAdministrator.CreatePattern(
                "every myself=" + typeof(MobileUserBean).FullName +
                "(UserId=" + mobileUser.UserId + ")");

            locationChange.Events +=
                delegate(Object sender, UpdateEventArgs e) {
                // When my location changed, re-establish pattern
                _locateOther.RemoveAllEventHandlers();
                var myself = (MobileUserBean)e.NewEvents[0]["myself"];
                SetupPatterns(myself);
            };
        }
Example #7
0
        public void TestSimpleSelectUpdateOnly()
        {
            MySubscriberRowByRowSpecific subscriber = new MySubscriberRowByRowSpecific();
            EPStatement stmt = _epService.EPAdministrator.CreateEPL("select TheString, IntPrimitive from " + typeof(SupportBean).FullName + ".std:lastevent()");

            stmt.Subscriber = subscriber;

            // get statement, attach listener
            SupportUpdateListener listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            // send event
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 100));
            EPAssertionUtil.AssertEqualsExactOrder(new Object[][] { new Object[] { "E1", 100 } }, subscriber.GetAndResetIndicate());
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), _fields, new Object[][] { new Object[] { "E1", 100 } });
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), _fields, new Object[] { "E1", 100 });

            // remove listener
            stmt.RemoveAllEventHandlers();

            // send event
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 200));
            EPAssertionUtil.AssertEqualsExactOrder(new Object[][] { new Object[] { "E2", 200 } }, subscriber.GetAndResetIndicate());
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), _fields, new Object[][] { new Object[] { "E2", 200 } });
            Assert.IsFalse(listener.IsInvoked);

            // add listener
            SupportStmtAwareUpdateListener stmtAwareListener = new SupportStmtAwareUpdateListener();

            stmt.Events += stmtAwareListener.Update;

            // send event
            _epService.EPRuntime.SendEvent(new SupportBean("E3", 300));
            EPAssertionUtil.AssertEqualsExactOrder(new Object[][] { new Object[] { "E3", 300 } }, subscriber.GetAndResetIndicate());
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), _fields, new Object[][] { new Object[] { "E3", 300 } });
            EPAssertionUtil.AssertProps(stmtAwareListener.AssertOneGetNewAndReset(), _fields, new Object[] { "E3", 300 });
        }
        public void TestBothListeners()
        {
            String      stmtText  = "select * from Bean";
            EPStatement statement = epService.EPAdministrator.CreateEPL(stmtText);

            SupportStmtAwareUpdateListener[] awareListeners  = new SupportStmtAwareUpdateListener[3];
            SupportUpdateListener[]          updateListeners = new SupportUpdateListener[awareListeners.Length];
            for (int i = 0; i < awareListeners.Length; i++)
            {
                awareListeners[i]  = new SupportStmtAwareUpdateListener();
                statement.Events  += awareListeners[i].Update;
                updateListeners[i] = new SupportUpdateListener();
                statement.Events  += updateListeners[i].Update;
            }

            Object theEvent = new SupportBean();

            epService.EPRuntime.SendEvent(theEvent);
            for (int i = 0; i < awareListeners.Length; i++)
            {
                Assert.AreSame(theEvent, updateListeners[i].AssertOneGetNewAndReset().Underlying);
                Assert.AreSame(theEvent, awareListeners[i].AssertOneGetNewAndReset().Underlying);
            }

            statement.Events -= awareListeners[1].Update;
            theEvent          = new SupportBean();
            epService.EPRuntime.SendEvent(theEvent);
            for (int i = 0; i < awareListeners.Length; i++)
            {
                if (i == 1)
                {
                    Assert.AreSame(theEvent, updateListeners[i].AssertOneGetNewAndReset().Underlying);
                    Assert.IsFalse(awareListeners[i].IsInvoked);
                }
                else
                {
                    Assert.AreSame(theEvent, updateListeners[i].AssertOneGetNewAndReset().Underlying);
                    Assert.AreSame(theEvent, awareListeners[i].AssertOneGetNewAndReset().Underlying);
                }
            }

            statement.Events -= updateListeners[1].Update;
            theEvent          = new SupportBean();
            epService.EPRuntime.SendEvent(theEvent);
            for (int i = 0; i < awareListeners.Length; i++)
            {
                if (i == 1)
                {
                    Assert.IsFalse(updateListeners[i].IsInvoked);
                    Assert.IsFalse(awareListeners[i].IsInvoked);
                }
                else
                {
                    Assert.AreSame(theEvent, updateListeners[i].AssertOneGetNewAndReset().Underlying);
                    Assert.AreSame(theEvent, awareListeners[i].AssertOneGetNewAndReset().Underlying);
                }
            }

            statement.Events += updateListeners[1].Update;
            statement.Events += awareListeners[1].Update;
            theEvent          = new SupportBean();
            epService.EPRuntime.SendEvent(theEvent);
            for (int i = 0; i < awareListeners.Length; i++)
            {
                Assert.AreSame(theEvent, updateListeners[i].AssertOneGetNewAndReset().Underlying);
                Assert.AreSame(theEvent, awareListeners[i].AssertOneGetNewAndReset().Underlying);
            }

            statement.RemoveAllEventHandlers();
            for (int i = 0; i < awareListeners.Length; i++)
            {
                Assert.IsFalse(updateListeners[i].IsInvoked);
                Assert.IsFalse(awareListeners[i].IsInvoked);
            }
        }