/// <inheritdoc/>
        public void Polled(Object source, IoEvent ioe)
        {
            Int32 eventSize = EstimateSize(ioe);
            Int32 currentCounter = Interlocked.Add(ref _counter, -eventSize);

            if (log.IsDebugEnabled)
                log.Debug(Thread.CurrentThread.Name + " state: " + _counter + " / " + _threshold);

            if (currentCounter < _threshold)
                Unblock();
        }
        /// <inheritdoc/>
        public void Execute(IoEvent ioe)
        {
            Boolean offeredEvent = _queueHandler.Accept(this, ioe);
            if (offeredEvent)
            {
                Execute(() =>
                {
                    _queueHandler.Polled(this, ioe);
                    ioe.Fire();
                });

                _queueHandler.Offered(this, ioe);
            }
        }
Beispiel #3
0
        /// <inheritdoc/>
        public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
        {
            IoEvent ioe = new IoEvent(IoEventType.Write, session, writeRequest);
            if (_queueHandler.Accept(this, ioe))
            {
                nextFilter.FilterWrite(session, writeRequest);
                IWriteFuture writeFuture = writeRequest.Future;
                if (writeFuture == null)
                    return;

                // We can track the write request only when it has a future.
                _queueHandler.Offered(this, ioe);
                writeFuture.Complete += (s, e) => _queueHandler.Polled(this, ioe);
            }
        }
        /// <inheritdoc/>
        public void Execute(IoEvent ioe)
        {
            IoSession session = ioe.Session;
            SessionTasksQueue sessionTasksQueue = GetSessionTasksQueue(session);
            Boolean exec;

            // propose the new event to the event queue handler. If we
            // use a throttle queue handler, the message may be rejected
            // if the maximum size has been reached.
            Boolean offerEvent = _queueHandler.Accept(this, ioe);

            if (offerEvent)
            {
                lock (sessionTasksQueue.syncRoot)
                {
                    sessionTasksQueue.tasksQueue.Enqueue(ioe);

                    if (sessionTasksQueue.processingCompleted)
                    {
                        sessionTasksQueue.processingCompleted = false;
                        exec = true;
                    }
                    else
                    {
                        exec = false;
                    }

                    if (log.IsDebugEnabled)
                        Print(sessionTasksQueue.tasksQueue, ioe);
                }

                if (exec)
                {
                    Execute(() =>
                    {
                        RunTasks(sessionTasksQueue);
                    });
                }

                _queueHandler.Offered(this, ioe);
            }
        }
 public Int32 EstimateSize(IoEvent ioe)
 {
     return EstimateSize((Object)ioe) + EstimateSize(ioe.Parameter);
 }
 /// <inheritdoc/>
 public Boolean Accept(Object source, IoEvent ioe)
 {
     return true;
 }
 private Int32 EstimateSize(IoEvent ioe)
 {
     Int32 size = _sizeEstimator.EstimateSize(ioe);
     if (size < 0)
         throw new InvalidOperationException(_sizeEstimator.GetType().Name + " returned "
                 + "a negative value (" + size + "): " + ioe);
     return size;
 }
 public void Polled(Object source, IoEvent ioe)
 {
     // NOOP
 }
 public void Offered(Object source, IoEvent ioe)
 {
     // NOOP
 }
        private void Print(ConcurrentQueue<IoEvent> queue, IoEvent ioe)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Adding event ")
                .Append(ioe.EventType)
                .Append(" to session ")
                .Append(ioe.Session.Id);
            Boolean first = true;
            sb.Append("\nQueue : [");
            foreach (IoEvent elem in queue)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(", ");
                }

                sb.Append(((IoEvent)elem).EventType).Append(", ");
            }
            sb.Append("]\n");
            log.Debug(sb.ToString());
        }