Beispiel #1
0
 /**
  * @warn javadoc description missing
  * @warn param producer not described
  * @param producer
  */
 public void setProducer(Producer producer) {
   long toRequest;
   boolean setProducer = false;
   synchronized (this) {
     toRequest = requested;
     p = producer;
     if (op != null) {
       // middle operator ... we pass thru unless a request has been made
       if (toRequest == Long.MIN_VALUE) {
         // we pass-thru to the next producer as nothing has been requested
         setProducer = true;
       }
     }
   }
   // do after releasing lock
   if (setProducer) {
     op.setProducer(p);
   } else {
     // we execute the request with whatever has been requested (or Long.MAX_VALUE)
     if (toRequest == Long.MIN_VALUE) {
       p.request(Long.MAX_VALUE);
     } else {
       p.request(toRequest);
     }
   }
 }
Beispiel #2
0
  @Test
  public void testRequestFromDecoupledOperatorThatRequestsN() {
    Subscriber<String> s = new TestSubscriber<String>();
    final AtomicLong innerR = new AtomicLong();
    Operator<String, String> o =
        new Operator<String, String>() {

          @Override
          public Subscriber<? super String> call(Subscriber<? super String> child) {
            // we want to decouple the chain so set our own Producer on the child instead of it
            // coming from the parent
            child.setProducer(
                new Producer() {

                  @Override
                  public void request(long n) {
                    innerR.set(n);
                  }
                });

            Subscriber<String> as =
                new Subscriber<String>() {

                  @Override
                  public void onCompleted() {}

                  @Override
                  public void onError(Throwable e) {}

                  @Override
                  public void onNext(String t) {}
                };
            // we request 99 up to the parent
            as.request(99);
            return as;
          }
        };
    s.request(10);
    Subscriber<? super String> ns = o.call(s);

    final AtomicLong r = new AtomicLong();
    // set set the producer at the top of the chain (ns) and it should flow through the operator to
    // the (s) subscriber
    // and then it should request up with the value set on the final Subscriber (s)
    ns.setProducer(
        new Producer() {

          @Override
          public void request(long n) {
            r.set(n);
          }
        });
    assertEquals(99, r.get());
    assertEquals(10, innerR.get());
  }
  @Override
  public Subscriber<? super Observable<? extends T>> call(Subscriber<? super T> child) {
    final SerializedSubscriber<T> s = new SerializedSubscriber<T>(child);
    final CompositeSubscription csub = new CompositeSubscription();
    child.add(csub);

    SourceSubscriber<T> ssub = new SourceSubscriber<T>(maxConcurrency, s, csub);
    child.setProducer(new MergeMaxConcurrentProducer<T>(ssub));

    return ssub;
  }
Beispiel #4
0
  /** Should request -1 for infinite */
  @Test
  public void testRequestFromFinalSubscribeWithoutRequestValue() {
    Subscriber<String> s = new TestSubscriber<String>();
    final AtomicLong r = new AtomicLong();
    s.setProducer(
        new Producer() {

          @Override
          public void request(long n) {
            r.set(n);
          }
        });
    assertEquals(Long.MAX_VALUE, r.get());
  }
  @Override
  public Subscriber<? super T> call(final Subscriber<? super T> child) {
    final ParentSubscriber parent = new ParentSubscriber(child);
    child.add(parent); // don't unsubscribe downstream
    child.setProducer(
        new Producer() {
          @Override
          public void request(long n) {
            parent.downstreamRequest(n);
          }
        });

    return parent;
  }
Beispiel #6
0
    SwitchSubscriber(Subscriber<? super T> child) {
      serializedChild = new SerializedSubscriber<T>(child);
      arbiter = new ProducerArbiter();
      ssub = new SerialSubscription();
      child.add(ssub);
      child.setProducer(
          new Producer() {

            @Override
            public void request(long n) {
              if (n > 0) {
                arbiter.request(n);
              }
            }
          });
    }
Beispiel #7
0
  @Test
  public void testRequestFromDecoupledOperator() {
    Subscriber<String> s = new TestSubscriber<String>();
    Operator<String, String> o =
        new Operator<String, String>() {

          @Override
          public Subscriber<? super String> call(Subscriber<? super String> s) {
            return new Subscriber<String>() {

              @Override
              public void onCompleted() {}

              @Override
              public void onError(Throwable e) {}

              @Override
              public void onNext(String t) {}
            };
          }
        };
    s.request(10);
    Subscriber<? super String> ns = o.call(s);

    final AtomicLong r = new AtomicLong();
    // set set the producer at the top of the chain (ns) and it should flow through the operator to
    // the (s) subscriber
    // and then it should request up with the value set on the final Subscriber (s)
    ns.setProducer(
        new Producer() {

          @Override
          public void request(long n) {
            r.set(n);
          }
        });
    // this will be Long.MAX_VALUE because it is decoupled and nothing requested on the Operator
    // subscriber
    assertEquals(Long.MAX_VALUE, r.get());
  }
 @Override
 public void call(Subscriber<? super T> s) {
   s.setProducer(new ScalarAsyncProducer<T>(s, value, onSchedule));
 }