Java Code Examples for rx.internal.operators.BackpressureUtils

The following examples show how to use rx.internal.operators.BackpressureUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: rxjava-extras   Source File: OnSubscribeRepeating.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void request(long n) {
    if (n < 0) {
        throw new IllegalArgumentException("reuest must be >=0");
    } else if (n == 0) {
        return;
    } else if (BackpressureUtils.getAndAddRequest(this, n) == 0) {
        long requested = n;
        long emitted = 0;
        do {
            emitted = requested;
            while (requested-- > 0 && !subscriber.isUnsubscribed()) {
                subscriber.onNext(v);
            }
        } while ((requested = this.addAndGet(-emitted)) > 0);
    }
}
 
Example 2
Source Project: titus-control-plane   Source File: ValueGenerator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void request(long n) {
    if (n > 0) {
        BackpressureUtils.getAndAddRequest(requested, n);
        worker.schedule(this::drain);
    }
}
 
Example 3
Source Project: titus-control-plane   Source File: DefaultRxEventBus.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void request(long n) {
    if (n > 0) {
        BackpressureUtils.getAndAddRequest(requested, n);
        drain();
    }
}
 
Example 4
Source Project: rxjava-extras   Source File: OnSubscribeMatch.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void request(long n) {
    if (BackpressureUtils.validate(n)) {
        BackpressureUtils.getAndAddRequest(requested, n);
        drain();
    }
}
 
Example 5
Source Project: rxjava-extras   Source File: OperatorBufferToFile.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void request(long n) {
    if (n > 0) {
        BackpressureUtils.getAndAddRequest(this, n);
        drain();
    }
}
 
Example 6
@Override
public void request(long n) {
    if (n < 0) {
        throw new IllegalArgumentException();
    }
    if (n == 0) {
        return;
    }
    if (BackpressureUtils.getAndAddRequest(requested, n) != 0) {
        return;
    }
    execute(this::produce);
}
 
Example 7
Source Project: rxjava-extras   Source File: OrderedMerge.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void request(long n) {
    BackpressureUtils.getAndAddRequest(this, n);
    emit();
}
 
Example 8
Source Project: rxjava-extras   Source File: OperatorBufferToFile.java    License: Apache License 2.0 4 votes vote down vote up
private void drainNow() {
    if (child.isUnsubscribed()) {
        // leave drainRequested > 0 to prevent more
        // scheduling of drains
        return;
    }
    // get the number of unsatisfied requests
    long requests = get();

    for (;;) {
        // reset drainRequested counter
        drainRequested.set(1);
        long emitted = 0;
        while (emitted < requests) {
            if (child.isUnsubscribed()) {
                // leave drainRequested > 0 to prevent more
                // scheduling of drains
                return;
            }
            T item = queue.poll();
            if (item == null) {
                // queue is empty
                if (finished()) {
                    return;
                } else {
                    // another drain was requested so go
                    // round again but break out of this
                    // while loop to the outer loop so we
                    // can update requests and reset drainRequested
                    break;
                }
            } else {
                // there was an item on the queue
                if (NullSentinel.isNullSentinel(item)) {
                    child.onNext(null);
                } else {
                    child.onNext(item);
                }
                emitted++;
            }
        }
        // update requests with emitted value and any new requests
        requests = BackpressureUtils.produced(this, emitted);
        if (child.isUnsubscribed() || (requests == 0L && finished())) {
            return;
        }
    }
}
 
Example 9
Source Project: hawkular-metrics   Source File: SortedMerge.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void request(long n) {
    BackpressureUtils.getAndAddRequest(this, n);
    emit();
}