Ejemplo n.º 1
0
    @Override
    public void onNext(Notification<? extends T> args) {

      if (waiting.getAndSet(false) || !args.isOnNext()) {
        Notification<? extends T> toOffer = args;
        while (!buf.offer(toOffer)) {
          Notification<? extends T> concurrentItem = buf.poll();

          // in case if we won race condition with onComplete/onError method
          if (concurrentItem != null && !concurrentItem.isOnNext()) {
            toOffer = concurrentItem;
          }
        }
      }
    }
Ejemplo n.º 2
0
  public static <T> AsyncSubject<T> create() {
    final SubjectSubscriptionManager<T> subscriptionManager = new SubjectSubscriptionManager<T>();
    final AtomicReference<Notification<T>> lastNotification =
        new AtomicReference<Notification<T>>(Notification.<T>createOnCompleted());

    OnSubscribe<T> onSubscribe =
        subscriptionManager.getOnSubscribeFunc(
            /**
             * This function executes at beginning of subscription.
             *
             * <p>This will always run, even if Subject is in terminal state.
             */
            new Action1<SubjectObserver<? super T>>() {

              @Override
              public void call(SubjectObserver<? super T> o) {
                // nothing to do if not terminated
              }
            },
            /** This function executes if the Subject is terminated. */
            new Action1<SubjectObserver<? super T>>() {

              @Override
              public void call(SubjectObserver<? super T> o) {
                // we want the last value + completed so add this extra logic
                // to send onCompleted if the last value is an onNext
                emitValueToObserver(lastNotification.get(), o);
              }
            },
            null);

    return new AsyncSubject<T>(onSubscribe, subscriptionManager, lastNotification);
  }
Ejemplo n.º 3
0
 private boolean moveToNext() {
   try {
     Notification<? extends T> nextNotification = observer.takeNext();
     if (nextNotification.isOnNext()) {
       isNextConsumed = false;
       next = nextNotification.getValue();
       return true;
     }
     // If an observable is completed or fails,
     // hasNext() always return false.
     hasNext = false;
     if (nextNotification.isOnCompleted()) {
       return false;
     }
     if (nextNotification.isOnError()) {
       error = nextNotification.getThrowable();
       throw Exceptions.propagate(error);
     }
     throw new IllegalStateException("Should not reach here");
   } catch (InterruptedException e) {
     Thread.currentThread().interrupt();
     error = e;
     throw Exceptions.propagate(error);
   }
 }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      // FIXME
      if (null == convertView) {
        convertView =
            LayoutInflater.from(parent.getContext())
                .inflate(R.layout.view_debug_subscriptions_stats, parent, false);
      }

      TextView countTextView = (TextView) convertView.findViewById(R.id.count);
      TextView infoTextView = (TextView) convertView.findViewById(R.id.info);
      RxDebugger.Stats stats = getItem(position);

      countTextView.setText("" + stats.onNextCount);
      if (null != stats.mostRecentNotification) {
        Notification n = stats.mostRecentNotification;
        switch (n.getKind()) {
          case OnNext:
            @Nullable Object value = n.getValue();
            infoTextView.setText(
                String.format(
                    "NEXT %s", null != value ? value.getClass().getSimpleName() : "null"));
            break;
          case OnCompleted:
            infoTextView.setText("COMPLETED");
            break;
          case OnError:
            infoTextView.setText("ERROR");
            break;
        }
      } else {
        infoTextView.setText("");
      }

      return convertView;
    }
Ejemplo n.º 5
0
 protected static <T> void emitValueToObserver(Notification<T> n, Observer<? super T> o) {
   n.accept(o);
   if (n.isOnNext()) {
     o.onCompleted();
   }
 }
Ejemplo n.º 6
0
 @Override
 public void onNext(T v) {
   lastNotification.set(Notification.createOnNext(v));
 }
Ejemplo n.º 7
0
  @Override
  protected void match() {
    if (!jo1.queue().isEmpty()
        && !jo2.queue().isEmpty()
        && !jo3.queue().isEmpty()
        && !jo4.queue().isEmpty()
        && !jo5.queue().isEmpty()
        && !jo6.queue().isEmpty()
        && !jo7.queue().isEmpty()) {
      Notification<T1> n1 = jo1.queue().peek();
      Notification<T2> n2 = jo2.queue().peek();
      Notification<T3> n3 = jo3.queue().peek();
      Notification<T4> n4 = jo4.queue().peek();
      Notification<T5> n5 = jo5.queue().peek();
      Notification<T6> n6 = jo6.queue().peek();
      Notification<T7> n7 = jo7.queue().peek();

      if (n1.isOnCompleted()
          || n2.isOnCompleted()
          || n3.isOnCompleted()
          || n4.isOnCompleted()
          || n5.isOnCompleted()
          || n6.isOnCompleted()
          || n7.isOnCompleted()) {
        onCompleted.call();
      } else {
        dequeue();
        onNext.call(
            n1.getValue(),
            n2.getValue(),
            n3.getValue(),
            n4.getValue(),
            n5.getValue(),
            n6.getValue(),
            n7.getValue());
      }
    }
  }