@Override
  public void subscribe(Subscriber<? super T> s) {
    Consumer<Runnable> scheduler;

    try {
      scheduler = schedulerFactory.call();
    } catch (Throwable e) {
      Exceptions.throwIfFatal(e);
      EmptySubscription.error(s, e);
      return;
    }

    if (scheduler == null) {
      EmptySubscription.error(
          s, new NullPointerException("The schedulerFactory returned a null Function"));
      return;
    }

    if (value == null) {
      FluxPublishOn.ScheduledEmptySubscriptionEager parent =
          new FluxPublishOn.ScheduledEmptySubscriptionEager(s, scheduler);
      s.onSubscribe(parent);
      scheduler.accept(parent);
    } else {
      s.onSubscribe(new FluxPublishOn.ScheduledSubscriptionEagerCancel<>(s, value, scheduler));
    }
  }
Пример #2
0
  @Override
  public void subscribe(final Subscriber<? super T> subscriber) {
    try {
      if (supplier != null) {
        subscriber.onSubscribe(
            new PushSubscription<T>(this, subscriber) {

              @Override
              public void request(long elements) {
                try {
                  supplyValue(subscriber);
                } catch (Throwable throwable) {
                  subscriber.onError(throwable);
                }
              }
            });

      } else {
        subscriber.onComplete();
      }
    } catch (Throwable throwable) {
      Exceptions.throwIfFatal(throwable);
      subscriber.onError(throwable);
    }
  }
Пример #3
0
  @Override
  public void subscribe(Subscriber<? super Object> s) {
    if (log.isDebugEnabled()) {
      log.debug(
          "Subscribing inbound receiver [pending: "
              + ""
              + inboundEmitter.getPending()
              + ", done: "
              + inboundEmitter.done
              + "]");
    }
    if (inboundEmitter.actual == null) {
      if (inboundEmitter.done) {
        if (inboundEmitter.error != null) {
          Operators.error(s, inboundEmitter.error);
          return;
        } else if (inboundEmitter.getPending() == 0) {
          Operators.complete(s);
          return;
        }
      }

      inboundEmitter.init(s);
      s.onSubscribe(inboundEmitter);
    } else {
      Operators.error(
          s, new IllegalStateException("Only one connection receive subscriber allowed."));
    }
  }
  @Override
  public void subscribe(Subscriber<? super Long> s) {
    PublisherTimerRunnable r = new PublisherTimerRunnable(s, asyncExecutor);

    s.onSubscribe(r);

    r.setCancel(asyncExecutor.apply(r));
  }
Пример #5
0
 @Override
 public void onSubscribe(Subscription s) {
   if (SubscriptionHelper.validateSubscription(this.s, s)) {
     return;
   }
   this.s = s;
   actual.onSubscribe(s);
 }
Пример #6
0
 @Override
 public void subscribe(Subscriber<? super T> s) {
   if (array.length == 0) {
     EmptySubscription.complete(s);
     return;
   }
   s.onSubscribe(new FluxArraySubscription<>(s, array));
 }
    @Override
    public void onSubscribe(Subscription s) {
      if (SubscriptionHelper.validateSubscription(this.s, s)) {
        return;
      }
      this.s = s;

      Subscriber<? super U> actual = this.actual;

      U b;

      try {
        b = bufferSupplier.get();
      } catch (Throwable e) {
        cancelled = true;
        s.cancel();
        EmptySubscription.error(e, actual);
        return;
      }

      if (b == null) {
        cancelled = true;
        s.cancel();
        EmptySubscription.error(new NullPointerException("The buffer supplied is null"), actual);
        return;
      }
      buffer = b;

      Publisher<B> boundary;

      try {
        boundary = boundarySupplier.get();
      } catch (Throwable ex) {
        cancelled = true;
        s.cancel();
        EmptySubscription.error(ex, actual);
        return;
      }

      if (boundary == null) {
        cancelled = true;
        s.cancel();
        EmptySubscription.error(
            new NullPointerException("The boundary publisher supplied is null"), actual);
        return;
      }

      BufferBoundarySubscriber<T, U, B> bs = new BufferBoundarySubscriber<T, U, B>(this);
      other = bs;

      actual.onSubscribe(this);

      if (!cancelled) {
        s.request(Long.MAX_VALUE);

        boundary.subscribe(bs);
      }
    }
    @Override
    public void onSubscribe(Subscription s) {
      if (Operators.validate(this.s, s)) {
        this.s = s;

        actual.onSubscribe(this);

        s.request(Long.MAX_VALUE);
      }
    }
 @Override
 void subscribe(
     AbstractRequestBodyPublisher publisher, Subscriber<? super DataBuffer> subscriber) {
   Objects.requireNonNull(subscriber);
   if (publisher.changeState(this, NO_DEMAND)) {
     Subscription subscription = new RequestBodySubscription(publisher);
     publisher.subscriber = subscriber;
     subscriber.onSubscribe(subscription);
   } else {
     throw new IllegalStateException(toString());
   }
 }
Пример #10
0
 @Override
 public void subscribe(final Subscriber<? super QueueSignal> subscriber) {
   try {
     if (refCount.getAndIncrement() == 0) {
       this.channel = lapin.createChannel();
     }
     subscriber.onSubscribe(createSubscription(subscriber, null, null));
   } catch (Exception e) {
     refCount.incrementAndGet();
     subscriber.onError(e);
   }
 }
  /**
   * Common method to take an Iterator as a source of values.
   *
   * @param s
   * @param it
   */
  static <T> void subscribe(Subscriber<? super T> s, Iterator<? extends T> it) {
    if (it == null) {
      EmptySubscription.error(s, new NullPointerException("The iterator is null"));
      return;
    }

    boolean b;

    try {
      b = it.hasNext();
    } catch (Throwable e) {
      EmptySubscription.error(s, e);
      return;
    }
    if (!b) {
      EmptySubscription.complete(s);
      return;
    }

    s.onSubscribe(new PublisherIterableSubscription<>(s, it));
  }
Пример #12
0
 @Override
 public void onSubscribe(final Subscription s) {
   this.subscription = s;
   delegate.onSubscribe(this);
 }
 @Override
 public void subscribe(Subscriber<? super Object> s) {
   s.onSubscribe(EmptySubscription.INSTANCE);
   s.onComplete();
 }
Пример #14
0
 @Override
 public void subscribe(Subscriber<? super T> subscriber) {
   BasicSubcription<T> sub = new BasicSubcription<>(subscriber, createEmitter());
   subscriber.onSubscribe(sub);
 }
Пример #15
0
 @Override
 public void onSubscribe(Subscription s) {
   upstream.onSubscribe(s);
 }