All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.reactivex.netty.protocol.http.client.internal.UnusableConnection Maven / Gradle / Ivy

There is a newer version: 0.5.3-rc.2
Show newest version
/*
 * Copyright 2016 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package io.reactivex.netty.protocol.http.client.internal;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.FileRegion;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.concurrent.EventExecutorGroup;
import io.reactivex.netty.channel.AllocatingTransformer;
import io.reactivex.netty.channel.Connection;
import io.reactivex.netty.channel.events.ConnectionEventListener;
import io.reactivex.netty.events.EventPublisher;
import rx.Observable;
import rx.Observable.Transformer;
import rx.functions.Action1;
import rx.functions.Func1;

final class UnusableConnection extends Connection {

    protected UnusableConnection(Channel nettyChannel,
                                 ConnectionEventListener eventListener,
                                 EventPublisher eventPublisher) {
        super(nettyChannel);
    }

    @Override
    public Observable write(Observable msgs) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public Observable write(Observable msgs, Func1 flushSelector) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public Observable writeAndFlushOnEach(Observable msgs) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public Observable writeString(Observable msgs) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public Observable writeString(Observable msgs, Func1 flushSelector) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public Observable writeStringAndFlushOnEach(Observable msgs) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public Observable writeBytes(Observable msgs) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public Observable writeBytes(Observable msgs, Func1 flushSelector) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public Observable writeBytesAndFlushOnEach(Observable msgs) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public Observable writeFileRegion(Observable msgs) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public Observable writeFileRegion(Observable msgs, Func1 flushSelector) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public Observable writeFileRegionAndFlushOnEach(Observable msgs) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public void flush() {
        throw new IllegalStateException("Connection is not usable.");
    }

    @Override
    public Observable close() {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public Observable close(boolean flush) {
        return Observable.error(new IllegalStateException("Connection is not usable."));
    }

    @Override
    public void closeNow() {
        throw new IllegalStateException("Connection is not usable.");
    }

    @Override
    public Observable closeListener() {
        throw new IllegalStateException("Connection is not usable.");
    }

    public static Connection create() {
        return new UnusableConnection<>(new EmbeddedChannel(), null, null);
    }

    @Override
    public  Connection addChannelHandlerFirst(String name, ChannelHandler handler) {
        return cast();
    }

    @Override
    public  Connection addChannelHandlerFirst(EventExecutorGroup group, String name,
                                                              ChannelHandler handler) {
        return cast();
    }

    @Override
    public  Connection addChannelHandlerLast(String name, ChannelHandler handler) {
        return cast();
    }

    @Override
    public  Connection addChannelHandlerLast(EventExecutorGroup group, String name,
                                                             ChannelHandler handler) {
        return cast();
    }

    @Override
    public  Connection addChannelHandlerBefore(String baseName, String name, ChannelHandler handler) {
        return cast();
    }

    @Override
    public  Connection addChannelHandlerBefore(EventExecutorGroup group, String baseName, String name,
                                                               ChannelHandler handler) {
        return cast();
    }

    @Override
    public  Connection addChannelHandlerAfter(String baseName, String name, ChannelHandler handler) {
        return cast();
    }

    @Override
    public  Connection addChannelHandlerAfter(EventExecutorGroup group, String baseName, String name,
                                                              ChannelHandler handler) {
        return cast();
    }

    @Override
    public  Connection pipelineConfigurator(Action1 pipelineConfigurator) {
        return cast();
    }

    @Override
    public  Connection transformRead(Transformer transformer) {
        throw new IllegalStateException("Connection is not usable.");
    }

    @Override
    public  Connection transformWrite(AllocatingTransformer transformer) {
        throw new IllegalStateException("Connection is not usable.");
    }

    @SuppressWarnings("unchecked")
    private  Connection cast() {
        return (Connection) this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy