rx.internal.operators.BackpressureUtils Java Examples

The following examples show how to use rx.internal.operators.BackpressureUtils. 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 File: OnSubscribeRepeating.java    From rxjava-extras with 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 File: ValueGenerator.java    From titus-control-plane with 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 File: DefaultRxEventBus.java    From titus-control-plane with 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 File: OnSubscribeMatch.java    From rxjava-extras with 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 File: OperatorBufferToFile.java    From rxjava-extras with 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
Source File: ResultSetToRowsTransformer.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
@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 File: OrderedMerge.java    From rxjava-extras with Apache License 2.0 4 votes vote down vote up
@Override
public void request(long n) {
    BackpressureUtils.getAndAddRequest(this, n);
    emit();
}
 
Example #8
Source File: OperatorBufferToFile.java    From rxjava-extras with 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 File: SortedMerge.java    From hawkular-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public void request(long n) {
    BackpressureUtils.getAndAddRequest(this, n);
    emit();
}