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

            Debug.WriteLine(Thread.CurrentThread.Name + " state: " + _counter + " / " + _threshold);

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

                _queueHandler.Offered(this, ioe);
            }
        }
Пример #3
0
        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);
            }
        }
 public void Polled(Object source, IoEvent ioe)
 {
     // NOOP
 }
 public void Offered(Object source, IoEvent ioe)
 {
     // NOOP
 }
 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;
 }