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

org.cassandraunit.shaded.io.netty.channel.ChannelOption Maven / Gradle / Ivy

There is a newer version: 4.3.1.0
Show newest version
/*
 * Copyright 2012 The Netty Project
 *
 * The Netty Project licenses this file to you 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.netty.channel;

import io.netty.buffer.ByteBufAllocator;
import io.netty.util.UniqueName;
import io.netty.util.internal.PlatformDependent;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.concurrent.ConcurrentMap;

import static io.netty.util.internal.ObjectUtil.checkNotNull;

/**
 * A {@link ChannelOption} allows to configure a {@link ChannelConfig} in a type-safe
 * way. Which {@link ChannelOption} is supported depends on the actual implementation
 * of {@link ChannelConfig} and may depend on the nature of the transport it belongs
 * to.
 *
 * @param    the type of the value which is valid for the {@link ChannelOption}
 */
@SuppressWarnings("deprecation")
public class ChannelOption extends UniqueName {

    @SuppressWarnings("rawtypes")
    private static final ConcurrentMap names = PlatformDependent.newConcurrentHashMap();

    public static final ChannelOption ALLOCATOR = valueOf("ALLOCATOR");
    public static final ChannelOption RCVBUF_ALLOCATOR = valueOf("RCVBUF_ALLOCATOR");
    public static final ChannelOption MESSAGE_SIZE_ESTIMATOR = valueOf("MESSAGE_SIZE_ESTIMATOR");

    public static final ChannelOption CONNECT_TIMEOUT_MILLIS = valueOf("CONNECT_TIMEOUT_MILLIS");
    public static final ChannelOption MAX_MESSAGES_PER_READ = valueOf("MAX_MESSAGES_PER_READ");
    public static final ChannelOption WRITE_SPIN_COUNT = valueOf("WRITE_SPIN_COUNT");
    public static final ChannelOption WRITE_BUFFER_HIGH_WATER_MARK = valueOf("WRITE_BUFFER_HIGH_WATER_MARK");
    public static final ChannelOption WRITE_BUFFER_LOW_WATER_MARK = valueOf("WRITE_BUFFER_LOW_WATER_MARK");

    public static final ChannelOption ALLOW_HALF_CLOSURE = valueOf("ALLOW_HALF_CLOSURE");
    public static final ChannelOption AUTO_READ = valueOf("AUTO_READ");

    /**
     * @deprecated  Auto close will be removed in a future release.
     *
     * If {@code true} then the {@link Channel} is closed automatically and immediately on write failure.
     * The default value is {@code true}.
     */
    @Deprecated
    public static final ChannelOption AUTO_CLOSE = valueOf("AUTO_CLOSE");

    public static final ChannelOption SO_BROADCAST = valueOf("SO_BROADCAST");
    public static final ChannelOption SO_KEEPALIVE = valueOf("SO_KEEPALIVE");
    public static final ChannelOption SO_SNDBUF = valueOf("SO_SNDBUF");
    public static final ChannelOption SO_RCVBUF = valueOf("SO_RCVBUF");
    public static final ChannelOption SO_REUSEADDR = valueOf("SO_REUSEADDR");
    public static final ChannelOption SO_LINGER = valueOf("SO_LINGER");
    public static final ChannelOption SO_BACKLOG = valueOf("SO_BACKLOG");
    public static final ChannelOption SO_TIMEOUT = valueOf("SO_TIMEOUT");

    public static final ChannelOption IP_TOS = valueOf("IP_TOS");
    public static final ChannelOption IP_MULTICAST_ADDR = valueOf("IP_MULTICAST_ADDR");
    public static final ChannelOption IP_MULTICAST_IF = valueOf("IP_MULTICAST_IF");
    public static final ChannelOption IP_MULTICAST_TTL = valueOf("IP_MULTICAST_TTL");
    public static final ChannelOption IP_MULTICAST_LOOP_DISABLED = valueOf("IP_MULTICAST_LOOP_DISABLED");

    public static final ChannelOption TCP_NODELAY = valueOf("TCP_NODELAY");

    @Deprecated
    public static final ChannelOption AIO_READ_TIMEOUT = valueOf("AIO_READ_TIMEOUT");
    @Deprecated
    public static final ChannelOption AIO_WRITE_TIMEOUT = valueOf("AIO_WRITE_TIMEOUT");

    @Deprecated
    public static final ChannelOption DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION =
            valueOf("DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION");

    public static final ChannelOption SINGLE_EVENTEXECUTOR_PER_GROUP =
            valueOf("SINGLE_EVENTEXECUTOR_PER_GROUP");

    /**
     * Creates a new {@link ChannelOption} with the specified {@param name} or return the already existing
     * {@link ChannelOption} for the given name.
     */
    @SuppressWarnings("unchecked")
    public static  ChannelOption valueOf(String name) {
        checkNotNull(name, "name");
        ChannelOption option = names.get(name);
        if (option == null) {
            option = new ChannelOption(name);
            ChannelOption old = names.putIfAbsent(name, option);
            if (old != null) {
                option = old;
            }
        }
        return option;
    }

    /**
     * Returns {@code true} if a {@link ChannelOption} exists for the given {@code name}.
     */
    public static boolean exists(String name) {
        checkNotNull(name, "name");
        return names.containsKey(name);
    }

    /**
     * Creates a new {@link ChannelOption} for the given {@param name} or fail with an
     * {@link IllegalArgumentException} if a {@link ChannelOption} for the given {@param name} exists.
     */
    @SuppressWarnings("unchecked")
    public static  ChannelOption newInstance(String name) {
        checkNotNull(name, "name");
        ChannelOption option = new ChannelOption(name);
        ChannelOption old = names.putIfAbsent(name, option);
        if (old != null) {
            throw new IllegalArgumentException(String.format("'%s' is already in use", name));
        }
        return option;
    }

    /**
     * @deprecated Use {@link #valueOf(String)} instead.
     */
    @Deprecated
    protected ChannelOption(String name) {
        super(name);
    }

    /**
     * Validate the value which is set for the {@link ChannelOption}. Sub-classes
     * may override this for special checks.
     */
    public void validate(T value) {
        if (value == null) {
            throw new NullPointerException("value");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy