author | bpb |
Mon, 04 Feb 2019 13:23:24 -0800 | |
branch | rsocket-branch |
changeset 57142 | 78d016915473 |
parent 57123 | 919516f93dcf |
child 57149 | 87484051dbba |
permissions | -rw-r--r-- |
57115 | 1 |
/* |
57120
64301e5a0da8
rsocket-branch: cleanup in selector provider and friends
chegar
parents:
57117
diff
changeset
|
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 |
/** |
|
57123
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
42 |
* Factory methods for creating RDMA-based TCP sockets and socket channels. |
57115 | 43 |
* |
57123
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
44 |
* <p>The {@link #openSocket(ProtocolFamily) openSocket} and {@link |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
45 |
* #openServerSocket(ProtocolFamily) openServerSocket} methods create RDMA-based |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
46 |
* TCP sockets. |
57115 | 47 |
* |
48 |
* <p>The {@link #openSelector() openSelector}, {@link |
|
57123
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
49 |
* #openSocketChannel(ProtocolFamily) openSocketChannel}, and {@link |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
50 |
* #openServerSocketChannel(ProtocolFamily) openServerSocketChannel} methods |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
51 |
* create selectors and selectable channels for use with RDMA sockets. These |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
52 |
* selectors and channels are created by the RDMA selector provider, which is |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
53 |
* not the {@linkplain SelectorProvider#provider() default} system-wide selector |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
54 |
* provider. Consequently, selectable channels to RDMA sockets may not be |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
55 |
* multiplexed with selectable channels created by the default system-wide |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
56 |
* selector provider. The RDMA selector provider does not support datagram |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
57 |
* channels or pipes. Its {@link SelectorProvider#openDatagramChannel |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
58 |
* openDatagramChannel} and {@link SelectorProvider#openPipe openPipe} methods |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
59 |
* throw {@link UnsupportedOperationException UnsupportedOperationException}. |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
60 |
* |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
61 |
* @implNote The RDMA selector provider supports socket channels of type |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
62 |
* {@link StandardProtocolFamily#INET INET} and {@link |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
63 |
* StandardProtocolFamily#INET6 INET6}. Its {@link |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
64 |
* SelectorProvider#openSocketChannel() openSocketChannel} and {@link |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
65 |
* SelectorProvider#openServerSocketChannel() openServerSocketChannel} |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
66 |
* methods create selectable channels with a family of {@link |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
67 |
* StandardProtocolFamily#INET6 INET6}, if the underlying platform supports |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
68 |
* IPv6. Otherwise, it creates selectable channels with a family of {@link |
919516f93dcf
rsocket-branch: Update RDMA selector provider and API
chegar
parents:
57121
diff
changeset
|
69 |
* StandardProtocolFamily#INET INET}. |
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 |
* |
|
80 |
* <p> An RDMA socket supports the same socket options that {@link |
|
81 |
* java.net.Socket java.net.Socket} defines. In addition, it supports the |
|
82 |
* socket options specified by {@link RdmaSocketOptions}. |
|
83 |
* |
|
84 |
* <p> When binding the socket to a local address, or invoking {@code |
|
85 |
* connect} to connect the socket, the socket address specified to those |
|
86 |
* methods must correspond to the protocol family specified here. |
|
87 |
* |
|
88 |
* @param family |
|
89 |
* The protocol family |
|
90 |
* |
|
91 |
* @throws IOException |
|
92 |
* If an I/O error occurs |
|
93 |
* @throws NullPointerException |
|
57142
78d016915473
rsocket-branch: RDMASockets change name to family in NPE doc
bpb
parents:
57123
diff
changeset
|
94 |
* If {@code family} is {@code null} |
57115 | 95 |
* @throws UnsupportedOperationException |
96 |
* If RDMA sockets are not supported on this platform or if the |
|
97 |
* specified protocol family is not supported. For example, if |
|
98 |
* the parameter is {@link java.net.StandardProtocolFamily#INET6 |
|
99 |
* StandardProtocolFamily.INET6} but IPv6 is not enabled on the |
|
100 |
* platform. |
|
101 |
*/ |
|
102 |
public static Socket openSocket(ProtocolFamily family) throws IOException { |
|
57117
7f1b415bfede
rsocket-branch: fix null arg checking in factories
chegar
parents:
57115
diff
changeset
|
103 |
Objects.requireNonNull(family, "protocol family is null"); |
57115 | 104 |
return RdmaSocketProvider.openSocket(family); |
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* Creates an unbound RDMA server socket. |
|
109 |
* |
|
110 |
* <p> An RDMA socket supports the same socket options that {@link |
|
111 |
* java.net.ServerSocket java.net.ServerSocket} defines. |
|
112 |
* |
|
113 |
* <p> When binding the socket to an address, the socket address specified |
|
114 |
* to the {@code bind} method must correspond to the protocol family |
|
115 |
* specified here. |
|
116 |
* |
|
117 |
* @param family |
|
118 |
* The protocol family |
|
119 |
* |
|
120 |
* @throws IOException |
|
121 |
* If an I/O error occurs |
|
122 |
* @throws NullPointerException |
|
57142
78d016915473
rsocket-branch: RDMASockets change name to family in NPE doc
bpb
parents:
57123
diff
changeset
|
123 |
* If {@code family} is {@code null} |
57115 | 124 |
* @throws UnsupportedOperationException |
125 |
* If RDMA sockets are not supported on this platform or if the |
|
126 |
* specified protocol family is not supported. For example, if |
|
127 |
* the parameter is {@link java.net.StandardProtocolFamily#INET6 |
|
128 |
* StandardProtocolFamily.INET6} but IPv6 is not enabled on the |
|
129 |
* platform. |
|
130 |
*/ |
|
131 |
public static ServerSocket openServerSocket(ProtocolFamily family) |
|
132 |
throws IOException { |
|
57117
7f1b415bfede
rsocket-branch: fix null arg checking in factories
chegar
parents:
57115
diff
changeset
|
133 |
Objects.requireNonNull(family, "protocol family is null"); |
57115 | 134 |
return RdmaSocketProvider.openServerSocket(family); |
135 |
} |
|
136 |
||
137 |
/** |
|
138 |
* Opens a socket channel to an RDMA socket. A newly created socket channel |
|
139 |
* is {@link SocketChannel#isOpen() open}, not yet bound to a {@link |
|
140 |
* SocketChannel#getLocalAddress() local address}, and not yet |
|
141 |
* {@link SocketChannel#isConnected() connected}. |
|
142 |
* |
|
143 |
* <p> A socket channel to an RDMA socket supports all of the socket options |
|
57142
78d016915473
rsocket-branch: RDMASockets change name to family in NPE doc
bpb
parents:
57123
diff
changeset
|
144 |
* specified by {@link SocketChannel java.nio.channels.SocketChannel}. In |
78d016915473
rsocket-branch: RDMASockets change name to family in NPE doc
bpb
parents:
57123
diff
changeset
|
145 |
* addition, it supports the socket options specified by |
78d016915473
rsocket-branch: RDMASockets change name to family in NPE doc
bpb
parents:
57123
diff
changeset
|
146 |
* {@link RdmaSocketOptions}. |
57115 | 147 |
* |
148 |
* <p> When binding the channel's socket to a local address, or invoking |
|
149 |
* {@code connect} to connect channel's socket, the socket address specified |
|
150 |
* to those methods must correspond to the protocol family specified here. |
|
151 |
* |
|
152 |
* @param family |
|
153 |
* The protocol family |
|
154 |
* |
|
155 |
* @throws IOException |
|
156 |
* If an I/O error occurs |
|
157 |
* @throws NullPointerException |
|
57142
78d016915473
rsocket-branch: RDMASockets change name to family in NPE doc
bpb
parents:
57123
diff
changeset
|
158 |
* If {@code family} is {@code null} |
57115 | 159 |
* @throws UnsupportedOperationException |
160 |
* If RDMA sockets are not supported on this platform or if the |
|
161 |
* specified protocol family is not supported. For example, if |
|
162 |
* the parameter is {@link java.net.StandardProtocolFamily#INET6 |
|
163 |
* StandardProtocolFamily.INET6} but IPv6 is not enabled on the |
|
164 |
* platform. |
|
165 |
*/ |
|
166 |
public static SocketChannel openSocketChannel(ProtocolFamily family) |
|
167 |
throws IOException { |
|
57117
7f1b415bfede
rsocket-branch: fix null arg checking in factories
chegar
parents:
57115
diff
changeset
|
168 |
Objects.requireNonNull(family, "protocol family is null"); |
57120
64301e5a0da8
rsocket-branch: cleanup in selector provider and friends
chegar
parents:
57117
diff
changeset
|
169 |
return RdmaPollSelectorProvider.provider().openSocketChannel(family); |
57115 | 170 |
} |
171 |
||
172 |
/** |
|
173 |
* Opens a server socket channel to an RDMA socket. A newly created socket |
|
174 |
* channel is {@link SocketChannel#isOpen() open} but not yet bound to a |
|
175 |
* {@link SocketChannel#getLocalAddress() local address}. |
|
176 |
* |
|
177 |
* <p> When binding the channel's socket to an address, the socket address |
|
178 |
* specified to the {@code bind} method must correspond to the protocol |
|
179 |
* family specified here. |
|
180 |
* |
|
181 |
* @param family |
|
182 |
* The protocol family |
|
183 |
* |
|
184 |
* @throws IOException |
|
185 |
* If an I/O error occurs |
|
186 |
* @throws NullPointerException |
|
57142
78d016915473
rsocket-branch: RDMASockets change name to family in NPE doc
bpb
parents:
57123
diff
changeset
|
187 |
* If {@code family} is {@code null} |
57115 | 188 |
* @throws UnsupportedOperationException |
189 |
* If RDMA sockets are not supported on this platform or if the |
|
190 |
* specified protocol family is not supported. For example, if |
|
191 |
* the parameter is {@link java.net.StandardProtocolFamily#INET6 |
|
192 |
* StandardProtocolFamily.INET6} but IPv6 is not enabled on the |
|
193 |
* platform. |
|
194 |
*/ |
|
195 |
public static ServerSocketChannel openServerSocketChannel( |
|
196 |
ProtocolFamily family) throws IOException { |
|
57117
7f1b415bfede
rsocket-branch: fix null arg checking in factories
chegar
parents:
57115
diff
changeset
|
197 |
Objects.requireNonNull(family, "protocol family is null"); |
57120
64301e5a0da8
rsocket-branch: cleanup in selector provider and friends
chegar
parents:
57117
diff
changeset
|
198 |
return RdmaPollSelectorProvider.provider().openServerSocketChannel(family); |
57115 | 199 |
} |
200 |
||
201 |
/** |
|
202 |
* Opens a selector to multiplex selectable channels to RDMA sockets. |
|
203 |
* |
|
204 |
* @throws IOException |
|
205 |
* If an I/O error occurs |
|
206 |
* @throws UnsupportedOperationException |
|
207 |
* If RDMA sockets are not supported on this platform |
|
208 |
*/ |
|
209 |
public static Selector openSelector() throws IOException { |
|
57120
64301e5a0da8
rsocket-branch: cleanup in selector provider and friends
chegar
parents:
57117
diff
changeset
|
210 |
return RdmaPollSelectorProvider.provider().openSelector(); |
57115 | 211 |
} |
212 |
} |