jdk/src/share/classes/java/nio/channels/AsynchronousDatagramChannel.java
changeset 7382 e1ed8c9e12e5
parent 7381 5d924959cd81
parent 7140 4951967a61b4
child 7383 cbd66f8db06b
equal deleted inserted replaced
7381:5d924959cd81 7382:e1ed8c9e12e5
     1 /*
       
     2  * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package java.nio.channels;
       
    27 
       
    28 import java.nio.channels.spi.*;
       
    29 import java.util.concurrent.TimeUnit;
       
    30 import java.util.concurrent.Future;
       
    31 import java.io.IOException;
       
    32 import java.net.SocketOption;
       
    33 import java.net.SocketAddress;
       
    34 import java.net.ProtocolFamily;
       
    35 import java.nio.ByteBuffer;
       
    36 
       
    37 /**
       
    38  * An asynchronous channel for datagram-oriented sockets.
       
    39  *
       
    40  * <p> An asynchronous datagram channel is created by invoking one of the {@link
       
    41  * #open open} methods defined by this class. It is not possible to create a channel
       
    42  * for an arbitrary, pre-existing datagram socket. A newly-created asynchronous
       
    43  * datagram channel is open but not connected. It need not be connected in order
       
    44  * for the {@link #send send} and {@link #receive receive} methods to be used.
       
    45  * A datagram channel may be connected, by invoking its {@link #connect connect}
       
    46  * method, in order to avoid the overhead of the security checks that are otherwise
       
    47  * performed as part of every send and receive operation when a security manager
       
    48  * is set. The channel must be connected in order to use the {@link #read read}
       
    49  * and {@link #write write} methods, since those methods do not accept or return
       
    50  * socket addresses. Once connected, an asynchronous datagram channel remains
       
    51  * connected until it is disconnected or closed.
       
    52  *
       
    53  * <p> Socket options are configured using the {@link #setOption(SocketOption,Object)
       
    54  * setOption} method. An asynchronous datagram channel to an Internet Protocol
       
    55  * (IP) socket supports the following options:
       
    56  * <blockquote>
       
    57  * <table border>
       
    58  *   <tr>
       
    59  *     <th>Option Name</th>
       
    60  *     <th>Description</th>
       
    61  *   </tr>
       
    62  *   <tr>
       
    63  *     <td> {@link java.net.StandardSocketOption#SO_SNDBUF SO_SNDBUF} </td>
       
    64  *     <td> The size of the socket send buffer </td>
       
    65  *   </tr>
       
    66  *   <tr>
       
    67  *     <td> {@link java.net.StandardSocketOption#SO_RCVBUF SO_RCVBUF} </td>
       
    68  *     <td> The size of the socket receive buffer </td>
       
    69  *   </tr>
       
    70  *   <tr>
       
    71  *     <td> {@link java.net.StandardSocketOption#SO_REUSEADDR SO_REUSEADDR} </td>
       
    72  *     <td> Re-use address </td>
       
    73  *   </tr>
       
    74  *   <tr>
       
    75  *     <td> {@link java.net.StandardSocketOption#SO_BROADCAST SO_BROADCAST} </td>
       
    76  *     <td> Allow transmission of broadcast datagrams </td>
       
    77  *   </tr>
       
    78  *   <tr>
       
    79  *     <td> {@link java.net.StandardSocketOption#IP_TOS IP_TOS} </td>
       
    80  *     <td> The Type of Service (ToS) octet in the Internet Protocol (IP) header </td>
       
    81  *   </tr>
       
    82  *   <tr>
       
    83  *     <td> {@link java.net.StandardSocketOption#IP_MULTICAST_IF IP_MULTICAST_IF} </td>
       
    84  *     <td> The network interface for Internet Protocol (IP) multicast datagrams </td>
       
    85  *   </tr>
       
    86  *   <tr>
       
    87  *     <td> {@link java.net.StandardSocketOption#IP_MULTICAST_TTL
       
    88  *       IP_MULTICAST_TTL} </td>
       
    89  *     <td> The <em>time-to-live</em> for Internet Protocol (IP) multicast
       
    90  *       datagrams </td>
       
    91  *   </tr>
       
    92  *   <tr>
       
    93  *     <td> {@link java.net.StandardSocketOption#IP_MULTICAST_LOOP
       
    94  *       IP_MULTICAST_LOOP} </td>
       
    95  *     <td> Loopback for Internet Protocol (IP) multicast datagrams </td>
       
    96  *   </tr>
       
    97  * </table>
       
    98  * </blockquote>
       
    99  * Additional (implementation specific) options may also be supported.
       
   100  *
       
   101  * <p> Asynchronous datagram channels allow more than one read/receive and
       
   102  * write/send to be oustanding at any given time.
       
   103  *
       
   104  * <p> <b>Usage Example:</b>
       
   105  * <pre>
       
   106  *  final AsynchronousDatagramChannel dc = AsynchronousDatagramChannel.open()
       
   107  *      .bind(new InetSocketAddress(4000));
       
   108  *
       
   109  *  // print the source address of all packets that we receive
       
   110  *  dc.receive(buffer, buffer, new CompletionHandler&lt;SocketAddress,ByteBuffer&gt;() {
       
   111  *      public void completed(SocketAddress sa, ByteBuffer buffer) {
       
   112  *          System.out.println(sa);
       
   113  *          buffer.clear();
       
   114  *          dc.receive(buffer, buffer, this);
       
   115  *      }
       
   116  *      public void failed(Throwable exc, ByteBuffer buffer) {
       
   117  *          ...
       
   118  *      }
       
   119  *  });
       
   120  * </pre>
       
   121  *
       
   122  * @since 1.7
       
   123  */
       
   124 
       
   125 public abstract class AsynchronousDatagramChannel
       
   126     implements AsynchronousByteChannel, MulticastChannel
       
   127 {
       
   128     private final AsynchronousChannelProvider provider;
       
   129 
       
   130     /**
       
   131      * Initializes a new instance of this class.
       
   132      */
       
   133     protected AsynchronousDatagramChannel(AsynchronousChannelProvider provider) {
       
   134         this.provider = provider;
       
   135     }
       
   136 
       
   137     /**
       
   138      * Returns the provider that created this channel.
       
   139      */
       
   140     public final AsynchronousChannelProvider provider() {
       
   141         return provider;
       
   142     }
       
   143 
       
   144     /**
       
   145      * Opens an asynchronous datagram channel.
       
   146      *
       
   147      * <p> The new channel is created by invoking the {@link
       
   148      * java.nio.channels.spi.AsynchronousChannelProvider#openAsynchronousDatagramChannel
       
   149      * openAsynchronousDatagramChannel} method on the {@link
       
   150      * java.nio.channels.spi.AsynchronousChannelProvider} object that created
       
   151      * the given group (or the default provider where {@code group} is {@code
       
   152      * null}).
       
   153      *
       
   154      * <p> The {@code family} parameter is used to specify the {@link ProtocolFamily}.
       
   155      * If the datagram channel is to be used for Internet Protocol {@link
       
   156      * MulticastChannel multicasting} then this parameter should correspond to
       
   157      * the address type of the multicast groups that this channel will join.
       
   158      *
       
   159      * @param   family
       
   160      *          The protocol family, or {@code null} to use the default protocol
       
   161      *          family
       
   162      * @param   group
       
   163      *          The group to which the newly constructed channel should be bound,
       
   164      *          or {@code null} for the default group
       
   165      *
       
   166      * @return  A new asynchronous datagram channel
       
   167      *
       
   168      * @throws  UnsupportedOperationException
       
   169      *          If the specified protocol family is not supported. For example,
       
   170      *          suppose the parameter is specified as {@link
       
   171      *          java.net.StandardProtocolFamily#INET6 INET6} but IPv6 is not
       
   172      *          enabled on the platform.
       
   173      * @throws  ShutdownChannelGroupException
       
   174      *          The specified group is shutdown
       
   175      * @throws  IOException
       
   176      *          If an I/O error occurs
       
   177      */
       
   178     public static AsynchronousDatagramChannel open(ProtocolFamily family,
       
   179                                                    AsynchronousChannelGroup group)
       
   180         throws IOException
       
   181     {
       
   182         AsynchronousChannelProvider provider = (group == null) ?
       
   183             AsynchronousChannelProvider.provider() : group.provider();
       
   184         return provider.openAsynchronousDatagramChannel(family, group);
       
   185     }
       
   186 
       
   187     /**
       
   188      * Opens an asynchronous datagram channel.
       
   189      *
       
   190      * <p> This method returns an asynchronous datagram channel that is
       
   191      * bound to the <em>default group</em>. This method is equivalent to evaluating
       
   192      * the expression:
       
   193      * <blockquote><pre>
       
   194      * open((ProtocolFamily)null,&nbsp;(AsynchronousChannelGroup)null);
       
   195      * </pre></blockquote>
       
   196      *
       
   197      * @return  A new asynchronous datagram channel
       
   198      *
       
   199      * @throws  IOException
       
   200      *          If an I/O error occurs
       
   201      */
       
   202     public static AsynchronousDatagramChannel open()
       
   203         throws IOException
       
   204     {
       
   205         return open(null, null);
       
   206     }
       
   207 
       
   208     // -- Socket-specific operations --
       
   209 
       
   210     /**
       
   211      * @throws  AlreadyBoundException               {@inheritDoc}
       
   212      * @throws  UnsupportedAddressTypeException     {@inheritDoc}
       
   213      * @throws  ClosedChannelException              {@inheritDoc}
       
   214      * @throws  IOException                         {@inheritDoc}
       
   215      * @throws  SecurityException
       
   216      *          If a security manager has been installed and its {@link
       
   217      *          SecurityManager#checkListen checkListen} method denies the
       
   218      *          operation
       
   219      */
       
   220     @Override
       
   221     public abstract AsynchronousDatagramChannel bind(SocketAddress local)
       
   222         throws IOException;
       
   223 
       
   224     /**
       
   225      * @throws  IllegalArgumentException                {@inheritDoc}
       
   226      * @throws  ClosedChannelException                  {@inheritDoc}
       
   227      * @throws  IOException                             {@inheritDoc}
       
   228      */
       
   229     @Override
       
   230     public abstract <T> AsynchronousDatagramChannel setOption(SocketOption<T> name, T value)
       
   231         throws IOException;
       
   232 
       
   233     /**
       
   234      * Returns the remote address to which this channel is connected.
       
   235      *
       
   236      * <p> Where the channel is connected to an Internet Protocol socket address
       
   237      * then the return value from this method is of type {@link
       
   238      * java.net.InetSocketAddress}.
       
   239      *
       
   240      * @return  The remote address; {@code null} if the channel's socket is not
       
   241      *          connected
       
   242      *
       
   243      * @throws  ClosedChannelException
       
   244      *          If the channel is closed
       
   245      * @throws  IOException
       
   246      *          If an I/O error occurs
       
   247      */
       
   248     public abstract SocketAddress getRemoteAddress() throws IOException;
       
   249 
       
   250     /**
       
   251      * Connects this channel's socket.
       
   252      *
       
   253      * <p> The channel's socket is configured so that it only receives
       
   254      * datagrams from, and sends datagrams to, the given remote <i>peer</i>
       
   255      * address.  Once connected, datagrams may not be received from or sent to
       
   256      * any other address.  A datagram socket remains connected until it is
       
   257      * explicitly disconnected or until it is closed.
       
   258      *
       
   259      * <p> This method performs exactly the same security checks as the {@link
       
   260      * java.net.DatagramSocket#connect connect} method of the {@link
       
   261      * java.net.DatagramSocket} class.  That is, if a security manager has been
       
   262      * installed then this method verifies that its {@link
       
   263      * java.lang.SecurityManager#checkAccept checkAccept} and {@link
       
   264      * java.lang.SecurityManager#checkConnect checkConnect} methods permit
       
   265      * datagrams to be received from and sent to, respectively, the given
       
   266      * remote address.
       
   267      *
       
   268      * <p> This method may be invoked at any time. Whether it has any effect
       
   269      * on outstanding read or write operations is implementation specific and
       
   270      * therefore not specified.
       
   271      *
       
   272      * @param  remote
       
   273      *         The remote address to which this channel is to be connected
       
   274      *
       
   275      * @return  This datagram channel
       
   276      *
       
   277      * @throws  ClosedChannelException
       
   278      *          If this channel is closed
       
   279      *
       
   280      * @throws  SecurityException
       
   281      *          If a security manager has been installed
       
   282      *          and it does not permit access to the given remote address
       
   283      *
       
   284      * @throws  IOException
       
   285      *          If some other I/O error occurs
       
   286      */
       
   287     public abstract AsynchronousDatagramChannel connect(SocketAddress remote)
       
   288         throws IOException;
       
   289 
       
   290     /**
       
   291      * Disconnects this channel's socket.
       
   292      *
       
   293      * <p> The channel's socket is configured so that it can receive datagrams
       
   294      * from, and sends datagrams to, any remote address so long as the security
       
   295      * manager, if installed, permits it.
       
   296      *
       
   297      * <p> This method may be invoked at any time. Whether it has any effect
       
   298      * on outstanding read or write operations is implementation specific and
       
   299      * therefore not specified.
       
   300      *
       
   301      * @return  This datagram channel
       
   302      *
       
   303      * @throws  IOException
       
   304      *          If some other I/O error occurs
       
   305      */
       
   306     public abstract AsynchronousDatagramChannel disconnect() throws IOException;
       
   307 
       
   308     /**
       
   309      * Receives a datagram via this channel.
       
   310      *
       
   311      * <p> This method initiates the receiving of a datagram into the given
       
   312      * buffer. The {@code handler} parameter is a completion handler that is
       
   313      * invoked when the receive operation completes (or fails). The result
       
   314      * passed to the completion handler is the datagram's source address.
       
   315      *
       
   316      * <p> The datagram is transferred into the given byte buffer starting at
       
   317      * its current position, as if by a regular {@link AsynchronousByteChannel#read
       
   318      * read} operation. If there are fewer bytes remaining in the buffer
       
   319      * than are required to hold the datagram then the remainder of the datagram
       
   320      * is silently discarded.
       
   321      *
       
   322      * <p> If a timeout is specified and the timeout elapses before the operation
       
   323      * completes then the operation completes with the exception {@link
       
   324      * InterruptedByTimeoutException}. When a timeout elapses then the state of
       
   325      * the {@link ByteBuffer} is not defined. The buffers should be discarded or
       
   326      * at least care must be taken to ensure that the buffer is not accessed
       
   327      * while the channel remains open.
       
   328      *
       
   329      * <p> When a security manager has been installed and the channel is not
       
   330      * connected, then it verifies that the source's address and port number are
       
   331      * permitted by the security manager's {@link SecurityManager#checkAccept
       
   332      * checkAccept} method. The permission check is performed with privileges that
       
   333      * are restricted by the calling context of this method. If the permission
       
   334      * check fails then the operation completes with a {@link SecurityException}.
       
   335      * The overhead of this security check can be avoided by first connecting the
       
   336      * socket via the {@link #connect connect} method.
       
   337      *
       
   338      * @param   dst
       
   339      *          The buffer into which the datagram is to be transferred
       
   340      * @param   timeout
       
   341      *          The timeout, or {@code 0L} for no timeout
       
   342      * @param   unit
       
   343      *          The time unit of the {@code timeout} argument
       
   344      * @param   attachment
       
   345      *          The object to attach to the I/O operation; can be {@code null}
       
   346      * @param   handler
       
   347      *          The handler for consuming the result
       
   348      *
       
   349      * @throws  IllegalArgumentException
       
   350      *          If the timeout is negative or the buffer is read-only
       
   351      * @throws  ShutdownChannelGroupException
       
   352      *          If the channel group has terminated
       
   353      */
       
   354     public abstract <A> void receive(ByteBuffer dst,
       
   355                                      long timeout,
       
   356                                      TimeUnit unit,
       
   357                                      A attachment,
       
   358                                      CompletionHandler<SocketAddress,? super A> handler);
       
   359 
       
   360     /**
       
   361      * Receives a datagram via this channel.
       
   362      *
       
   363      * <p> This method initiates the receiving of a datagram into the given
       
   364      * buffer. The {@code handler} parameter is a completion handler that is
       
   365      * invoked when the receive operation completes (or fails). The result
       
   366      * passed to the completion handler is the datagram's source address.
       
   367      *
       
   368      * <p> This method is equivalent to invoking {@link
       
   369      * #receive(ByteBuffer,long,TimeUnit,Object,CompletionHandler)} with a
       
   370      * timeout of {@code 0L}.
       
   371      *
       
   372      * @param   dst
       
   373      *          The buffer into which the datagram is to be transferred
       
   374      * @param   attachment
       
   375      *          The object to attach to the I/O operation; can be {@code null}
       
   376      * @param   handler
       
   377      *          The handler for consuming the result
       
   378      *
       
   379      * @throws  IllegalArgumentException
       
   380      *          If the buffer is read-only
       
   381      * @throws  ShutdownChannelGroupException
       
   382      *          If the channel group has terminated
       
   383      */
       
   384     public final <A> void receive(ByteBuffer dst,
       
   385                                   A attachment,
       
   386                                   CompletionHandler<SocketAddress,? super A> handler)
       
   387     {
       
   388         receive(dst, 0L, TimeUnit.MILLISECONDS, attachment, handler);
       
   389     }
       
   390 
       
   391     /**
       
   392      * Receives a datagram via this channel.
       
   393      *
       
   394      * <p> This method initiates the receiving of a datagram into the given
       
   395      * buffer. The method behaves in exactly the same manner as the {@link
       
   396      * #receive(ByteBuffer,Object,CompletionHandler)
       
   397      * receive(ByteBuffer,Object,CompletionHandler)} method except that instead
       
   398      * of specifying a completion handler, this method returns a {@code Future}
       
   399      * representing the pending result. The {@code Future}'s {@link Future#get()
       
   400      * get} method returns the datagram's source address.
       
   401      *
       
   402      * @param   dst
       
   403      *          The buffer into which the datagram is to be transferred
       
   404      *
       
   405      * @return  a {@code Future} object representing the pending result
       
   406      *
       
   407      * @throws  IllegalArgumentException
       
   408      *          If the buffer is read-only
       
   409      */
       
   410     public abstract Future<SocketAddress> receive(ByteBuffer dst);
       
   411 
       
   412     /**
       
   413      * Sends a datagram via this channel.
       
   414      *
       
   415      * <p> This method initiates sending of a datagram from the given buffer to
       
   416      * the given address. The {@code handler} parameter is a completion handler
       
   417      * that is invoked when the send completes (or fails). The result passed to
       
   418      * the completion handler is the number of bytes sent.
       
   419      *
       
   420      * <p> Otherwise this method works in the same manner as the {@link
       
   421      * AsynchronousByteChannel#write(ByteBuffer,Object,CompletionHandler)}
       
   422      * method.
       
   423      *
       
   424      * @param   src
       
   425      *          The buffer containing the datagram to be sent
       
   426      * @param   target
       
   427      *          The address to which the datagram is to be sent
       
   428      * @param   attachment
       
   429      *          The object to attach to the I/O operation; can be {@code null}
       
   430      * @param   handler
       
   431      *          The handler for consuming the result
       
   432      *
       
   433      * @throws  UnresolvedAddressException
       
   434      *          If the given remote address is not fully resolved
       
   435      * @throws  UnsupportedAddressTypeException
       
   436      *          If the type of the given remote address is not supported
       
   437      * @throws  IllegalArgumentException
       
   438      *          If the channel's socket is connected and is connected to an
       
   439      *          address that is not equal to {@code target}
       
   440      * @throws  SecurityException
       
   441      *          If a security manager has been installed and it does not permit
       
   442      *          datagrams to be sent to the given address
       
   443      * @throws  ShutdownChannelGroupException
       
   444      *          If the channel group has terminated
       
   445      */
       
   446     public abstract <A> void send(ByteBuffer src,
       
   447                                   SocketAddress target,
       
   448                                   A attachment,
       
   449                                   CompletionHandler<Integer,? super A> handler);
       
   450 
       
   451     /**
       
   452      * Sends a datagram via this channel.
       
   453      *
       
   454      * <p> This method initiates sending of a datagram from the given buffer to
       
   455      * the given address. The method behaves in exactly the same manner as the
       
   456      * {@link #send(ByteBuffer,SocketAddress,Object,CompletionHandler)
       
   457      * send(ByteBuffer,SocketAddress,Object,CompletionHandler)} method except
       
   458      * that instead of specifying a completion handler, this method returns a
       
   459      * {@code Future} representing the pending result. The {@code Future}'s
       
   460      * {@link Future#get() get} method returns the number of bytes sent.
       
   461      *
       
   462      * @param   src
       
   463      *          The buffer containing the datagram to be sent
       
   464      * @param   target
       
   465      *          The address to which the datagram is to be sent
       
   466      *
       
   467      * @return  a {@code Future} object representing the pending result
       
   468      *
       
   469      * @throws  UnresolvedAddressException
       
   470      *          If the given remote address is not fully resolved
       
   471      * @throws  UnsupportedAddressTypeException
       
   472      *          If the type of the given remote address is not supported
       
   473      * @throws  IllegalArgumentException
       
   474      *          If the channel's socket is connected and is connected to an
       
   475      *          address that is not equal to {@code target}
       
   476      * @throws  SecurityException
       
   477      *          If a security manager has been installed and it does not permit
       
   478      *          datagrams to be sent to the given address
       
   479      */
       
   480     public abstract Future<Integer> send(ByteBuffer src, SocketAddress target);
       
   481 
       
   482     /**
       
   483      * Receives a datagram via this channel.
       
   484      *
       
   485      * <p> This method initiates the receiving of a datagram into the given
       
   486      * buffer. The {@code handler} parameter is a completion handler that is
       
   487      * invoked when the receive operation completes (or fails). The result
       
   488      * passed to the completion handler is number of bytes read.
       
   489      *
       
   490      * <p> This method may only be invoked if this channel is connected, and it
       
   491      * only accepts datagrams from the peer that the channel is connected too.
       
   492      * The datagram is transferred into the given byte buffer starting at
       
   493      * its current position and exactly as specified in the {@link
       
   494      * AsynchronousByteChannel} interface. If there are fewer bytes
       
   495      * remaining in the buffer than are required to hold the datagram then the
       
   496      * remainder of the datagram is silently discarded.
       
   497      *
       
   498      * <p> If a timeout is specified and the timeout elapses before the operation
       
   499      * completes then the operation completes with the exception {@link
       
   500      * InterruptedByTimeoutException}. When a timeout elapses then the state of
       
   501      * the {@link ByteBuffer} is not defined. The buffers should be discarded or
       
   502      * at least care must be taken to ensure that the buffer is not accessed
       
   503      * while the channel remains open.
       
   504      *
       
   505      * @param   dst
       
   506      *          The buffer into which the datagram is to be transferred
       
   507      * @param   timeout
       
   508      *          The timeout, or {@code 0L} for no timeout
       
   509      * @param   unit
       
   510      *          The time unit of the {@code timeout} argument
       
   511      * @param   attachment
       
   512      *          The object to attach to the I/O operation; can be {@code null}
       
   513      * @param   handler
       
   514      *          The handler for consuming the result
       
   515      *
       
   516      * @throws  IllegalArgumentException
       
   517      *          If the timeout is negative or buffer is read-only
       
   518      * @throws  NotYetConnectedException
       
   519      *          If this channel is not connected
       
   520      * @throws  ShutdownChannelGroupException
       
   521      *          If the channel group has terminated
       
   522      */
       
   523     public abstract <A> void read(ByteBuffer dst,
       
   524                                   long timeout,
       
   525                                   TimeUnit unit,
       
   526                                   A attachment,
       
   527                                   CompletionHandler<Integer,? super A> handler);
       
   528 
       
   529     /**
       
   530      * @throws  NotYetConnectedException
       
   531      *          If this channel is not connected
       
   532      * @throws  ShutdownChannelGroupException
       
   533      *          If the channel group has terminated
       
   534      */
       
   535     @Override
       
   536     public final <A> void read(ByteBuffer dst,
       
   537                                A attachment,
       
   538                                CompletionHandler<Integer,? super A> handler)
       
   539     {
       
   540         read(dst, 0L, TimeUnit.MILLISECONDS, attachment, handler);
       
   541     }
       
   542 
       
   543     /**
       
   544      * @throws  NotYetConnectedException
       
   545      *          If this channel is not connected
       
   546      * @throws  ShutdownChannelGroupException
       
   547      *          If the channel group has terminated
       
   548      */
       
   549     @Override
       
   550     public abstract Future<Integer> read(ByteBuffer dst);
       
   551 
       
   552     /**
       
   553      * @throws  NotYetConnectedException
       
   554      *          If this channel is not connected
       
   555      * @throws  ShutdownChannelGroupException
       
   556      *          If the channel group has terminated
       
   557      */
       
   558     @Override
       
   559     public abstract <A> void  write(ByteBuffer src,
       
   560                                     A attachment,
       
   561                                     CompletionHandler<Integer,? super A> handler);
       
   562 
       
   563 
       
   564     /**
       
   565      * @throws  NotYetConnectedException
       
   566      *          If this channel is not connected
       
   567      * @throws  ShutdownChannelGroupException
       
   568      *          If the channel group has terminated
       
   569      */
       
   570     @Override
       
   571     public abstract Future<Integer> write(ByteBuffer src);
       
   572 }