@Override protected void onRequest(Subscriber<? super O> subscriber, long n) { long demand; Subscription upStream; synchronized (this) { demand = cappedAdd(this.demand, n); upStream = upStream(); this.demand = upStream == null ? demand : 0; } upStreamRequest(upStream, demand); }
protected Subscriber<? super O> downStream() { return subscriber(); }
private void upStreamCancel() { upStreamCancel(upStream()); }
protected void upStreamRequest(long n) { upStreamRequest(upStream(), n); }
@Override public void subscribe(Subscriber<? super I> s) { publisher.subscribe(this); super.subscribe(s); }
@Override public void onError(Throwable throwable) { Subscriber<? super O> downStream = downStream(); if (downStream != null) { downStream.onError(throwable); } }
@Override protected void onFailure(Subscriber<? super O> subscriber, Throwable failure) { upStreamCancel(); super.onFailure(subscriber, failure); }
@Override public void onComplete() { downStreamOnNext(response); super.onComplete(); } }
@Override protected void onRequest(Subscriber<? super T> subscriber, long n) { boolean send; synchronized (this) { send = !requestSent; requestSent = true; } if (send) { send(); } super.onRequest(subscriber, n); }
@Override public void onSubscribe(Subscription subscription) { Objects.requireNonNull(subscription, "invalid 'null' subscription"); long demand = 0; boolean cancel = false; synchronized (this) { if (this.upStream != null) { cancel = true; } else { if (isCancelled()) { cancel = true; } else { this.upStream = subscription; demand = this.demand; this.demand = 0; } } } if (cancel) { subscription.cancel(); } else if (demand > 0) { subscription.request(demand); } }
@Override public void subscribe(Subscriber<? super I> s) { publisher.subscribe(this); super.subscribe(s); }
protected void upStreamRequest(long n) { upStreamRequest(upStream(), n); }
@Override public void onComplete() { Subscriber<? super O> downStream = downStream(); if (downStream != null) { downStream.onComplete(); } }
@Override public void cancel() { upStreamCancel(); super.cancel(); }
@Override public void onComplete() { downStreamOnNext(response); super.onComplete(); } }
@Override protected void onRequest(Subscriber<? super T> subscriber, long n) { boolean send; synchronized (this) { send = !requestSent; requestSent = true; } if (send) { send(); } super.onRequest(subscriber, n); }
@Override public void onSubscribe(Subscription subscription) { Objects.requireNonNull(subscription, "invalid 'null' subscription"); long demand = 0; boolean cancel = false; synchronized (this) { if (this.upStream != null) { cancel = true; } else { if (isCancelled()) { cancel = true; } else { this.upStream = subscription; demand = this.demand; this.demand = 0; } } } if (cancel) { subscription.cancel(); } else if (demand > 0) { subscription.request(demand); } }
@Override protected void onRequest(Subscriber<? super O> subscriber, long n) { long demand; Subscription upStream; synchronized (this) { demand = cappedAdd(this.demand, n); upStream = upStream(); this.demand = upStream == null ? demand : 0; } upStreamRequest(upStream, demand); }
private void upStreamCancel() { upStreamCancel(upStream()); }
protected void downStreamOnNext(O item) { Subscriber<? super O> downStream = downStream(); if (downStream != null) { downStream.onNext(item); } }