Пример #1
0
                public void OnSubscribe(IDisposable d)
                {
                    if (DisposableHelper.SetOnce(ref upstream, d))
                    {
                        if (d is IFuseableDisposable <T> fd)
                        {
                            var m = fd.RequestFusion(FusionSupport.AnyBoundary);

                            if (m == FusionSupport.Sync)
                            {
                                fusionMode = m;
                                Volatile.Write(ref queue, fd);
                                SetDone();
                                parent.Drain();
                                return;
                            }
                            if (m == FusionSupport.Async)
                            {
                                fusionMode = m;
                                Volatile.Write(ref queue, fd);
                                return;
                            }
                        }

                        queue = new SpscLinkedArrayQueue <T>(parent.capacityHint);
                    }
                }
Пример #2
0
 internal static void Clear <T>(ISimpleQueue <T> q)
 {
     while (q.Poll(out T item) && !q.IsEmpty())
     {
         ;
     }
 }
            public void OnSubscribe(IDisposable d)
            {
                upstream = d;
                if (d is IFuseableDisposable<T> f)
                {
                    var m = f.RequestFusion(FusionSupport.Any);

                    if (m == FusionSupport.Sync)
                    {
                        sourceFused = true;
                        this.queue = f;
                        Volatile.Write(ref done, true);
                        downstream.OnSubscribe(this);
                        Drain();
                        return;
                    }
                    if (m == FusionSupport.Async)
                    {
                        sourceFused = true;
                        this.queue = f;
                        downstream.OnSubscribe(this);
                        return;
                    }
                }

                queue = new SpscLinkedArrayQueue<T>(capacityHint);
                downstream.OnSubscribe(this);
            }
Пример #4
0
            internal void InnerNext(FlatMapInnerSubscriber inner, R item)
            {
                if (Volatile.Read(ref wip) == 0 && Interlocked.CompareExchange(ref wip, 1, 0) == 0)
                {
                    long e = emitted;
                    if (Volatile.Read(ref requested) != e)
                    {
                        actual.OnNext(item);
                        emitted = e + 1;
                        inner.Request(1);
                    }
                    else
                    {
                        ISimpleQueue <R> q = inner.GetOrCreateQueue();
                        q.Offer(item);
                    }
                    if (Interlocked.Decrement(ref wip) == 0)
                    {
                        return;
                    }
                }
                else
                {
                    ISimpleQueue <R> q = inner.GetOrCreateQueue();
                    q.Offer(item);
                    if (Interlocked.Increment(ref wip) != 1)
                    {
                        return;
                    }
                }

                DrainLoop();
            }
Пример #5
0
            public void OnSubscribe(ISubscription subscription)
            {
                if (SubscriptionHelper.Validate(ref upstream, subscription))
                {
                    if (subscription is IQueueSubscription <T> qs)
                    {
                        int m = qs.RequestFusion(FusionSupport.ANY);
                        if (m == FusionSupport.SYNC)
                        {
                            fusionMode = m;
                            queue      = qs;
                            Volatile.Write(ref done, true);

                            actual.OnSubscribe(this);
                            return;
                        }
                        if (m == FusionSupport.ASYNC)
                        {
                            fusionMode = m;
                            queue      = qs;

                            actual.OnSubscribe(this);

                            subscription.Request(prefetch);
                            return;
                        }
                    }

                    queue = new SpscArrayQueue <T>(prefetch);

                    actual.OnSubscribe(this);

                    subscription.Request(prefetch);
                }
            }
Пример #6
0
 public static void Init(string apiKey, ISimpleQueue queueImpl)
 {
     _apiKey = apiKey;
     _queue = queueImpl;
     RegisterType(new ObservationType("Common.TimedAction", "Time taken for a custom action to occur", "Custom Action Time", "ms"));
     RegisterType(new ObservationType("Common.Heartbeat", "Heartbeat of a given lifeforce", "Heartbeats should occur at regular intervals", String.Empty));
 }
Пример #7
0
 internal AbstractRunOnSubscriber(int bufferSize, IExecutorWorker worker)
 {
     this.bufferSize = bufferSize;
     this.worker     = worker;
     this.limit      = bufferSize - (bufferSize >> 2);
     this.queue      = new SpscArrayQueue <T>(bufferSize);
     this.run        = Drain;
 }
Пример #8
0
        // 订单队列
        //  private static BlockingCollection<string> _requestOrderQueue = new BlockingCollection<string>();


        public PosSyncController(IPosSyncQuery query, IPosSyncFacade posFacade, ILogger log, IAccessTokenFacade accessTokenFacade, ISimpleQueue <string> isaleQueue)
        {
            _posQuery          = query;
            _posFacade         = posFacade;
            _log               = log;
            _accessTokenFacade = accessTokenFacade;
            _saleQueue         = isaleQueue;
        }
 public HiLowBuffer(
     int sizeHint,
     Action <T> onNext,
     ISimpleQueue <T> lowPriorityQueue)
     : base(sizeHint, onNext)
 {
     _lowPriorityQueue = lowPriorityQueue;
 }
 internal BufferBoundarySubscriber(IFlowableSubscriber <C> actual, C buffer, Func <C> bufferSupplier)
 {
     this.actual         = actual;
     this.buffer         = buffer;
     this.bufferSupplier = bufferSupplier;
     this.boundary       = new BoundarySubscriber(this);
     this.queue          = new SpscLinkedArrayQueue <C>(16);
 }
 internal WindowSizeOverlapSubscriber(IFlowableSubscriber <IFlowable <T> > actual, int size, int skip)
 {
     this.actual  = actual;
     this.size    = size;
     this.skip    = skip;
     this.active  = 1;
     this.queue   = new ArrayQueue <UnicastProcessor <T> >();
     this.windows = new SpscLinkedArrayQueue <UnicastProcessor <T> >(Flowable.BufferSize());
 }
Пример #12
0
 internal ScanWithSubscriber(IFlowableSubscriber <R> actual, R initial, Func <R, T, R> scanner, int bufferSize)
 {
     this.actual      = actual;
     this.scanner     = scanner;
     this.bufferSize  = bufferSize;
     this.limit       = bufferSize - (bufferSize >> 2);
     this.queue       = new SpscArrayQueue <R>(bufferSize);
     this.accumulator = initial;
     this.queue.Offer(initial);
 }
 internal GroupBySubscriber(IFlowableSubscriber <IGroupedFlowable <K, V> > actual, Func <T, K> keySelector, Func <T, V> valueSelector, int bufferSize)
 {
     this.actual        = actual;
     this.keySelector   = keySelector;
     this.valueSelector = valueSelector;
     this.groups        = new ConcurrentDictionary <K, GroupedFlowable>();
     this.bufferSize    = bufferSize;
     this.active        = 1;
     this.queue         = new SpscLinkedArrayQueue <GroupedFlowable>(bufferSize);
 }
Пример #14
0
 internal WindowBoundarySubscriber(IFlowableSubscriber <IFlowable <T> > actual, int bufferSize)
 {
     this.actual     = actual;
     this.active     = 1;
     this.queue      = new SpscLinkedArrayQueue <IFlowable <T> >(16);
     this.terminate  = OnTerminate;
     this.bufferSize = bufferSize;
     this.buffer     = new UnicastProcessor <T>(bufferSize, terminate);
     this.boundary   = new BoundarySubscriber(this);
     queue.Offer(buffer);
 }
Пример #15
0
                internal ISimpleQueue <R> GetOrCreateQueue()
                {
                    ISimpleQueue <R> q = Volatile.Read(ref queue);

                    if (q == null)
                    {
                        q = new SpscArrayQueue <R>(bufferSize);
                        Volatile.Write(ref queue, q);
                    }
                    return(q);
                }
Пример #16
0
        internal static void QueueDrainFused <T>(IFlowableSubscriber <T> a,
                                                 ref int wip, ISimpleQueue <T> q, ref bool cancelled, ref bool done, ref Exception error)
        {
            if (Interlocked.Increment(ref wip) != 1)
            {
                return;
            }

            int missed = 1;

            for (;;)
            {
                if (Volatile.Read(ref cancelled))
                {
                    q.Clear();
                    return;
                }
                bool d     = Volatile.Read(ref done);
                bool empty = q.IsEmpty();

                if (!empty)
                {
                    a.OnNext(default(T));
                }

                if (d)
                {
                    var ex = error;
                    if (ex == null)
                    {
                        a.OnComplete();
                    }
                    else
                    {
                        a.OnError(ex);
                    }
                }

                int w = Volatile.Read(ref wip);
                if (w == missed)
                {
                    missed = Interlocked.Add(ref wip, -missed);
                    if (missed == 0)
                    {
                        break;
                    }
                }
                else
                {
                    missed = w;
                }
            }
        }
Пример #17
0
            void DrainFused()
            {
                int missed = 1;

                IFlowableSubscriber <T> a = actual;
                ISimpleQueue <T>        q = queue;

                for (;;)
                {
                    if (Volatile.Read(ref cancelled))
                    {
                        q.Clear();
                        return;
                    }

                    bool d     = Volatile.Read(ref done);
                    bool empty = q.IsEmpty();

                    if (!empty)
                    {
                        a.OnNext(default(T));
                    }

                    if (d)
                    {
                        Exception ex = error;
                        if (ex != null)
                        {
                            a.OnError(ex);
                        }
                        else
                        {
                            a.OnComplete();
                        }
                        return;
                    }

                    int w = Volatile.Read(ref wip);
                    if (w == missed)
                    {
                        missed = Interlocked.Add(ref wip, -missed);
                        if (missed == 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        missed = w;
                    }
                }
            }
Пример #18
0
            internal CombineLatestSubscription(IFlowableSubscriber <R> actual, Func <T[], R> combiner, int n, int prefetch)
            {
                this.actual   = actual;
                this.combiner = combiner;
                latest        = new T[n];
                var s = new CombineLatestSubscriber[n];

                for (int i = 0; i < n; i++)
                {
                    s[i] = new CombineLatestSubscriber(this, i, prefetch);
                }
                this.subscribers = s;
                this.queue       = new SpscLinkedArrayQueue <Entry>(prefetch);
            }
Пример #19
0
        static QueueHelper()
        {
            _queueType = GetQueueType();
            switch (_queueType)
            {
            case 1:
                _queue = new RabbitQueue();
                break;

            case 2:
                _queue = new WcfQueue();
                break;

            default:
                throw new BusinessLogicException("队列类型配置错误");
            }
        }
            public void OnSubscribe(ISubscription subscription)
            {
                if (SubscriptionHelper.Validate(ref upstream, subscription))
                {
                    if (subscription is IQueueSubscription <T> qs)
                    {
                        int m = qs.RequestFusion(FusionSupport.ANY | FusionSupport.BARRIER);
                        if (m == FusionSupport.SYNC)
                        {
                            fusionMode = m;
                            queue      = qs;
                            Volatile.Write(ref done, true);

                            InitRails();
                            Drain();
                            return;
                        }

                        if (m == FusionSupport.ASYNC)
                        {
                            fusionMode = m;
                            queue      = qs;

                            InitRails();

                            subscription.Request(bufferSize);
                            return;
                        }
                    }

                    queue = new SpscArrayQueue <T>(bufferSize);

                    InitRails();

                    subscription.Request(bufferSize);
                }
            }
 internal GroupedFlowable(K key, int bufferSize, GroupBySubscriber parent)
 {
     this.key    = key;
     this.parent = parent;
     this.queue  = new SpscArrayQueue <V>(bufferSize);
 }
Пример #22
0
 internal FromObserverBuffer(IFlowableSubscriber <T> actual)
 {
     this.actual = actual;
     this.queue  = new SpscLinkedArrayQueue <T>(Flowable.BufferSize());
 }
Пример #23
0
 /// <summary>
 /// Constructs an UnicastProcessor with the given buffer size
 /// and termination action (called at most once on a terminal event
 /// or when the single subscriber cancels).
 /// </summary>
 /// <param name="bufferSize">The island size of the internal unbounded buffer.</param>
 /// <param name="onTerminate">The action called when this UnicastProcessor
 /// receives a terminal event or cancellation.</param>
 public UnicastProcessor(int bufferSize, Action onTerminate)
 {
     this.bufferSize = bufferSize;
     this.queue      = new SpscLinkedArrayQueue <T>(bufferSize);
     Volatile.Write(ref this.onTerminate, onTerminate);
 }
 public AbstractOnBackpressureBufferAll(int capacityHint)
 {
     queue = new SpscLinkedArrayQueue <T>(capacityHint);
 }
Пример #25
0
 internal BlockingQueueConsumer(int capacityHint, string name, bool daemon = true)
 {
     this.queue  = new MpscLinkedArrayQueue <Action>(capacityHint);
     this.daemon = daemon;
     this.name   = name;
 }
Пример #26
0
            void DrainLoop()
            {
                IFlowableSubscriber <R> a = actual;
                int  missed = 1;
                long e      = emitted;

                for (;;)
                {
                    if (Volatile.Read(ref cancelled) != 0)
                    {
                        return;
                    }
                    bool again = false;
                    bool d     = Volatile.Read(ref done);
                    FlatMapInnerSubscriber[] s = Volatile.Read(ref subscribers);
                    int n = s.Length;

                    if (d && n == 0)
                    {
                        Exception ex = ExceptionHelper.Terminate(ref error);
                        if (ex == null)
                        {
                            a.OnComplete();
                        }
                        else
                        {
                            a.OnError(ex);
                        }
                        return;
                    }

                    long r = Volatile.Read(ref requested);

                    if (n != 0)
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (Volatile.Read(ref cancelled) != 0)
                            {
                                return;
                            }
                            if (r == e)
                            {
                                break;
                            }

                            var inner = s[i];

                            bool             innerDone  = Volatile.Read(ref inner.done);
                            ISimpleQueue <R> q          = Volatile.Read(ref inner.queue);
                            bool             innerEmpty = q == null || q.IsEmpty();

                            if (innerDone && innerEmpty)
                            {
                                Remove(inner);
                                upstream.Request(1);
                                again = true;
                            }
                            else
                            if (!innerEmpty)
                            {
                                while (e != r)
                                {
                                    if (Volatile.Read(ref cancelled) != 0)
                                    {
                                        return;
                                    }
                                    innerDone  = Volatile.Read(ref inner.done);
                                    innerEmpty = !q.Poll(out R item);

                                    if (innerDone && innerEmpty)
                                    {
                                        Remove(inner);
                                        upstream.Request(1);
                                        again = true;
                                        break;
                                    }

                                    if (innerEmpty)
                                    {
                                        break;
                                    }

                                    a.OnNext(item);

                                    e++;
                                    inner.Request(1);
                                }

                                if (e == r)
                                {
                                    if (Volatile.Read(ref cancelled) != 0)
                                    {
                                        return;
                                    }
                                    innerDone  = Volatile.Read(ref inner.done);
                                    innerEmpty = q.IsEmpty();
                                    if (innerDone && innerEmpty)
                                    {
                                        Remove(inner);
                                        upstream.Request(1);
                                        again = true;
                                    }
                                }
                            }
                        }
                    }

                    if (e == r)
                    {
                        d = Volatile.Read(ref done);
                        s = Volatile.Read(ref subscribers);
                        n = s.Length;

                        if (d && n == 0)
                        {
                            Exception ex = ExceptionHelper.Terminate(ref error);
                            if (ex == null)
                            {
                                a.OnComplete();
                            }
                            else
                            {
                                a.OnError(ex);
                            }
                            return;
                        }
                    }

                    if (again)
                    {
                        continue;
                    }
                    int w = Volatile.Read(ref wip);
                    if (w == missed)
                    {
                        emitted = e;
                        missed  = Interlocked.Add(ref wip, -missed);
                        if (missed == 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        missed = w;
                    }
                }
            }
Пример #27
0
 /// <summary>
 /// Create new instance nased on result storage and configuration provider.
 /// </summary>
 /// <param name="sq">Storage result.</param>
 /// <param name="qc">Configuration provider.</param>
 public MagicQueue(ISimpleQueue sq, IMagicQueueConfiguration qc)
     : base(sq, qc)
 {
 }
Пример #28
0
 /// <summary>
 /// Create new instance nased on result storage and configuration provider.
 /// </summary>
 /// <param name="sq">Storage result.</param>
 /// <param name="qc">Configuration provider.</param>
 protected BaseMagicQueue(ISimpleQueue sq, IMagicQueueConfiguration qc)
 {
     Qc = qc;
     Sq = sq;
 }
Пример #29
0
            void DrainAsync()
            {
                int  missed = 1;
                long e      = emitted;
                int  f      = consumed;
                int  lim    = limit;
                IFlowableSubscriber <T> a = actual;
                ISimpleQueue <T>        q = queue;

                for (;;)
                {
                    long r = Volatile.Read(ref requested);

                    while (e != r)
                    {
                        if (Volatile.Read(ref cancelled))
                        {
                            q.Clear();
                            return;
                        }

                        bool d     = Volatile.Read(ref done);
                        bool empty = !q.Poll(out T item);

                        if (d && empty)
                        {
                            Exception ex = error;
                            if (ex != null)
                            {
                                a.OnError(ex);
                            }
                            else
                            {
                                a.OnComplete();
                            }
                            return;
                        }

                        if (empty)
                        {
                            break;
                        }

                        a.OnNext(item);

                        e++;

                        if (++f == lim)
                        {
                            f = 0;
                            upstream.Request(lim);
                        }
                    }

                    if (e == r)
                    {
                        if (Volatile.Read(ref cancelled))
                        {
                            q.Clear();
                            return;
                        }

                        bool d     = Volatile.Read(ref done);
                        bool empty = q.IsEmpty();

                        if (d && empty)
                        {
                            Exception ex = error;
                            if (ex != null)
                            {
                                a.OnError(ex);
                            }
                            else
                            {
                                a.OnComplete();
                            }
                            return;
                        }
                    }

                    int w = Volatile.Read(ref wip);
                    if (w == missed)
                    {
                        emitted  = e;
                        consumed = f;
                        missed   = Interlocked.Add(ref wip, -missed);
                        if (missed == 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        missed = w;
                    }
                }
            }
Пример #30
0
 /// <summary>
 /// Create new instance nased on result storage and configuration provider.
 /// </summary>
 /// <param name="sq">Storage result.</param>
 /// <param name="qc">Configuration provider.</param>
 protected BaseMagicQueue(ISimpleQueue sq, IMagicQueueConfiguration qc)
 {
     Qc = qc;
     Sq = sq;
 }
Пример #31
0
 /// <summary>
 /// Create new instance nased on result storage and configuration provider.
 /// </summary>
 /// <param name="sq">Storage result.</param>
 /// <param name="qc">Configuration provider.</param>
 public MagicQueue(ISimpleQueue sq, IMagicQueueConfiguration qc) : base(sq, qc)
 {
 }
 public HighCapacityBuffer(int sizeHint, ILogger logger, Action <T> onNext, ISimpleQueue <T> lowPriorityQueue)
     : base(sizeHint, logger, onNext)
 {
     this.lowPriorityQueue = lowPriorityQueue;
 }
 public BufferFlowableEmitter(IFlowableSubscriber <T> actual, int capacityHint) : base(actual)
 {
     queue = new SpscLinkedArrayQueue <T>(capacityHint);
 }