Search in sources :

Example 1 with DataObserver

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();
            }
        };
    });
}
Also used : Subscriber(io.servicetalk.concurrent.CompletableSource.Subscriber) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) DataObserver(io.servicetalk.transport.api.ConnectionObserver.DataObserver) NoopDataObserver(io.servicetalk.transport.netty.internal.NoopTransportObserver.NoopDataObserver) ReadObserver(io.servicetalk.transport.api.ConnectionObserver.ReadObserver) Nullable(javax.annotation.Nullable)

Aggregations

Subscriber (io.servicetalk.concurrent.CompletableSource.Subscriber)1 Subscription (io.servicetalk.concurrent.PublisherSource.Subscription)1 DataObserver (io.servicetalk.transport.api.ConnectionObserver.DataObserver)1 ReadObserver (io.servicetalk.transport.api.ConnectionObserver.ReadObserver)1 NoopDataObserver (io.servicetalk.transport.netty.internal.NoopTransportObserver.NoopDataObserver)1 Nullable (javax.annotation.Nullable)1