io.reactivex.internal.subscriptions.EmptySubscription Java Examples

The following examples show how to use io.reactivex.internal.subscriptions.EmptySubscription. 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: FlowableCollector.java    From smallrye-reactive-streams-operators with Apache License 2.0 6 votes vote down vote up
@Override
protected void subscribeActual(Subscriber<? super R> s) {
    A initialValue;
    BiConsumer<A, T> accumulator;
    Function<A, R> finisher;

    try {
        initialValue = collector.supplier().get();
        accumulator = collector.accumulator();
        finisher = collector.finisher();
    } catch (Exception ex) {
        source.subscribe(new CancellationSubscriber<>());
        EmptySubscription.error(ex, s);
        return;
    }

    source.subscribe(new CollectorSubscriber<>(s, initialValue, accumulator, finisher));
}
 
Example #2
Source File: ResourceFlowableIterable.java    From akarnokd-misc with Apache License 2.0 6 votes vote down vote up
@Override
protected void subscribeActual(Subscriber<? super T> subscriber) {
    Iterator<? extends T> it;
    boolean b;
    try {
        it = items.iterator();

        b = it.hasNext();
    } catch (Throwable ex) {
        Exceptions.throwIfFatal(ex);
        EmptySubscription.error(ex, subscriber);
        return;
    }

    if (!b) {
        EmptySubscription.complete(subscriber);
        return;
    }

    subscriber.onSubscribe(new RFIteratorSubscription<>(subscriber, release, it));
}
 
Example #3
Source File: ParallelFlowableLife.java    From rxjava-RxLife with Apache License 2.0 5 votes vote down vote up
private boolean validate(@NonNull Subscriber<?>[] subscribers) {
    int p = parallelism();
    if (subscribers.length != p) {
        Throwable iae = new IllegalArgumentException("parallelism = " + p + ", subscribers = " + subscribers.length);
        for (Subscriber<?> s : subscribers) {
            EmptySubscription.error(iae, s);
        }
        return false;
    }
    return true;
}
 
Example #4
Source File: OnErrorResumeWithSubscriber.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
    if (!(s instanceof EmptySubscription)) {
        arbiter.setSubscription(s);
    }
    // else the subscription has already been cancelled, and so we must not subscribe to
    // be compliant with Reactive Streams.
}
 
Example #5
Source File: SomeAsyncApiBridge.java    From akarnokd-misc with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Subscriber<? super T> s) {
    if (once.compareAndSet(false, true)) {
        SomeAsyncApiBridgeSubscription<T> parent = new SomeAsyncApiBridgeSubscription<>(s, apiInvoker);
        s.onSubscribe(parent);
        parent.moveNext();
    } else {
        EmptySubscription.error(new IllegalStateException("Only one Subscriber allowed"), s);
    }
}
 
Example #6
Source File: ResourceFlowableDefer.java    From akarnokd-misc with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Subscriber<? super T> subscriber) {
    ResourceFlowable<T> rf;

    try {
        rf = call.call();
    } catch (Throwable ex) {
        Exceptions.throwIfFatal(ex);
        EmptySubscription.error(ex, subscriber);
        return;
    }

    rf.subscribe(subscriber);
}
 
Example #7
Source File: FlowableCircuitBreaker.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Subscriber<? super T> downstream) {
    if (circuitBreaker.tryAcquirePermission()) {
        upstream.subscribe(new CircuitBreakerSubscriber(downstream));
    } else {
        downstream.onSubscribe(EmptySubscription.INSTANCE);
        downstream.onError(createCallNotPermittedException(circuitBreaker));
    }
}
 
Example #8
Source File: FlowableBulkhead.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Subscriber<? super T> downstream) {
    if (bulkhead.tryAcquirePermission()) {
        upstream.subscribe(new BulkheadSubscriber(downstream));
    } else {
        downstream.onSubscribe(EmptySubscription.INSTANCE);
        downstream.onError(BulkheadFullException.createBulkheadFullException(bulkhead));
    }
}
 
Example #9
Source File: FlowableRateLimiter.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Subscriber<? super T> downstream) {
    long waitDuration = rateLimiter.reservePermission();
    if (waitDuration >= 0) {
        if (waitDuration > 0) {
            Completable.timer(waitDuration, TimeUnit.NANOSECONDS)
                .subscribe(() -> upstream.subscribe(new RateLimiterSubscriber(downstream)));
        } else {
            upstream.subscribe(new RateLimiterSubscriber(downstream));
        }
    } else {
        downstream.onSubscribe(EmptySubscription.INSTANCE);
        downstream.onError(createRequestNotPermitted(rateLimiter));
    }
}
 
Example #10
Source File: FlowableReadStream.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Subscriber<? super U> subscriber) {

  Subscription sub = new Subscription() {
    @Override
    public void request(long l) {
      if (current.get() == this) {
        stream.fetch(l);
      }
    }

    @Override
    public void cancel() {
      release();
    }
  };
  if (!current.compareAndSet(null, sub)) {
    EmptySubscription.error(new IllegalStateException("This processor allows only a single Subscriber"), subscriber);
    return;
  }

  stream.pause();

  stream.endHandler(v -> {
    release();
    subscriber.onComplete();
  });
  stream.exceptionHandler(err -> {
    release();
    subscriber.onError(err);
  });
  stream.handler(item -> {
    subscriber.onNext(f.apply(item));
  });

  subscriber.onSubscribe(sub);
}