void fastPath() {
      final Iterator<? extends T> a = iterator;
      final Subscriber<? super T> s = actual;

      for (; ; ) {

        if (cancelled) {
          return;
        }

        T t;

        try {
          t = a.next();
        } catch (Exception ex) {
          s.onError(ex);
          return;
        }

        if (cancelled) {
          return;
        }

        if (t == null) {
          s.onError(new NullPointerException("The iterator returned a null value"));
          return;
        }

        s.onNext(t);

        if (cancelled) {
          return;
        }

        boolean b;

        try {
          b = a.hasNext();
        } catch (Exception ex) {
          s.onError(ex);
          return;
        }

        if (cancelled) {
          return;
        }

        if (!b) {
          s.onComplete();
          return;
        }
      }
    }
 @Override
 public void onError(final Throwable e) {
   // TODO throw if fatal ?;
   FastList list;
   synchronized (this) {
     if (terminated) {
       return;
     }
     if (emitting) {
       if (queue == null) {
         queue = new FastList();
       }
       queue.add(new ErrorSentinel(e));
       return;
     }
     emitting = true;
     list = queue;
     queue = null;
   }
   drainQueue(list);
   delegate.onError(e);
   synchronized (this) {
     emitting = false;
   }
 }
示例#3
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);
    }
  }
    @Override
    public void onError(Throwable t) {
      if (done) {
        RxJavaPlugins.onError(t);
        return;
      }
      done = true;

      actual.onError(t);
    }
    @Override
    public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
      if (subscriber == null) {
        throw Exceptions.spec_2_13_exception();
      }
      if (this.subscriber != null) {
        subscriber.onError(new IllegalStateException("Only one subscriber allowed"));
      }

      this.subscriber = subscriber;
      this.subscriber.onSubscribe(new RequestBodySubscription());
    }
 @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);
   }
 }
 @Override
 public void run() {
   if (requested) {
     if (cancel != CANCELLED) {
       s.onNext(0L);
     }
     asyncExecutor.apply(null);
     if (cancel != CANCELLED) {
       s.onComplete();
     }
   } else {
     s.onError(new IllegalStateException("Could not emit value due to lack of requests"));
   }
 }
示例#8
0
    void slowPath(long n) {
      final T[] a = array;
      final int len = a.length;
      final Subscriber<? super T> s = actual;

      int i = index;
      int e = 0;

      for (; ; ) {
        if (cancelled) {
          return;
        }

        while (i != len && e != n) {
          T t = a[i];

          if (t == null) {
            s.onError(new NullPointerException("The " + i + "th array element was null"));
            return;
          }

          s.onNext(t);

          if (cancelled) {
            return;
          }

          i++;
          e++;
        }

        if (i == len) {
          s.onComplete();
          return;
        }

        n = requested;

        if (n == e) {
          index = i;
          n = REQUESTED.addAndGet(this, -e);
          if (n == 0) {
            return;
          }
          e = 0;
        }
      }
    }
 @Override
 public void fail(Throwable error) {
   if (error == null) {
     error = new NullPointerException("error is null");
   }
   if (isCancelled() || done) {
     Exceptions.onErrorDropped(error);
     return;
   }
   done = true;
   if (caughtUp && actual != null) {
     actual.onError(error);
   } else {
     this.error = error;
     done = true;
     drain();
   }
 }
示例#10
0
    @Override
    public void onError(Throwable t) {
      if (done) {
        RxJavaPlugins.onError(t);
        return;
      }
      done = true;
      try {
        onError.accept(t);
      } catch (Throwable e) {
        t.addSuppressed(e);
      }
      actual.onError(t);

      try {
        onAfterTerminate.run();
      } catch (Throwable e) {
        RxJavaPlugins.onError(e);
      }
    }
    boolean checkTerminated(boolean d, boolean empty, Subscriber<? super T> a) {
      if (cancelled) {
        VALUE.lazySet(this, null);
        return true;
      }

      if (d) {
        Throwable e = error;
        if (e != null) {
          VALUE.lazySet(this, null);

          a.onError(e);
          return true;
        } else if (empty) {
          a.onComplete();
          return true;
        }
      }

      return false;
    }
 void drainQueue(FastList list) {
   if (list == null || list.size == 0) {
     return;
   }
   Object v;
   for (int i = 0; i < list.size; i++) {
     v = list.array[i];
     if (v == null) {
       break;
     }
     if (v == NULL_SENTINEL) {
       delegate.onNext(null);
     } else if (v == COMPLETE_SENTINEL) {
       delegate.onComplete();
       return;
     } else if (v.getClass() == ErrorSentinel.class) {
       delegate.onError(((ErrorSentinel) v).e);
     } else {
       @SuppressWarnings("unchecked")
       T t = (T) v;
       delegate.onNext(t);
     }
   }
 }
示例#13
0
    void fastPath() {
      final T[] a = array;
      final int len = a.length;
      final Subscriber<? super T> s = actual;

      for (int i = index; i != len; i++) {
        if (cancelled) {
          return;
        }

        T t = a[i];

        if (t == null) {
          s.onError(new NullPointerException("The " + i + "th array element was null"));
          return;
        }

        s.onNext(t);
      }
      if (cancelled) {
        return;
      }
      s.onComplete();
    }
    void slowPath(long n) {
      final Iterator<? extends T> a = iterator;
      final Subscriber<? super T> s = actual;

      long e = 0L;

      for (; ; ) {

        while (e != n) {
          T t;

          try {
            t = a.next();
          } catch (Throwable ex) {
            s.onError(ex);
            return;
          }

          if (cancelled) {
            return;
          }

          if (t == null) {
            s.onError(new NullPointerException("The iterator returned a null value"));
            return;
          }

          s.onNext(t);

          if (cancelled) {
            return;
          }

          boolean b;

          try {
            b = a.hasNext();
          } catch (Throwable ex) {
            s.onError(ex);
            return;
          }

          if (cancelled) {
            return;
          }

          if (!b) {
            s.onComplete();
            return;
          }

          e++;
        }

        n = requested;

        if (n == e) {
          n = REQUESTED.addAndGet(this, -e);
          if (n == 0L) {
            return;
          }
          e = 0L;
        }
      }
    }
示例#15
0
 @Override
 public void onError(Throwable t) {
   upstream.onError(t);
 }
    boolean drain() {
      if (wip++ != 0) {
        return false;
      }

      int missed = 1;

      for (; ; ) {
        final Queue<Object> q = queue;
        final Subscriber<? super Object> a = actual;

        if (a == null) {
          return false;
        }

        long r = requested;
        long e = 0L;

        while (e != r) {
          if (isCancelled()) {
            return false;
          }

          boolean d = done;
          Object v = q != null ? q.poll() : null;
          boolean empty = v == null;

          if (d && empty) {
            cancelResource();
            if (q != null) {
              q.clear();
            }
            Throwable ex = error;
            if (ex != null) {
              a.onError(ex);
            } else {
              a.onComplete();
            }
            return false;
          }

          if (empty) {
            ch.read();
            break;
          }

          try {
            a.onNext(v);
          } finally {
            ReferenceCountUtil.release(v);
            ch.read();
          }

          e++;
        }

        if (e == r) {
          if (isCancelled()) {
            return false;
          }

          if (done && (q == null || q.isEmpty())) {
            cancelResource();
            if (q != null) {
              q.clear();
            }
            Throwable ex = error;
            if (ex != null) {
              a.onError(ex);
            } else {
              a.onComplete();
            }
            return false;
          }
        }

        if (e != 0L) {
          if (r != Long.MAX_VALUE) {
            if ((requested -= e) > 0L) {
              ch.read();
            }
          }
        }

        missed = (wip = wip - missed);
        if (missed == 0) {
          if (r == Long.MAX_VALUE) {
            ch.config().setAutoRead(true);
            ch.read();
            return true;
          }
          return false;
        }
      }
    }