NetworkChannel.java revision 893
893N/A/*
893N/A * Copyright 2007-2009 Sun Microsystems, Inc. All Rights Reserved.
893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
893N/A *
893N/A * This code is free software; you can redistribute it and/or modify it
893N/A * under the terms of the GNU General Public License version 2 only, as
893N/A * published by the Free Software Foundation. Sun designates this
893N/A * particular file as subject to the "Classpath" exception as provided
893N/A * by Sun in the LICENSE file that accompanied this code.
893N/A *
893N/A * This code is distributed in the hope that it will be useful, but WITHOUT
893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
893N/A * version 2 for more details (a copy is included in the LICENSE file that
893N/A * accompanied this code).
893N/A *
893N/A * You should have received a copy of the GNU General Public License version
893N/A * 2 along with this work; if not, write to the Free Software Foundation,
893N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
893N/A *
893N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
893N/A * CA 95054 USA or visit www.sun.com if you need additional information or
893N/A * have any questions.
893N/A */
893N/A
893N/Apackage java.nio.channels;
893N/A
893N/Aimport java.net.SocketOption;
893N/Aimport java.net.SocketAddress;
893N/Aimport java.util.Set;
893N/Aimport java.io.IOException;
893N/A
893N/A/**
893N/A * A channel to a network socket.
893N/A *
893N/A * <p> A channel that implements this interface is a channel to a network
893N/A * socket. The {@link #bind(SocketAddress) bind} method is used to bind the
893N/A * socket to a local {@link SocketAddress address}, the {@link #getLocalAddress()
893N/A * getLocalAddress} method returns the address that the socket is bound to, and
893N/A * the {@link #setOption(SocketOption,Object) setOption} and {@link
893N/A * #getOption(SocketOption) getOption} methods are used to set and query socket
893N/A * options. An implementation of this interface should specify the socket options
893N/A * that it supports.
893N/A *
893N/A * <p> The {@link #bind bind} and {@link #setOption setOption} methods that do
893N/A * not otherwise have a value to return are specified to return the network
893N/A * channel upon which they are invoked. This allows method invocations to be
893N/A * chained. Implementations of this interface should specialize the return type
893N/A * so that method invocations on the implementation class can be chained.
893N/A *
893N/A * @since 1.7
893N/A */
893N/A
893N/Apublic interface NetworkChannel
893N/A extends Channel
893N/A{
893N/A /**
893N/A * Binds the channel's socket to a local address.
893N/A *
893N/A * <p> This method is used to establish an association between the socket and
893N/A * a local address. Once an association is established then the socket remains
893N/A * bound until the channel is closed. If the {@code local} parameter has the
893N/A * value {@code null} then the socket will be bound to an address that is
893N/A * assigned automatically.
893N/A *
893N/A * @param local
893N/A * The address to bind the socket, or {@code null} to bind the socket
893N/A * to an automatically assigned socket address
893N/A *
893N/A * @return This channel
893N/A *
893N/A * @throws AlreadyBoundException
893N/A * If the socket is already bound
893N/A * @throws UnsupportedAddressTypeException
893N/A * If the type of the given address is not supported
893N/A * @throws ClosedChannelException
893N/A * If the channel is closed
893N/A * @throws IOException
893N/A * If some other I/O error occurs
893N/A * @throws SecurityException
893N/A * If a security manager is installed and it denies an unspecified
893N/A * permission. An implementation of this interface should specify
893N/A * any required permissions.
893N/A *
893N/A * @see #getLocalAddress
893N/A */
893N/A NetworkChannel bind(SocketAddress local) throws IOException;
893N/A
893N/A /**
893N/A * Returns the socket address that this channel's socket is bound to, or
893N/A * {@code null} if the socket is not bound.
893N/A *
893N/A * <p> Where the channel is {@link #bind bound} to an Internet Protocol
893N/A * socket address then the return value from this method is of type {@link
893N/A * java.net.InetSocketAddress}.
893N/A *
893N/A * @return The socket address that the socket is bound to, or {@code null}
893N/A * if the channel's socket is not bound
893N/A *
893N/A * @throws ClosedChannelException
893N/A * If the channel is closed
893N/A * @throws IOException
893N/A * If an I/O error occurs
893N/A */
893N/A SocketAddress getLocalAddress() throws IOException;
893N/A
893N/A /**
893N/A * Sets the value of a socket option.
893N/A *
893N/A * @param name
893N/A * The socket option
893N/A * @param value
893N/A * The value of the socket option. A value of {@code null} may be
893N/A * a valid value for some socket options.
893N/A *
893N/A * @return This channel
893N/A *
893N/A * @throws UnsupportedOperationException
893N/A * If the socket option is not supported by this channel
893N/A * @throws IllegalArgumentException
893N/A * If the value is not a valid value for this socket option
893N/A * @throws ClosedChannelException
893N/A * If this channel is closed
893N/A * @throws IOException
893N/A * If an I/O error occurs
893N/A *
893N/A * @see java.net.StandardSocketOption
893N/A */
893N/A <T> NetworkChannel setOption(SocketOption<T> name, T value) throws IOException;
893N/A
893N/A /**
893N/A * Returns the value of a socket option.
893N/A *
893N/A * @param name
893N/A * The socket option
893N/A *
893N/A * @return The value of the socket option. A value of {@code null} may be
893N/A * a valid value for some socket options.
893N/A *
893N/A * @throws UnsupportedOperationException
893N/A * If the socket option is not supported by this channel
893N/A * @throws ClosedChannelException
893N/A * If this channel is closed
893N/A * @throws IOException
893N/A * If an I/O error occurs
893N/A *
893N/A * @see java.net.StandardSocketOption
893N/A */
893N/A <T> T getOption(SocketOption<T> name) throws IOException;
893N/A
893N/A /**
893N/A * Returns a set of the socket options supported by this channel.
893N/A *
893N/A * <p> This method will continue to return the set of options even after the
893N/A * channel has been closed.
893N/A *
893N/A * @return A set of the socket options supported by this channel
893N/A */
893N/A Set<SocketOption<?>> supportedOptions();
893N/A}
893N/A