com.sun.sgs.impl.nio
Class AsyncServerSocketChannelImpl

java.lang.Object
  extended by com.sun.sgs.nio.channels.AsynchronousChannel
      extended by com.sun.sgs.nio.channels.AsynchronousServerSocketChannel
          extended by com.sun.sgs.impl.nio.AsyncServerSocketChannelImpl
All Implemented Interfaces:
NetworkChannel, Closeable, Channel

final class AsyncServerSocketChannelImpl
extends AsynchronousServerSocketChannel

An implementation of AsynchronousServerSocketChannel. Most interesting methods are delegated to the AsyncKey returned by this channel's channel group.


Field Summary
(package private)  ServerSocketChannel channel
          The underlying ServerSocketChannel.
(package private)  AsyncGroupImpl group
          The channel group.
(package private)  AsyncKey key
          The AsyncKey for the underlying channel.
 
Constructor Summary
AsyncServerSocketChannelImpl(AsyncGroupImpl group)
          Creates a new instance registered with the given channel group.
 
Method Summary
<A> IoFuture<AsynchronousSocketChannel,A>
accept(A attachment, CompletionHandler<AsynchronousSocketChannel,? super A> handler)
          Accepts a connection.
 AsyncServerSocketChannelImpl bind(SocketAddress local, int backlog)
          Binds the channel's socket to a local address and configures the socket to listen for connections.
 void close()
          Closes this channel.
 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.
 boolean isAcceptPending()
          Tells whether or not an accept is pending for this channel.
 boolean isOpen()
          
 Set<SocketOption> options()
          Returns a set of the socket options supported by this channel.
 AsyncServerSocketChannelImpl setOption(SocketOption name, Object value)
          Sets the value of a socket option.
 String toString()
          
 
Methods inherited from class com.sun.sgs.nio.channels.AsynchronousServerSocketChannel
accept, bind, open, open
 
Methods inherited from class com.sun.sgs.nio.channels.AsynchronousChannel
provider
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

group

final AsyncGroupImpl group
The channel group.


channel

final ServerSocketChannel channel
The underlying ServerSocketChannel.


key

final AsyncKey key
The AsyncKey for the underlying channel.

Constructor Detail

AsyncServerSocketChannelImpl

AsyncServerSocketChannelImpl(AsyncGroupImpl group)
                       throws IOException
Creates a new instance registered with the given channel group.

Parameters:
group - the channel group
Throws:
IOException - if an I/O error occurs
Method Detail

toString

public String toString()

Overrides:
toString in class Object

isOpen

public boolean isOpen()


close

public void close()
           throws IOException
Closes this channel.

Any outstanding asynchronous operations upon this channel will complete by throwing ExecutionException with cause AsynchronousCloseException.

This method otherwise behaves exactly as specified by the Channel interface.

Specified by:
close in interface Closeable
Specified by:
close in interface Channel
Specified by:
close in class AsynchronousChannel
Throws:
IOException - if an I/O error occurs

bind

public AsyncServerSocketChannelImpl bind(SocketAddress local,
                                         int backlog)
                                  throws IOException
Binds the channel's socket to a local address and configures the socket to listen for connections.

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 associated 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 address is assigned automatically.

The backlog parameter is the maximum number of pending connections on the socket. Its exact semantics are implementation specific. An implementation may impose an implementation specific maximum length or may choose to ignore the parameter. If the backlog parameter has the value 0, or a negative value, then an implementation specific default is used.

Specified by:
bind in class AsynchronousServerSocketChannel
Parameters:
local - the local address to bind the socket, or null to bind to an automatically assigned socket address
backlog - the maximum number number of pending connections
Returns:
this channel
Throws:
ClosedChannelException - if the channel is closed
IOException - if some other I/O error occurs

getLocalAddress

public 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

public AsyncServerSocketChannelImpl 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.

Specified by:
setOption in interface NetworkChannel
Specified by:
setOption in class AsynchronousServerSocketChannel
Parameters:
name - the name of the socket option
value - the value of the socket option
Returns:
this channel
Throws:
ClosedChannelException - if this channel is closed
IOException - if an I/O error occurs
See Also:
SocketOption

getOption

public 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:
ClosedChannelException - if this channel is closed
IOException - if an I/O error occurs
See Also:
SocketOption

options

public 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

isAcceptPending

public boolean isAcceptPending()
Tells whether or not an accept is pending for this channel.

The result of this method is a snapshot of the channel state. It may be invalid when the caller goes to examine the result and should not be used for the purpose of coordination.

Specified by:
isAcceptPending in class AsynchronousServerSocketChannel
Returns:
true if, and only if, an accept is pending for this this channel but has not yet completed.

accept

public <A> IoFuture<AsynchronousSocketChannel,A> accept(A attachment,
                                                        CompletionHandler<AsynchronousSocketChannel,? super A> handler)
Accepts a connection.

This method initiates accepting a connection made to this channel's socket, returning an IoFuture representing the pending result of the operation. The IoFuture's get method will return the AsynchronousSocketChannel for the new connection on successful completion.

When a new connection is accepted then the resulting AsynchronousSocketChannel will be bound to the same AsynchronousChannelGroup as this channel.

If a security manager has been installed then it verifies that the address and port number of the connection's remote endpoint are permitted by the security manager's checkAccept method. The permission check is performed with privileges that are restricted by the calling context of this method. If the permission check fails then the operation completes by throwing ExecutionException with cause SecurityException.

Specified by:
accept in class AsynchronousServerSocketChannel
Type Parameters:
A - the attachment type
Parameters:
attachment - the object to attach to the returned IoFuture object; can be null
handler - the handler for consuming the result; can be null
Returns:
an IoFuture object representing the pending result

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