public virtual void Watch(List <StreamManagerPool> p_Pools)
        {
            foreach (StreamManagerPool l_Pool in p_Pools)
            {
                try
                {
                    PoolWatcherPoolStatistic l_Statistic =
                        m_PoolStatistics.GetOrAdd(l_Pool, p_Pool => new PoolWatcherPoolStatistic(p_Pool));
                    PoolWatcherPoolState l_OldState = l_Statistic.State;
                    l_Statistic.UpdateState();
                    PoolWatcherPoolState l_NewState = l_Statistic.State;

                    if (l_OldState == l_NewState)
                    {
                        continue;
                    }

                    PoolStateChanged(l_Pool, l_OldState, l_NewState);
                }
                catch (Exception e)
                {
                    HandleError(l_Pool, e);
                }
            }
        }
Exemple #2
0
        private void RefreshLimitReached()
        {
            bool l_HasFreeBlocks = Pool.HasFreeBlocks();

            if (State.LimitReached == !l_HasFreeBlocks)
            {
                return;
            }

            State = new PoolWatcherPoolState(State.Trend, !l_HasFreeBlocks, Pool.GetBlocksInUse());
        }
Exemple #3
0
        protected override void PoolStateChanged(StreamManagerPool p_Statistic, PoolWatcherPoolState p_OldState,
                                                 PoolWatcherPoolState p_NewState)
        {
            PoolWatcherPoolStateChangedEvent l_Event = OnPoolStateChanged;

            if (l_Event == null)
            {
                return;
            }

            l_Event(this, new PoolWatcherPoolStateChangedEventArgs(p_Statistic, p_OldState, p_NewState));
        }
Exemple #4
0
 public PoolWatcherPoolStateChangedEventArgs(StreamManagerPool p_Pool, PoolWatcherPoolState p_OldState, PoolWatcherPoolState p_NewState)
 {
     Pool     = p_Pool;
     OldState = p_OldState;
     NewState = p_NewState;
 }
Exemple #5
0
        public void UpdateState()
        {
            lock (this)
            {
                int l_BlocksInUse = Pool.GetBlocksInUse();
                m_BlocksInUseHistory.Enqueue(l_BlocksInUse);

                // If Limit is reached remote a point
                if (m_BlocksInUseHistory.Count < CONST_MAX_QUEUE_SIZE)
                {
                    // We Call Only Status when queue is full
                    RefreshLimitReached();
                    return;
                }

                int l_Count = m_BlocksInUseHistory.Count;

                if (l_Count <= 1)
                {
                    return;
                }

                int    l_Pos         = 0;
                Double l_First       = 0;
                int    l_FirstCount  = 0;
                Double l_Second      = 0;
                int    l_SecondCount = 0;

                foreach (long l_DataPoint in m_BlocksInUseHistory)
                {
                    if (l_Pos < ((int)l_Count / 2))
                    {
                        l_First = l_First + l_DataPoint;
                        l_FirstCount++;
                    }
                    else
                    {
                        l_Second = l_Second + l_DataPoint;
                        l_SecondCount++;
                    }

                    l_Pos++;
                }


                Double l_FirstAvg  = l_First / l_FirstCount;
                Double l_SecondAvg = l_Second / l_SecondCount;

                int l_Diff = (int)(l_SecondAvg - l_FirstAvg);

                Double l_MinDiff = Pool.MaxBlockCount * CONST_PERCENT_CHANGE_FACTOR;

                if (Math.Abs(l_Diff) < l_MinDiff)
                {
                    l_Diff = 0;
                }

                if (l_Diff > 0)
                {
                    State = new PoolWatcherPoolState(PoolWatcherPoolTrend.Growing, !Pool.HasFreeBlocks(), Pool.GetBlocksInUse());
                }
                else
                if (l_Diff == 0)
                {
                    State = new PoolWatcherPoolState(PoolWatcherPoolTrend.NothingChanged, !Pool.HasFreeBlocks(), Pool.GetBlocksInUse());
                }
                else
                {
                    State = new PoolWatcherPoolState(PoolWatcherPoolTrend.Shrinking, !Pool.HasFreeBlocks(), Pool.GetBlocksInUse());
                }


                m_BlocksInUseHistory.Clear();
            }
        }
Exemple #6
0
 public PoolWatcherPoolStatistic(IPoolStateProvider p_Pool)
 {
     Pool = p_Pool;
     m_BlocksInUseHistory = new Queue <long>(CONST_MAX_QUEUE_SIZE);
     State = new PoolWatcherPoolState(PoolWatcherPoolTrend.NothingChanged, false, 0);
 }
 protected abstract void PoolStateChanged(StreamManagerPool p_Statistic,
                                          PoolWatcherPoolState p_OldState, PoolWatcherPoolState p_NewState);