public static EventDistributor GetInstance()
 {
     if (instance == null)
     {
         instance = new EventDistributor();
     }
     return(instance);
 }
        protected void Init()
        {
            EventType[] acceptedEventTypeList = { EventType.NewTupleArrive, EventType.NoMoreTuple, EventType.InlierBecomeOutlier, EventType.OutlierBecomeInlier, EventType.WindowSlide, EventType.OldTupleDepart };
            EventDistributor.GetInstance().SubcribeListenerWithFullAcceptedTypeList(this, acceptedEventTypeList);

            processedTupleCount               = 0;
            outlierHistoryCount               = 0;
            avgOutlierRateAgainstWindowSize   = 0;
            totalOutlierRateAgainstWindowSize = 0;
            windowSlideCount             = 0;
            windowSize                   = 0;
            outliersCountInCurrentWindow = 0;
            OutlierIndexList             = new List <int>();
        }
 public void StartSimulationInTimerMode()
 {
     if (!isRunningTimerMode)
     {
         simulateTimer.Change(0, _periodTimeBetweenTuple);
         Console.WriteLine("Timer Start");
         Thread.Sleep(10);
         tupleHandleThread.Start();
         isRunningTimerMode = true;
     }
     else
     {
         Event e = new Event(GetType().ToString(), EventType.Informative);
         e.AddAttribute(EventAttributeType.Message, "Already running in timer mode");
         EventDistributor.GetInstance().SendEvent(e);
     }
 }
        public void StopTimerModeSimulation()
        {
            if (isRunningTimerMode)
            {
                //To-do 实现停止Timer
                simulateTimer.Change(Timeout.Infinite, _periodTimeBetweenTuple);
                //To-do 重新恢复初始化时各个组件状态(如状态变量、DataAdapter的文件指针等)
                ResetState();

                isRunningTimerMode = false;
            }
            else
            {
                Event e = new Event(GetType().ToString(), EventType.Informative);
                e.AddAttribute(EventAttributeType.Message, "Simulation is not running in timer mode right now");
                EventDistributor.GetInstance().SendEvent(e);
            }
        }
        /// <summary>
        /// 对变量初始化,在EventDistributor注册listener等工作
        /// 同时也负责reset工作
        /// </summary>
        public void Initialize()
        {
            _curStreamStep = 0;
            _isProcessOver = false;

            _periodTimeBetweenTuple       = 1000;
            millisecondsTimeoutOfWaitLock = _periodTimeBetweenTuple;

            simulateTimer     = new Timer(new TimerCallback(TimerThreadFunc), this, Timeout.Infinite, _periodTimeBetweenTuple);
            tupleHandleThread = new Thread(TupleProcessorThreadFunc);

            if (ToDoBuffer != null && ToDoBuffer.Count != 0)
            {
                ToDoBuffer.Clear();
            }

            //StreamSimulator需要NoMoreTuple来停止Timer继续向dataAdapter索要Tuple
            EventType[] acceptedEventTypeList = { EventType.NoMoreTuple };
            EventDistributor.GetInstance().SubcribeListenerWithFullAcceptedTypeList(this, acceptedEventTypeList);
        }