changeset 786:9889b32ad574

Eliminate cast when joining multicast group AsynchronousDatagramChannel dependency missing in build
author alanb
date Sat, 25 Oct 2008 13:20:39 +0100
parents 44f2691ef9be
children 1616d976e9da
files make/java/nio/FILES_java.gmk src/share/classes/java/nio/channels/AsynchronousDatagramChannel.java src/share/classes/java/nio/channels/DatagramChannel.java src/share/classes/java/nio/channels/MulticastChannel.java src/share/sample/nio/multicast/Reader.java test/java/nio/channels/AsynchronousDatagramChannel/Basic.java test/java/nio/channels/DatagramChannel/BasicMulticastTests.java test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java
diffstat 8 files changed, 29 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/make/java/nio/FILES_java.gmk	Sat Oct 25 13:13:44 2008 +0100
+++ b/make/java/nio/FILES_java.gmk	Sat Oct 25 13:20:39 2008 +0100
@@ -34,6 +34,7 @@
 	java/nio/channels/AsynchronousByteChannel.java \
 	java/nio/channels/AsynchronousChannel.java \
 	java/nio/channels/AsynchronousChannelGroup.java \
+	java/nio/channels/AsynchronousDatagramChannel.java \
 	java/nio/channels/AsynchronousFileChannel.java \
 	java/nio/channels/AsynchronousServerSocketChannel.java \
 	java/nio/channels/AsynchronousSocketChannel.java \
--- a/src/share/classes/java/nio/channels/AsynchronousDatagramChannel.java	Sat Oct 25 13:13:44 2008 +0100
+++ b/src/share/classes/java/nio/channels/AsynchronousDatagramChannel.java	Sat Oct 25 13:20:39 2008 +0100
@@ -51,7 +51,7 @@
  * connected until it is disconnected or closed.
  *
  * <p> Socket options are configured using the {@link #setOption(SocketOption,Object)
- * setOption} method. An asynchronousdatagram channel to an Internet Protocol
+ * setOption} method. An asynchronous datagram channel to an Internet Protocol
  * (IP) socket supports the following options:
  * <blockquote>
  * <table border>
@@ -126,7 +126,7 @@
  */
 
 public abstract class AsynchronousDatagramChannel
-    implements AsynchronousByteChannel, NetworkChannel
+    implements AsynchronousByteChannel, MulticastChannel
 {
     private final AsynchronousChannelProvider provider;
 
--- a/src/share/classes/java/nio/channels/DatagramChannel.java	Sat Oct 25 13:13:44 2008 +0100
+++ b/src/share/classes/java/nio/channels/DatagramChannel.java	Sat Oct 25 13:20:39 2008 +0100
@@ -100,10 +100,6 @@
  * </blockquote>
  * Additional (implementation specific) options may also be supported.
  *
- * <p> Furthermore, a datagram channel to an Internet Protocol socket supports
- * multicasting and may be cast to a {@link MulticastChannel} so as to join a
- * multicast group and receive multicast datagrams sent to the group.
- *
  * <p> Datagram channels are safe for use by multiple concurrent threads.  They
  * support concurrent reading and writing, though at most one thread may be
  * reading and at most one thread may be writing at any given time.  </p>
@@ -116,7 +112,7 @@
 
 public abstract class DatagramChannel
     extends AbstractSelectableChannel
-    implements ByteChannel, ScatteringByteChannel, GatheringByteChannel, NetworkChannel
+    implements ByteChannel, ScatteringByteChannel, GatheringByteChannel, MulticastChannel
 {
 
     /**
--- a/src/share/classes/java/nio/channels/MulticastChannel.java	Sat Oct 25 13:13:44 2008 +0100
+++ b/src/share/classes/java/nio/channels/MulticastChannel.java	Sat Oct 25 13:20:39 2008 +0100
@@ -113,7 +113,7 @@
  *
  *     InetAddress group = InetAddress.getByName("225.4.5.6");
  *
- *     MembershipKey key = ((MulticastChannel)dc).join(group, ni);
+ *     MembershipKey key = dc.join(group, ni);
  * </pre>
  *
  * @since 1.7
@@ -150,6 +150,8 @@
      * @throws  IllegalStateException
      *          If the channel already has source-specific membership of the
      *          group on the interface
+     * @throws  UnsupportedOperationException
+     *          If the channel's socket is not an Internet Protocol socket
      * @throws  ClosedChannelException
      *          If this channel is closed
      * @throws  IOException
@@ -196,7 +198,8 @@
      *          If the channel is currently a member of the group on the given
      *          interface to receive all datagrams
      * @throws  UnsupportedOperationException
-     *          If the underlying operation system does not support source filtering
+     *          If the channel's socket is not an Internet Protocol socket or
+     *          source filtering is not supported
      * @throws  ClosedChannelException
      *          If this channel is closed
      * @throws  IOException
--- a/src/share/sample/nio/multicast/Reader.java	Sat Oct 25 13:13:44 2008 +0100
+++ b/src/share/sample/nio/multicast/Reader.java	Sat Oct 25 13:20:39 2008 +0100
@@ -101,7 +101,7 @@
 
         if (includeList.isEmpty()) {
             // join group and block addresses on the exclude list
-            MembershipKey key = ((MulticastChannel)dc).join(target.group(), target.interf());
+            MembershipKey key = dc.join(target.group(), target.interf());
             for (InetAddress source: excludeList) {
                 key.block(source);
             }
--- a/test/java/nio/channels/AsynchronousDatagramChannel/Basic.java	Sat Oct 25 13:13:44 2008 +0100
+++ b/test/java/nio/channels/AsynchronousDatagramChannel/Basic.java	Sat Oct 25 13:20:39 2008 +0100
@@ -354,7 +354,7 @@
         // join group
         InetAddress group = InetAddress.getByName("225.4.5.6");
         NetworkInterface interf = NetworkInterface.getByInetAddress(lh);
-        MembershipKey key = ((MulticastChannel)ch).join(group, interf);
+        MembershipKey key = ch.join(group, interf);
 
         // check key
         if (key.channel() != ch)
--- a/test/java/nio/channels/DatagramChannel/BasicMulticastTests.java	Sat Oct 25 13:13:44 2008 +0100
+++ b/test/java/nio/channels/DatagramChannel/BasicMulticastTests.java	Sat Oct 25 13:20:39 2008 +0100
@@ -55,8 +55,8 @@
             .bind(new InetSocketAddress(source, 0));
 
         // check existing key is returned
-        MembershipKey key = ((MulticastChannel)dc).join(group, nif);
-        MembershipKey other = ((MulticastChannel)dc).join(group, nif);
+        MembershipKey key = dc.join(group, nif);
+        MembershipKey other = dc.join(group, nif);
         if (other != key) {
             throw new RuntimeException("existing key not returned");
         }
@@ -79,8 +79,8 @@
 
         // source-specific
         try {
-            key = ((MulticastChannel)dc).join(group, nif, source);
-            other = ((MulticastChannel)dc).join(group, nif, source);
+            key = dc.join(group, nif, source);
+            other = dc.join(group, nif, source);
             if (other != key) {
                 throw new RuntimeException("existing key not returned");
             }
@@ -123,18 +123,18 @@
 
         // IllegalStateException
         MembershipKey key;
-        key = ((MulticastChannel)dc).join(group, nif);
+        key = dc.join(group, nif);
         try {
-            ((MulticastChannel)dc).join(group, nif, thisHost);
+            dc.join(group, nif, thisHost);
             throw new RuntimeException("IllegalStateException not thrown");
         } catch (IllegalStateException x) {
         } catch (UnsupportedOperationException x) {
         }
         key.drop();
         try {
-            key = ((MulticastChannel)dc).join(group, nif, thisHost);
+            key = dc.join(group, nif, thisHost);
             try {
-                ((MulticastChannel)dc).join(group, nif);
+                dc.join(group, nif);
                 throw new RuntimeException("IllegalStateException not thrown");
             } catch (IllegalStateException x) {
             }
@@ -144,12 +144,12 @@
 
         // IllegalArgumentException
         try {
-            ((MulticastChannel)dc).join(notGroup, nif);
+            dc.join(notGroup, nif);
             throw new RuntimeException("IllegalArgumentException not thrown");
         } catch (IllegalArgumentException x) {
         }
         try {
-            ((MulticastChannel)dc).join(notGroup, nif, thisHost);
+            dc.join(notGroup, nif, thisHost);
             throw new RuntimeException("IllegalArgumentException not thrown");
         } catch (IllegalArgumentException x) {
         } catch (UnsupportedOperationException x) {
@@ -157,17 +157,17 @@
 
         // NullPointerException
         try {
-            ((MulticastChannel)dc).join(null, nif);
+            dc.join(null, nif);
             throw new RuntimeException("NullPointerException not thrown");
         } catch (NullPointerException x) {
         }
         try {
-            ((MulticastChannel)dc).join(group, null);
+            dc.join(group, null);
             throw new RuntimeException("NullPointerException not thrown");
         } catch (NullPointerException x) {
         }
         try {
-            ((MulticastChannel)dc).join(group, nif, null);
+            dc.join(group, nif, null);
             throw new RuntimeException("NullPointerException not thrown");
         } catch (NullPointerException x) {
         } catch (UnsupportedOperationException x) {
@@ -177,12 +177,12 @@
 
         // ClosedChannelException
         try {
-            ((MulticastChannel)dc).join(group, nif);
+            dc.join(group, nif);
             throw new RuntimeException("ClosedChannelException not thrown");
         } catch (ClosedChannelException x) {
         }
         try {
-            ((MulticastChannel)dc).join(group, nif, thisHost);
+            dc.join(group, nif, thisHost);
             throw new RuntimeException("ClosedChannelException not thrown");
         } catch (ClosedChannelException x) {
         } catch (UnsupportedOperationException x) {
--- a/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java	Sat Oct 25 13:13:44 2008 +0100
+++ b/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java	Sat Oct 25 13:20:39 2008 +0100
@@ -142,7 +142,7 @@
         // join group
         System.out.format("join %s @ %s\n", group.getHostAddress(),
             nif.getName());
-        MembershipKey key = ((MulticastChannel)dc).join(group, nif);
+        MembershipKey key = dc.join(group, nif);
 
         // send message to group
         int port = ((InetSocketAddress)dc.getLocalAddress()).getPort();
@@ -181,14 +181,14 @@
             nif.getName(), bogus.getHostAddress());
         try {
             // may throw UOE
-            key = ((MulticastChannel)dc).join(group, nif, bogus);
+            key = dc.join(group, nif, bogus);
 
             id = sendDatagram(source, nif, group, port);
             receiveDatagram(dc, null, id);
 
             System.out.format("join %s @ %s only-source %s\n", group.getHostAddress(),
                 nif.getName(), source.getHostAddress());
-            key = ((MulticastChannel)dc).join(group, nif, source);
+            key = dc.join(group, nif, source);
 
             id = sendDatagram(source, nif, group, port);
             receiveDatagram(dc, source, id);