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