com.sun.sgs.nio.channels
Interface NetworkChannel

All Superinterfaces:
Channel, Closeable
All Known Subinterfaces:
MulticastChannel
All Known Implementing Classes:
AsynchronousDatagramChannel, AsynchronousServerSocketChannel, AsynchronousSocketChannel

public interface NetworkChannel
extends Channel

A channel to a network socket.

A channel that implements this interface is a channel to a network socket. The bind(java.net.SocketAddress) method is used to bind the socket to a local address, the getLocalAddress() method returns the address that the socket is bound to, and the setOption(com.sun.sgs.nio.channels.SocketOption, java.lang.Object) and getOption(com.sun.sgs.nio.channels.SocketOption) methods are used to set and query socket options. An implementation of this interface should specify the socket options that it supports.

The {#link #bind} and setOption(com.sun.sgs.nio.channels.SocketOption, java.lang.Object) methods that do not otherwise have a value to return are specified to return the network channel upon which they are invoked. This allows method invocations to be chained. Implementations of this interface should specialize the return type so that method invocations on the implementation class can be chained.


Method Summary
 NetworkChannel bind(SocketAddress local)
          Binds the channel's socket to a local address.
 SocketAddress getLocalAddress()
          Returns the socket address that this channel's socket is bound to, or null if the socket is not bound.
 Object getOption(SocketOption name)
          Returns the value of a socket option.
 Set<SocketOption> options()
          Returns a set of the socket options supported by this channel.
 NetworkChannel setOption(SocketOption name, Object value)
          Sets the value of a socket option.
 
Methods inherited from interface java.nio.channels.Channel
close, isOpen
 

Method Detail

bind

NetworkChannel bind(SocketAddress local)
                    throws IOException
Binds the channel's socket to a local address.

This method is used to establish an association between the socket and a local address. Once an association is established then the socket remains bound until the channel is closed. An attempt to bind a socket that is already bound throws AlreadyBoundException. If the local parameter has the value null then the socket will be bound to an address that is assigned automatically.

An implementation of this interface should specify if a permission is required when a security manager is installed.

Parameters:
local - the address to bind the socket, or null to bind the socket to an automatically assigned socket address
Returns:
this channel
Throws:
AlreadyBoundException - if the socket is already bound
UnsupportedAddressTypeException - if the type of the given address is not supported
ClosedChannelException - if the channel is closed
IOException - if some other I/O error occurs

getLocalAddress

SocketAddress getLocalAddress()
                              throws IOException
Returns the socket address that this channel's socket is bound to, or null if the socket is not bound.

Returns:
the socket address that the socket is bound to, or null if the channel is not open or the channel's socket is not bound
Throws:
IOException - if an I/O error occurs

setOption

NetworkChannel setOption(SocketOption name,
                         Object value)
                         throws IOException
Sets the value of a socket option.

The name parameter is the name of the socket option. The value parameter is the value of the option and is of the type specified by the option. A value of null may be a valid value for some socket options.

Parameters:
name - the name of the socket option
value - the value of the socket option
Returns:
this channel
Throws:
IllegalArgumentException - If the socket option is not supported by this channel, or the value is not a valid value for this socket option
ClosedChannelException - if this channel is closed
IOException - if an I/O error occurs
See Also:
SocketOption

getOption

Object getOption(SocketOption name)
                 throws IOException
Returns the value of a socket option.

The return type is specific to the socket option and null may be a valid value for some socket options.

Parameters:
name - the socket option
Returns:
the value of the socket option
Throws:
IllegalArgumentException - if the socket option is not supported by this channel
ClosedChannelException - if this channel is closed
IOException - if an I/O error occurs
See Also:
SocketOption

options

Set<SocketOption> options()
Returns a set of the socket options supported by this channel.

This method will continue to return the set of options even after the channel has been closed.

Returns:
a set of the socket options supported by this channel

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved