< prev index next >

jdk/src/java.base/share/classes/java/net/ServerSocket.java

Print this page




 929      * @param value The value of the socket option. A value of {@code null}
 930      *              may be valid for some options.
 931      * @return this ServerSocket
 932      *
 933      * @throws UnsupportedOperationException if the server socket does not
 934      *         support the option.
 935      *
 936      * @throws IllegalArgumentException if the value is not valid for
 937      *         the option.
 938      *
 939      * @throws IOException if an I/O error occurs, or if the socket is closed.
 940      *
 941      * @throws NullPointerException if name is {@code null}
 942      *
 943      * @throws SecurityException if a security manager is set and if the socket
 944      *         option requires a security permission and if the caller does
 945      *         not have the required permission.
 946      *         {@link java.net.StandardSocketOptions StandardSocketOptions}
 947      *         do not require any security permission.
 948      *
 949      * @since 1.9
 950      */
 951     public <T> ServerSocket setOption(SocketOption<T> name, T value)
 952         throws IOException
 953     {
 954         getImpl().setOption(name, value);
 955         return this;
 956     }
 957 
 958     /**
 959      * Returns the value of a socket option.
 960      *
 961      * @param <T> The type of the socket option value
 962      * @param name The socket option
 963      *
 964      * @return The value of the socket option.
 965      *
 966      * @throws UnsupportedOperationException if the server socket does not
 967      *         support the option.
 968      *
 969      * @throws IOException if an I/O error occurs, or if the socket is closed.
 970      *
 971      * @throws NullPointerException if name is {@code null}
 972      *
 973      * @throws SecurityException if a security manager is set and if the socket
 974      *         option requires a security permission and if the caller does
 975      *         not have the required permission.
 976      *         {@link java.net.StandardSocketOptions StandardSocketOptions}
 977      *         do not require any security permission.
 978      *
 979      * @since 1.9
 980      */
 981     public <T> T getOption(SocketOption<T> name) throws IOException {
 982         return getImpl().getOption(name);
 983     }
 984 
 985     private static Set<SocketOption<?>> options;
 986     private static boolean optionsSet = false;
 987 
 988     /**
 989      * Returns a set of the socket options supported by this server socket.
 990      *
 991      * This method will continue to return the set of options even after
 992      * the socket has been closed.
 993      *
 994      * @return A set of the socket options supported by this socket. This set
 995      *         may be empty if the socket's SocketImpl cannot be created.
 996      *
 997      * @since 1.9
 998      */
 999     public Set<SocketOption<?>> supportedOptions() {
1000         synchronized (ServerSocket.class) {
1001             if (optionsSet) {
1002                 return options;
1003             }
1004             try {
1005                 SocketImpl impl = getImpl();
1006                 options = Collections.unmodifiableSet(impl.supportedOptions());
1007             } catch (IOException e) {
1008                 options = Collections.emptySet();
1009             }
1010             optionsSet = true;
1011             return options;
1012         }
1013     }
1014 }


 929      * @param value The value of the socket option. A value of {@code null}
 930      *              may be valid for some options.
 931      * @return this ServerSocket
 932      *
 933      * @throws UnsupportedOperationException if the server socket does not
 934      *         support the option.
 935      *
 936      * @throws IllegalArgumentException if the value is not valid for
 937      *         the option.
 938      *
 939      * @throws IOException if an I/O error occurs, or if the socket is closed.
 940      *
 941      * @throws NullPointerException if name is {@code null}
 942      *
 943      * @throws SecurityException if a security manager is set and if the socket
 944      *         option requires a security permission and if the caller does
 945      *         not have the required permission.
 946      *         {@link java.net.StandardSocketOptions StandardSocketOptions}
 947      *         do not require any security permission.
 948      *
 949      * @since 9
 950      */
 951     public <T> ServerSocket setOption(SocketOption<T> name, T value)
 952         throws IOException
 953     {
 954         getImpl().setOption(name, value);
 955         return this;
 956     }
 957 
 958     /**
 959      * Returns the value of a socket option.
 960      *
 961      * @param <T> The type of the socket option value
 962      * @param name The socket option
 963      *
 964      * @return The value of the socket option.
 965      *
 966      * @throws UnsupportedOperationException if the server socket does not
 967      *         support the option.
 968      *
 969      * @throws IOException if an I/O error occurs, or if the socket is closed.
 970      *
 971      * @throws NullPointerException if name is {@code null}
 972      *
 973      * @throws SecurityException if a security manager is set and if the socket
 974      *         option requires a security permission and if the caller does
 975      *         not have the required permission.
 976      *         {@link java.net.StandardSocketOptions StandardSocketOptions}
 977      *         do not require any security permission.
 978      *
 979      * @since 9
 980      */
 981     public <T> T getOption(SocketOption<T> name) throws IOException {
 982         return getImpl().getOption(name);
 983     }
 984 
 985     private static Set<SocketOption<?>> options;
 986     private static boolean optionsSet = false;
 987 
 988     /**
 989      * Returns a set of the socket options supported by this server socket.
 990      *
 991      * This method will continue to return the set of options even after
 992      * the socket has been closed.
 993      *
 994      * @return A set of the socket options supported by this socket. This set
 995      *         may be empty if the socket's SocketImpl cannot be created.
 996      *
 997      * @since 9
 998      */
 999     public Set<SocketOption<?>> supportedOptions() {
1000         synchronized (ServerSocket.class) {
1001             if (optionsSet) {
1002                 return options;
1003             }
1004             try {
1005                 SocketImpl impl = getImpl();
1006                 options = Collections.unmodifiableSet(impl.supportedOptions());
1007             } catch (IOException e) {
1008                 options = Collections.emptySet();
1009             }
1010             optionsSet = true;
1011             return options;
1012         }
1013     }
1014 }
< prev index next >