org.jboss.xnio.nio
Class BioDatagramChannelImpl

java.lang.Object
  extended by org.jboss.xnio.nio.BioDatagramChannelImpl
All Implemented Interfaces:
java.io.Closeable, java.nio.channels.Channel, BoundChannel<java.net.SocketAddress>, Configurable, MultipointDatagramChannel<java.net.SocketAddress>, MultipointMessageChannel<java.net.SocketAddress>, MultipointReadableMessageChannel<java.net.SocketAddress>, MultipointWritableMessageChannel<java.net.SocketAddress>, SuspendableChannel, SuspendableReadChannel, SuspendableWriteChannel, UdpChannel
Direct Known Subclasses:
BioMulticastChannelImpl

public class BioDatagramChannelImpl
extends java.lang.Object
implements UdpChannel


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.xnio.channels.UdpChannel
UdpChannel.Key
 
Field Summary
protected static java.util.Set<ChannelOption<?>> OPTIONS
           
 
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.
 boolean isOpen()
           
 UdpChannel.Key join(java.net.InetAddress group, java.net.NetworkInterface iface)
          Join a multicast group to begin receiving all datagrams sent to the group.
 UdpChannel.Key join(java.net.InetAddress group, java.net.NetworkInterface iface, java.net.InetAddress source)
          Join a multicast group to begin receiving all datagrams sent to the group from a given source address.
protected  void open()
           
 MultipointReadResult<java.net.SocketAddress> receive(java.nio.ByteBuffer buffer)
          Receive a message via this channel.
 void resumeReads()
          Resume reads on this channel.
 void resumeWrites()
          Resume writes on this channel.
 boolean send(java.net.SocketAddress target, java.nio.ByteBuffer buffer)
          Send a buffer to a destination.
 boolean send(java.net.SocketAddress target, java.nio.ByteBuffer[] dsts)
          Send a message with data from multiple buffers to a destination.
 boolean send(java.net.SocketAddress target, java.nio.ByteBuffer[] dsts, int offset, int length)
          Send a message with data from multiple buffers to a destination.
<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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPTIONS

protected static final java.util.Set<ChannelOption<?>> OPTIONS
Method Detail

open

protected void open()

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

receive

public MultipointReadResult<java.net.SocketAddress> receive(java.nio.ByteBuffer buffer)
                                                     throws java.io.IOException
Description copied from interface: MultipointReadableMessageChannel
Receive a message via this channel. If a message is immediately available, then the datagram is written into the given buffer and the source and destination addresses (if available) are returned. If there is no message immediately available, this method will return null.

Specified by:
receive in interface MultipointReadableMessageChannel<java.net.SocketAddress>
Parameters:
buffer - the buffer into which data should be read
Returns:
a result instance if a message was found and processed, or null if the operation would block
Throws:
java.io.IOException - if an I/O error occurs

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

send

public boolean send(java.net.SocketAddress target,
                    java.nio.ByteBuffer buffer)
             throws java.io.IOException
Description copied from interface: MultipointWritableMessageChannel
Send a buffer to a destination.

Specified by:
send in interface MultipointWritableMessageChannel<java.net.SocketAddress>
Parameters:
target - the destination
buffer - the data to send
Returns:
true if the message was sent, or false if the channel is not currently writable
Throws:
java.io.IOException - if an I/O error occurs

send

public boolean send(java.net.SocketAddress target,
                    java.nio.ByteBuffer[] dsts)
             throws java.io.IOException
Description copied from interface: MultipointWritableMessageChannel
Send a message with data from multiple buffers to a destination.

Specified by:
send in interface MultipointWritableMessageChannel<java.net.SocketAddress>
Parameters:
target - the destination
dsts - the data to send
Returns:
true if the message was sent, or false if the channel is not currently writable
Throws:
java.io.IOException - if an I/O error occurs

send

public boolean send(java.net.SocketAddress target,
                    java.nio.ByteBuffer[] dsts,
                    int offset,
                    int length)
             throws java.io.IOException
Description copied from interface: MultipointWritableMessageChannel
Send a message with data from multiple buffers to a destination.

Specified by:
send in interface MultipointWritableMessageChannel<java.net.SocketAddress>
Parameters:
target - the destination
dsts - the data to send
offset - the offset into the buffers array
length - the number of buffers to read from
Returns:
true if the message was sent, or false if the channel is not currently writable
Throws:
java.io.IOException - if an I/O error occurs

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

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

join

public UdpChannel.Key join(java.net.InetAddress group,
                           java.net.NetworkInterface iface)
                    throws java.io.IOException
Description copied from interface: UdpChannel
Join a multicast group to begin receiving all datagrams sent to the group. A multicast channel may join several multicast groups, including the same group on more than one interface. An implementation may impose a limit on the number of groups that may be joined at the same time.

Specified by:
join in interface UdpChannel
Parameters:
group - the multicast address to join
iface - the network interface to join on
Returns:
a new key
Throws:
java.io.IOException - if an I/O error occurs

join

public UdpChannel.Key join(java.net.InetAddress group,
                           java.net.NetworkInterface iface,
                           java.net.InetAddress source)
                    throws java.io.IOException
Description copied from interface: UdpChannel
Join a multicast group to begin receiving all datagrams sent to the group from a given source address. A multicast channel may join several multicast groups, including the same group on more than one interface. An implementation may impose a limit on the number of groups that may be joined at the same time.

Specified by:
join in interface UdpChannel
Parameters:
group - the multicast address to join
iface - the network interface to join on
source - the source address to listen for
Returns:
a new key
Throws:
java.io.IOException - if an I/O error occurs