use of io.servicetalk.transport.api.ConnectionObserver.DataObserver in project servicetalk by apple.
the class DefaultNettyConnection method registerReadObserver.
private Publisher<Read> registerReadObserver(final Publisher<Read> readPublisher) {
return readPublisher.liftSync(target -> {
final DataObserver dataObserver = this.dataObserver;
if (dataObserver == NoopDataObserver.INSTANCE) {
return target;
}
final ReadObserver observer = dataObserver.onNewRead();
return new PublisherSource.Subscriber<Read>() {
@Override
public void onSubscribe(final Subscription subscription) {
target.onSubscribe(new Subscription() {
@Override
public void request(final long n) {
observer.requestedToRead(n);
subscription.request(n);
}
@Override
public void cancel() {
observer.readCancelled();
subscription.cancel();
}
});
}
@Override
public void onNext(@Nullable final Read read) {
observer.itemRead(read);
target.onNext(read);
}
@Override
public void onError(final Throwable t) {
observer.readFailed(t);
target.onError(t);
}
@Override
public void onComplete() {
observer.readComplete();
target.onComplete();
}
};
});
}
Aggregations