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

org.apache.hbase.thirdparty.io.netty.handler.ssl.ocsp.IoTransport Maven / Gradle / Ivy

/*
 * Copyright 2022 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:
 *
 *   https://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 org.apache.hbase.thirdparty.io.netty.handler.ssl.ocsp;

import org.apache.hbase.thirdparty.io.netty.channel.ChannelFactory;
import org.apache.hbase.thirdparty.io.netty.channel.EventLoop;
import org.apache.hbase.thirdparty.io.netty.channel.nio.NioEventLoop;
import org.apache.hbase.thirdparty.io.netty.channel.nio.NioEventLoopGroup;
import org.apache.hbase.thirdparty.io.netty.channel.socket.DatagramChannel;
import org.apache.hbase.thirdparty.io.netty.channel.socket.SocketChannel;
import org.apache.hbase.thirdparty.io.netty.channel.socket.nio.NioDatagramChannel;
import org.apache.hbase.thirdparty.io.netty.channel.socket.nio.NioSocketChannel;

import static org.apache.hbase.thirdparty.io.netty.util.internal.ObjectUtil.checkNotNull;

/**
 * {@link IoTransport} holds {@link EventLoop}, {@link SocketChannel}
 * and {@link DatagramChannel} for DNS I/O.
 */
public final class IoTransport {
    private final EventLoop eventLoop;
    private final ChannelFactory socketChannel;
    private final ChannelFactory datagramChannel;

    /**
     * Default {@link IoTransport} which uses {@link NioEventLoop}, {@link NioSocketChannel}
     * and {@link NioDatagramChannel}.
     */
    public static final IoTransport DEFAULT = new IoTransport(new NioEventLoopGroup(1).next(),
            new ChannelFactory() {
                @Override
                public SocketChannel newChannel() {
                    return new NioSocketChannel();
                }
            },
            new ChannelFactory() {
                @Override
                public DatagramChannel newChannel() {
                    return new NioDatagramChannel();
                }
            });

    /**
     * Create a new {@link IoTransport} instance
     *
     * @param eventLoop       {@link EventLoop} to use for I/O
     * @param socketChannel   {@link SocketChannel} for TCP DNS lookup and OCSP query
     * @param datagramChannel {@link DatagramChannel} for UDP DNS lookup
     * @return {@link NullPointerException} if any parameter is {@code null}
     */
    public static IoTransport create(EventLoop eventLoop, ChannelFactory socketChannel,
                                     ChannelFactory datagramChannel) {
        return new IoTransport(eventLoop, socketChannel, datagramChannel);
    }

    private IoTransport(EventLoop eventLoop, ChannelFactory socketChannel,
                        ChannelFactory datagramChannel) {
        this.eventLoop = checkNotNull(eventLoop, "EventLoop");
        this.socketChannel = checkNotNull(socketChannel, "SocketChannel");
        this.datagramChannel = checkNotNull(datagramChannel, "DatagramChannel");
    }

    public EventLoop eventLoop() {
        return eventLoop;
    }

    public ChannelFactory socketChannel() {
        return socketChannel;
    }

    public ChannelFactory datagramChannel() {
        return datagramChannel;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy