org.jboss.xnio.nio
Class NioTcpChannel

java.lang.Object
  extended by org.jboss.xnio.nio.NioTcpChannel
All Implemented Interfaces:
java.io.Closeable, java.nio.channels.Channel, java.nio.channels.GatheringByteChannel, java.nio.channels.ReadableByteChannel, java.nio.channels.ScatteringByteChannel, java.nio.channels.WritableByteChannel, BoundChannel<java.net.SocketAddress>, Configurable, ConnectedChannel<java.net.SocketAddress>, ConnectedStreamChannel<java.net.SocketAddress>, StreamChannel, StreamSinkChannel, StreamSourceChannel, SuspendableChannel, SuspendableReadChannel, SuspendableWriteChannel, TcpChannel

public final class NioTcpChannel
extends java.lang.Object
implements TcpChannel, java.io.Closeable


Nested Class Summary
 class NioTcpChannel.MBean
           
 
Constructor Summary
NioTcpChannel(NioXnio nioXnio, java.nio.channels.SocketChannel socketChannel, IoHandler<? super TcpChannel> handler, java.util.concurrent.Executor executor, boolean manage)
           
 
Method Summary
 void awaitReadable()
          Block until this channel becomes readable again.
 void awaitReadable(long time, java.util.concurrent.TimeUnit timeUnit)
          Block until this channel becomes readable again, or until the timeout expires.
 void awaitWritable()
          Block until this channel becomes writable again.
 void awaitWritable(long time, java.util.concurrent.TimeUnit timeUnit)
          Block until this channel becomes writable again, or until the timeout expires.
 void close()
           
 java.net.SocketAddress getLocalAddress()
          Get the local address that this channel is bound to.
<T> T
getOption(ChannelOption<T> option)
          Get the value of a channel option.
 java.util.Set<ChannelOption<?>> getOptions()
          Get the options that may be set on this channel.
 java.net.SocketAddress getPeerAddress()
          Get the peer address of this channel.
 boolean isOpen()
           
 int read(java.nio.ByteBuffer dst)
           
 long read(java.nio.ByteBuffer[] dsts)
           
 long read(java.nio.ByteBuffer[] dsts, int offset, int length)
           
 void resumeReads()
          Resume reads on this channel.
 void resumeWrites()
          Resume writes on this channel.
<T> Configurable
setOption(ChannelOption<T> option, T value)
          Set an option for this channel.
 void shutdownReads()
          Places this readable channel at "end of stream".
 void shutdownWrites()
          Indicate that writing is complete for this channel.
 void suspendReads()
          Suspend further reads on this channel.
 void suspendWrites()
          Suspend further writes on this channel.
 java.lang.String toString()
           
 int write(java.nio.ByteBuffer src)
           
 long write(java.nio.ByteBuffer[] srcs)
           
 long write(java.nio.ByteBuffer[] srcs, int offset, int length)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NioTcpChannel

public NioTcpChannel(NioXnio nioXnio,
                     java.nio.channels.SocketChannel socketChannel,
                     IoHandler<? super TcpChannel> handler,
                     java.util.concurrent.Executor executor,
                     boolean manage)
              throws java.io.IOException
Throws:
java.io.IOException
Method Detail

write

public long write(java.nio.ByteBuffer[] srcs,
                  int offset,
                  int length)
           throws java.io.IOException
Specified by:
write in interface java.nio.channels.GatheringByteChannel
Throws:
java.io.IOException

write

public long write(java.nio.ByteBuffer[] srcs)
           throws java.io.IOException
Specified by:
write in interface java.nio.channels.GatheringByteChannel
Throws:
java.io.IOException

write

public int write(java.nio.ByteBuffer src)
          throws java.io.IOException
Specified by:
write in interface java.nio.channels.WritableByteChannel
Throws:
java.io.IOException

isOpen

public boolean isOpen()
Specified by:
isOpen in interface java.nio.channels.Channel

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in interface java.nio.channels.Channel
Throws:
java.io.IOException

read

public long read(java.nio.ByteBuffer[] dsts,
                 int offset,
                 int length)
          throws java.io.IOException
Specified by:
read in interface java.nio.channels.ScatteringByteChannel
Throws:
java.io.IOException

read

public long read(java.nio.ByteBuffer[] dsts)
          throws java.io.IOException
Specified by:
read in interface java.nio.channels.ScatteringByteChannel
Throws:
java.io.IOException

read

public int read(java.nio.ByteBuffer dst)
         throws java.io.IOException
Specified by:
read in interface java.nio.channels.ReadableByteChannel
Throws:
java.io.IOException

suspendReads

public void suspendReads()
Description copied from interface: SuspendableReadChannel
Suspend further reads on this channel. The IoReadHandler.handleReadable(java.nio.channels.Channel) method will not be called until reads are resumed.

Specified by:
suspendReads in interface SuspendableReadChannel

suspendWrites

public void suspendWrites()
Description copied from interface: SuspendableWriteChannel
Suspend further writes on this channel. The IoWriteHandler.handleWritable(java.nio.channels.Channel) method will not be called until writes are resumed.

Specified by:
suspendWrites in interface SuspendableWriteChannel

resumeReads

public void resumeReads()
Description copied from interface: SuspendableReadChannel
Resume reads on this channel. The IoReadHandler.handleReadable(java.nio.channels.Channel) method will be called as soon as there is data available to be read.

Specified by:
resumeReads in interface SuspendableReadChannel

resumeWrites

public void resumeWrites()
Description copied from interface: SuspendableWriteChannel
Resume writes on this channel. The IoWriteHandler.handleWritable(java.nio.channels.Channel) method will be called as soon as there is space in the channel's transmit buffer.

Specified by:
resumeWrites in interface SuspendableWriteChannel

shutdownReads

public void shutdownReads()
                   throws java.io.IOException
Description copied from interface: SuspendableReadChannel
Places this readable channel at "end of stream". Further reads will result in EOF.

Specified by:
shutdownReads in interface SuspendableReadChannel
Throws:
java.io.IOException - if an I/O error occurs

shutdownWrites

public void shutdownWrites()
                    throws java.io.IOException
Description copied from interface: SuspendableWriteChannel
Indicate that writing is complete for this channel. Further attempts to write after shutdown will result in an exception.

Specified by:
shutdownWrites in interface SuspendableWriteChannel
Throws:
java.io.IOException - if an I/O error occurs

awaitReadable

public void awaitReadable()
                   throws java.io.IOException
Description copied from interface: SuspendableReadChannel
Block until this channel becomes readable again. This method may return spuriously before the channel becomes readable.

Specified by:
awaitReadable in interface SuspendableReadChannel
Throws:
java.io.IOException - if an I/O error occurs

awaitReadable

public void awaitReadable(long time,
                          java.util.concurrent.TimeUnit timeUnit)
                   throws java.io.IOException
Description copied from interface: SuspendableReadChannel
Block until this channel becomes readable again, or until the timeout expires. This method may return spuriously before the channel becomes readable or the timeout expires.

Specified by:
awaitReadable in interface SuspendableReadChannel
Parameters:
time - the time to wait
timeUnit - the time unit
Throws:
java.io.IOException - if an I/O error occurs

awaitWritable

public void awaitWritable()
                   throws java.io.IOException
Description copied from interface: SuspendableWriteChannel
Block until this channel becomes writable again. This method may return spuriously before the channel becomes writable.

Specified by:
awaitWritable in interface SuspendableWriteChannel
Throws:
java.io.IOException - if an I/O error occurs

awaitWritable

public void awaitWritable(long time,
                          java.util.concurrent.TimeUnit timeUnit)
                   throws java.io.IOException
Description copied from interface: SuspendableWriteChannel
Block until this channel becomes writable again, or until the timeout expires. This method may return spuriously before the channel becomes writable or the timeout expires.

Specified by:
awaitWritable in interface SuspendableWriteChannel
Parameters:
time - the time to wait
timeUnit - the time unit
Throws:
java.io.IOException - if an I/O error occurs

getPeerAddress

public java.net.SocketAddress getPeerAddress()
Description copied from interface: ConnectedChannel
Get the peer address of this channel.

Specified by:
getPeerAddress in interface ConnectedChannel<java.net.SocketAddress>
Returns:
the peer address

getLocalAddress

public java.net.SocketAddress getLocalAddress()
Description copied from interface: BoundChannel
Get the local address that this channel is bound to.

Specified by:
getLocalAddress in interface BoundChannel<java.net.SocketAddress>
Returns:
the local address

getOption

public <T> T getOption(ChannelOption<T> option)
            throws UnsupportedOptionException,
                   java.io.IOException
Description copied from interface: Configurable
Get the value of a channel option.

Specified by:
getOption in interface Configurable
Type Parameters:
T - the type of the option value
Parameters:
option - the option to get
Returns:
the value of the option
Throws:
UnsupportedOptionException - if the option is not supported by this channel
java.io.IOException - if an I/O error occurred when reading the option

getOptions

public java.util.Set<ChannelOption<?>> getOptions()
Description copied from interface: Configurable
Get the options that may be set on this channel.

Specified by:
getOptions in interface Configurable
Returns:
an unmodifiable set of options

setOption

public <T> Configurable setOption(ChannelOption<T> option,
                                  T value)
                       throws java.lang.IllegalArgumentException,
                              java.io.IOException
Description copied from interface: Configurable
Set an option for this channel.

Specified by:
setOption in interface Configurable
Type Parameters:
T - the type of the option value
Parameters:
option - the option to set
value - the value of the option to set
Returns:
this channel
Throws:
UnsupportedOptionException - if the option is not supported by this channel
java.lang.IllegalArgumentException - if the value is not acceptable for this option
java.io.IOException - if an I/O error occured when modifying the option

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object