src/jdk.net/share/classes/jdk/net/RdmaSockets.java
author alanb
Sat, 26 Jan 2019 14:02:35 +0000
branchrsocket-branch
changeset 57115 512e7cc6ccce
child 57117 7f1b415bfede
permissions -rw-r--r--
Initial load of JEP 337 implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     1
/*
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     4
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    10
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    16
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    20
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    23
 * questions.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    24
 */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    25
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    26
package jdk.net;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    27
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    28
import java.net.ProtocolFamily;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    29
import java.net.ServerSocket;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    30
import java.net.Socket;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    31
import java.net.SocketException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    32
import java.net.SocketOption;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    33
import java.net.StandardSocketOptions;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    34
import java.nio.channels.Selector;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    35
import java.nio.channels.ServerSocketChannel;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    36
import java.nio.channels.SocketChannel;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    37
import java.nio.channels.spi.SelectorProvider;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    38
import java.io.IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    39
import java.util.Objects;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    40
import jdk.internal.net.rdma.RdmaPollSelectorProvider;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    41
import jdk.internal.net.rdma.RdmaSocketProvider;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    42
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    43
/**
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    44
 * Factory methods for creating RDMA-based TCP sockets and channels.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    45
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    46
 * <p>The {@link #openSocket(ProtocolFamily family) openSocket} and {@link
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    47
 * #openServerSocket(ProtocolFamily family) openServerSocket} methods
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    48
 * create RDMA-based TCP sockets.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    49
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    50
 * <p>The {@link #openSelector() openSelector}, {@link
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    51
 * #openSocketChannel(ProtocolFamily family) openSocketChannel}, and {@link
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    52
 * #openServerSocketChannel(ProtocolFamily family) openServerSocketChannel}
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    53
 * methods create selectors and selectable channels for use with RDMA sockets.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    54
 * These objects are created by a {@link java.nio.channels.spi.SelectorProvider
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    55
 * SelectorProvider} that is not the default {@code SelectorProvider}.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    56
 * Consequently, selectable channels to RDMA sockets may not be multiplexed
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    57
 * with selectable channels created by the default selector provider. Its
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    58
 * selector provider does not support datagram channels and pipes.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    59
 * The {@link java.nio.channels.spi.SelectorProvider#openDatagramChannel
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    60
 * openDatagramChannel} and
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    61
 * {@link java.nio.channels.spi.SelectorProvider#openPipe openPipe} methods
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    62
 * throw {@link java.lang.UnsupportedOperationException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    63
 * UnsupportedOperationException}.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    64
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    65
 * @since 12
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    66
 */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    67
public class RdmaSockets {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    68
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    69
    private RdmaSockets() {}
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    70
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    71
    /**
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    72
     * Creates an unbound and unconnected RDMA socket.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    73
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    74
     * <p> An RDMA socket supports the same socket options that {@link
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    75
     * java.net.Socket java.net.Socket} defines. In addition, it supports the
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    76
     * socket options specified by {@link RdmaSocketOptions}.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    77
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    78
     * <p> When binding the socket to a local address, or invoking {@code
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    79
     * connect} to connect the socket, the socket address specified to those
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    80
     * methods must correspond to the protocol family specified here.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    81
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    82
     * @param   family
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    83
     *          The protocol family
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    84
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    85
     * @throws IOException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    86
     *         If an I/O error occurs
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    87
     * @throws NullPointerException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    88
     *         If name is {@code null}
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    89
     * @throws UnsupportedOperationException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    90
     *         If RDMA sockets are not supported on this platform or if the
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    91
     *         specified protocol family is not supported. For example, if
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    92
     *         the parameter is {@link java.net.StandardProtocolFamily#INET6
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    93
     *         StandardProtocolFamily.INET6} but IPv6 is not enabled on the
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    94
     *         platform.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    95
     */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    96
    public static Socket openSocket(ProtocolFamily family) throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    97
        Objects.requireNonNull("protocol family is null");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    98
        return RdmaSocketProvider.openSocket(family);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    99
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   100
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   101
    /**
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   102
     * Creates an unbound RDMA server socket.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   103
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   104
     * <p> An RDMA socket supports the same socket options that {@link
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   105
     * java.net.ServerSocket java.net.ServerSocket} defines.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   106
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   107
     * <p> When binding the socket to an address, the socket address specified
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   108
     * to the {@code bind} method must correspond to the protocol family
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   109
     * specified here.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   110
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   111
     * @param   family
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   112
     *          The protocol family
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   113
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   114
     * @throws IOException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   115
     *         If an I/O error occurs
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   116
     * @throws NullPointerException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   117
     *         If name is {@code null}
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   118
     * @throws UnsupportedOperationException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   119
     *         If RDMA sockets are not supported on this platform or if the
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   120
     *         specified protocol family is not supported. For example, if
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   121
     *         the parameter is {@link java.net.StandardProtocolFamily#INET6
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   122
     *         StandardProtocolFamily.INET6} but IPv6 is not enabled on the
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   123
     *         platform.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   124
     */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   125
    public static ServerSocket openServerSocket(ProtocolFamily family)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   126
            throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   127
        Objects.requireNonNull("protocol family is null");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   128
        return RdmaSocketProvider.openServerSocket(family);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   129
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   130
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   131
    /**
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   132
     * Opens a socket channel to an RDMA socket. A newly created socket channel
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   133
     * is {@link SocketChannel#isOpen() open}, not yet bound to a {@link
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   134
     * SocketChannel#getLocalAddress() local address}, and not yet
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   135
     * {@link SocketChannel#isConnected() connected}.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   136
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   137
     * <p> A socket channel to an RDMA socket supports all of the socket options
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   138
     * specified by {@code SocketChannel}. In addition, it supports the
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   139
     * socket options specified by {@link RdmaSocketOptions}.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   140
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   141
     * <p> When binding the channel's socket to a local address, or invoking
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   142
     * {@code connect} to connect channel's socket, the socket address specified
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   143
     * to those methods must correspond to the protocol family specified here.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   144
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   145
     * @param   family
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   146
     *          The protocol family
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   147
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   148
     * @throws IOException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   149
     *         If an I/O error occurs
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   150
     * @throws NullPointerException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   151
     *         If name is {@code null}
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   152
     * @throws UnsupportedOperationException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   153
     *         If RDMA sockets are not supported on this platform or if the
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   154
     *         specified protocol family is not supported. For example, if
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   155
     *         the parameter is {@link java.net.StandardProtocolFamily#INET6
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   156
     *         StandardProtocolFamily.INET6} but IPv6 is not enabled on the
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   157
     *         platform.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   158
     */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   159
    public static SocketChannel openSocketChannel(ProtocolFamily family)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   160
            throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   161
        Objects.requireNonNull("protocol family is null");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   162
        SelectorProvider provider = RdmaPollSelectorProvider.provider();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   163
        return ((RdmaPollSelectorProvider)provider).openSocketChannel(family);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   164
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   165
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   166
    /**
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   167
     * Opens a server socket channel to an RDMA socket. A newly created socket
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   168
     * channel is {@link SocketChannel#isOpen() open} but not yet bound to a
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   169
     * {@link SocketChannel#getLocalAddress() local address}.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   170
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   171
     * <p> When binding the channel's socket to an address, the socket address
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   172
     * specified to the {@code bind} method must correspond to the protocol
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   173
     * family specified here.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   174
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   175
     * @param   family
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   176
     *          The protocol family
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   177
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   178
     * @throws IOException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   179
     *         If an I/O error occurs
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   180
     * @throws NullPointerException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   181
     *         If name is {@code null}
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   182
     * @throws UnsupportedOperationException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   183
     *         If RDMA sockets are not supported on this platform or if the
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   184
     *         specified protocol family is not supported. For example, if
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   185
     *         the parameter is {@link java.net.StandardProtocolFamily#INET6
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   186
     *         StandardProtocolFamily.INET6} but IPv6 is not enabled on the
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   187
     *         platform.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   188
     */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   189
    public static ServerSocketChannel openServerSocketChannel(
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   190
            ProtocolFamily family) throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   191
        Objects.requireNonNull("protocol family is null");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   192
        SelectorProvider provider = RdmaPollSelectorProvider.provider();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   193
        return ((RdmaPollSelectorProvider)provider)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   194
                .openServerSocketChannel(family);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   195
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   196
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   197
    /**
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   198
     * Opens a selector to multiplex selectable channels to RDMA sockets.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   199
     *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   200
     * @throws IOException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   201
     *         If an I/O error occurs
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   202
     * @throws UnsupportedOperationException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   203
     *         If RDMA sockets are not supported on this platform
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   204
     */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   205
    public static Selector openSelector() throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   206
        SelectorProvider provider = RdmaPollSelectorProvider.provider();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   207
        return provider.openSelector();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   208
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   209
}