author | alanb |
Mon, 09 May 2011 18:45:33 +0100 | |
changeset 9679 | d98ae8bc45fc |
parent 5506 | 202f599c92aa |
child 14342 | 8435a30053c1 |
permissions | -rw-r--r-- |
1152 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. |
1152 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
1152 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
1152 | 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 |
* |
|
5506 | 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. |
|
1152 | 24 |
*/ |
25 |
||
26 |
package java.nio.channels; |
|
27 |
||
28 |
import java.net.SocketOption; |
|
29 |
import java.net.SocketAddress; |
|
30 |
import java.util.Set; |
|
31 |
import java.io.IOException; |
|
32 |
||
33 |
/** |
|
34 |
* A channel to a network socket. |
|
35 |
* |
|
36 |
* <p> A channel that implements this interface is a channel to a network |
|
37 |
* socket. The {@link #bind(SocketAddress) bind} method is used to bind the |
|
38 |
* socket to a local {@link SocketAddress address}, the {@link #getLocalAddress() |
|
39 |
* getLocalAddress} method returns the address that the socket is bound to, and |
|
40 |
* the {@link #setOption(SocketOption,Object) setOption} and {@link |
|
41 |
* #getOption(SocketOption) getOption} methods are used to set and query socket |
|
42 |
* options. An implementation of this interface should specify the socket options |
|
43 |
* that it supports. |
|
44 |
* |
|
45 |
* <p> The {@link #bind bind} and {@link #setOption setOption} methods that do |
|
46 |
* not otherwise have a value to return are specified to return the network |
|
47 |
* channel upon which they are invoked. This allows method invocations to be |
|
48 |
* chained. Implementations of this interface should specialize the return type |
|
49 |
* so that method invocations on the implementation class can be chained. |
|
50 |
* |
|
51 |
* @since 1.7 |
|
52 |
*/ |
|
53 |
||
54 |
public interface NetworkChannel |
|
55 |
extends Channel |
|
56 |
{ |
|
57 |
/** |
|
58 |
* Binds the channel's socket to a local address. |
|
59 |
* |
|
60 |
* <p> This method is used to establish an association between the socket and |
|
61 |
* a local address. Once an association is established then the socket remains |
|
62 |
* bound until the channel is closed. If the {@code local} parameter has the |
|
63 |
* value {@code null} then the socket will be bound to an address that is |
|
64 |
* assigned automatically. |
|
65 |
* |
|
66 |
* @param local |
|
67 |
* The address to bind the socket, or {@code null} to bind the socket |
|
68 |
* to an automatically assigned socket address |
|
69 |
* |
|
70 |
* @return This channel |
|
71 |
* |
|
72 |
* @throws AlreadyBoundException |
|
73 |
* If the socket is already bound |
|
74 |
* @throws UnsupportedAddressTypeException |
|
75 |
* If the type of the given address is not supported |
|
76 |
* @throws ClosedChannelException |
|
77 |
* If the channel is closed |
|
78 |
* @throws IOException |
|
79 |
* If some other I/O error occurs |
|
80 |
* @throws SecurityException |
|
81 |
* If a security manager is installed and it denies an unspecified |
|
82 |
* permission. An implementation of this interface should specify |
|
83 |
* any required permissions. |
|
84 |
* |
|
85 |
* @see #getLocalAddress |
|
86 |
*/ |
|
87 |
NetworkChannel bind(SocketAddress local) throws IOException; |
|
88 |
||
89 |
/** |
|
90 |
* Returns the socket address that this channel's socket is bound to, or |
|
91 |
* {@code null} if the socket is not bound. |
|
92 |
* |
|
93 |
* <p> Where the channel is {@link #bind bound} to an Internet Protocol |
|
94 |
* socket address then the return value from this method is of type {@link |
|
95 |
* java.net.InetSocketAddress}. |
|
96 |
* |
|
97 |
* @return The socket address that the socket is bound to, or {@code null} |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1152
diff
changeset
|
98 |
* if the channel's socket is not bound |
1152 | 99 |
* |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1152
diff
changeset
|
100 |
* @throws ClosedChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1152
diff
changeset
|
101 |
* If the channel is closed |
1152 | 102 |
* @throws IOException |
103 |
* If an I/O error occurs |
|
104 |
*/ |
|
105 |
SocketAddress getLocalAddress() throws IOException; |
|
106 |
||
107 |
/** |
|
108 |
* Sets the value of a socket option. |
|
109 |
* |
|
110 |
* @param name |
|
111 |
* The socket option |
|
112 |
* @param value |
|
113 |
* The value of the socket option. A value of {@code null} may be |
|
114 |
* a valid value for some socket options. |
|
115 |
* |
|
116 |
* @return This channel |
|
117 |
* |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1152
diff
changeset
|
118 |
* @throws UnsupportedOperationException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1152
diff
changeset
|
119 |
* If the socket option is not supported by this channel |
1152 | 120 |
* @throws IllegalArgumentException |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1152
diff
changeset
|
121 |
* If the value is not a valid value for this socket option |
1152 | 122 |
* @throws ClosedChannelException |
123 |
* If this channel is closed |
|
124 |
* @throws IOException |
|
125 |
* If an I/O error occurs |
|
126 |
* |
|
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
5506
diff
changeset
|
127 |
* @see java.net.StandardSocketOptions |
1152 | 128 |
*/ |
129 |
<T> NetworkChannel setOption(SocketOption<T> name, T value) throws IOException; |
|
130 |
||
131 |
/** |
|
132 |
* Returns the value of a socket option. |
|
133 |
* |
|
134 |
* @param name |
|
135 |
* The socket option |
|
136 |
* |
|
137 |
* @return The value of the socket option. A value of {@code null} may be |
|
138 |
* a valid value for some socket options. |
|
139 |
* |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1152
diff
changeset
|
140 |
* @throws UnsupportedOperationException |
1152 | 141 |
* If the socket option is not supported by this channel |
142 |
* @throws ClosedChannelException |
|
143 |
* If this channel is closed |
|
144 |
* @throws IOException |
|
145 |
* If an I/O error occurs |
|
146 |
* |
|
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
5506
diff
changeset
|
147 |
* @see java.net.StandardSocketOptions |
1152 | 148 |
*/ |
149 |
<T> T getOption(SocketOption<T> name) throws IOException; |
|
150 |
||
151 |
/** |
|
152 |
* Returns a set of the socket options supported by this channel. |
|
153 |
* |
|
154 |
* <p> This method will continue to return the set of options even after the |
|
155 |
* channel has been closed. |
|
156 |
* |
|
157 |
* @return A set of the socket options supported by this channel |
|
158 |
*/ |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1152
diff
changeset
|
159 |
Set<SocketOption<?>> supportedOptions(); |
1152 | 160 |
} |