jdk/src/share/classes/java/nio/channels/MulticastChannel.java
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 9679 d98ae8bc45fc
child 18574 4aeaeb541678
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 9679
diff changeset
     2
 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
     4
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    10
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    15
 * accompanied this code).
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    16
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
diff changeset
    23
 * questions.
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    24
 */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    25
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    26
package java.nio.channels;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    27
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    28
import java.net.InetAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    29
import java.net.NetworkInterface;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    30
import java.io.IOException;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    31
import java.net.ProtocolFamily;             // javadoc
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    32
import java.net.StandardProtocolFamily;     // javadoc
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 5506
diff changeset
    33
import java.net.StandardSocketOptions;      // javadoc
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    34
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    35
/**
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    36
 * A network channel that supports Internet Protocol (IP) multicasting.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    37
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    38
 * <p> IP multicasting is the transmission of IP datagrams to members of
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    39
 * a <em>group</em> that is zero or more hosts identified by a single destination
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    40
 * address.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    41
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    42
 * <p> In the case of a channel to an {@link StandardProtocolFamily#INET IPv4} socket,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    43
 * the underlying operating system supports <a href="http://www.ietf.org/rfc/rfc2236.txt">
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    44
 * <i>RFC&nbsp;2236: Internet Group Management Protocol, Version 2 (IGMPv2)</i></a>.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    45
 * It may optionally support source filtering as specified by <a
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    46
 * href="http://www.ietf.org/rfc/rfc3376.txt"> <i>RFC&nbsp;3376: Internet Group
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    47
 * Management Protocol, Version 3 (IGMPv3)</i></a>.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    48
 * For channels to an {@link StandardProtocolFamily#INET6 IPv6} socket, the equivalent
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    49
 * standards are <a href="http://www.ietf.org/rfc/rfc2710.txt"> <i>RFC&nbsp;2710:
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    50
 * Multicast Listener Discovery (MLD) for IPv6</i></a> and <a
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    51
 * href="http://www.ietf.org/rfc/rfc3810.txt"> <i>RFC&nbsp;3810: Multicast Listener
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    52
 * Discovery Version 2 (MLDv2) for IPv6</i></a>.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    53
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    54
 * <p> The {@link #join(InetAddress,NetworkInterface)} method is used to
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    55
 * join a group and receive all multicast datagrams sent to the group. A channel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    56
 * may join several multicast groups and may join the same group on several
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    57
 * {@link NetworkInterface interfaces}. Membership is dropped by invoking the {@link
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    58
 * MembershipKey#drop drop} method on the returned {@link MembershipKey}. If the
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    59
 * underlying platform supports source filtering then the {@link MembershipKey#block
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    60
 * block} and {@link MembershipKey#unblock unblock} methods can be used to block or
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    61
 * unblock multicast datagrams from particular source addresses.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    62
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    63
 * <p> The {@link #join(InetAddress,NetworkInterface,InetAddress)} method
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    64
 * is used to begin receiving datagrams sent to a group whose source address matches
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    65
 * a given source address. This method throws {@link UnsupportedOperationException}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    66
 * if the underlying platform does not support source filtering.  Membership is
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    67
 * <em>cumulative</em> and this method may be invoked again with the same group
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    68
 * and interface to allow receiving datagrams from other source addresses. The
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    69
 * method returns a {@link MembershipKey} that represents membership to receive
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    70
 * datagrams from the given source address. Invoking the key's {@link
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    71
 * MembershipKey#drop drop} method drops membership so that datagrams from the
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    72
 * source address can no longer be received.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    73
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    74
 * <h4>Platform dependencies</h4>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    75
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    76
 * The multicast implementation is intended to map directly to the native
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    77
 * multicasting facility. Consequently, the following items should be considered
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    78
 * when developing an application that receives IP multicast datagrams:
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    79
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    80
 * <ol>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    81
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    82
 * <li><p> The creation of the channel should specify the {@link ProtocolFamily}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    83
 * that corresponds to the address type of the multicast groups that the channel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    84
 * will join. There is no guarantee that a channel to a socket in one protocol
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    85
 * family can join and receive multicast datagrams when the address of the
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    86
 * multicast group corresponds to another protocol family. For example, it is
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    87
 * implementation specific if a channel to an {@link StandardProtocolFamily#INET6 IPv6}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    88
 * socket can join an {@link StandardProtocolFamily#INET IPv4} multicast group and receive
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    89
 * multicast datagrams sent to the group. </p></li>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    90
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    91
 * <li><p> The channel's socket should be bound to the {@link
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    92
 * InetAddress#isAnyLocalAddress wildcard} address. If the socket is bound to
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    93
 * a specific address, rather than the wildcard address then it is implementation
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    94
 * specific if multicast datagrams are received by the socket. </p></li>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    95
 *
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 5506
diff changeset
    96
 * <li><p> The {@link StandardSocketOptions#SO_REUSEADDR SO_REUSEADDR} option should be
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    97
 * enabled prior to {@link NetworkChannel#bind binding} the socket. This is
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    98
 * required to allow multiple members of the group to bind to the same
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    99
 * address. </p></li>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   100
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   101
 * </ol>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   102
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   103
 * <p> <b>Usage Example:</b>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   104
 * <pre>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   105
 *     // join multicast group on this interface, and also use this
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   106
 *     // interface for outgoing multicast datagrams
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   107
 *     NetworkInterface ni = NetworkInterface.getByName("hme0");
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   108
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   109
 *     DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET)
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 5506
diff changeset
   110
 *         .setOption(StandardSocketOptions.SO_REUSEADDR, true)
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   111
 *         .bind(new InetSocketAddress(5000))
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 5506
diff changeset
   112
 *         .setOption(StandardSocketOptions.IP_MULTICAST_IF, ni);
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   113
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   114
 *     InetAddress group = InetAddress.getByName("225.4.5.6");
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   115
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   116
 *     MembershipKey key = dc.join(group, ni);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   117
 * </pre>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   118
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   119
 * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   120
 */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   121
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   122
public interface MulticastChannel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   123
    extends NetworkChannel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   124
{
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   125
    /**
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   126
     * Closes this channel.
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   127
     *
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   128
     * <p> If the channel is a member of a multicast group then the membership
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   129
     * is {@link MembershipKey#drop dropped}. Upon return, the {@link
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   130
     * MembershipKey membership-key} will be {@link MembershipKey#isValid
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   131
     * invalid}.
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   132
     *
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   133
     * <p> This method otherwise behaves exactly as specified by the {@link
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   134
     * Channel} interface.
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   135
     *
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   136
     * @throws  IOException
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   137
     *          If an I/O error occurs
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   138
     */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   139
    @Override void close() throws IOException;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   140
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   141
    /**
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   142
     * Joins a multicast group to begin receiving all datagrams sent to the group,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   143
     * returning a membership key.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   144
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   145
     * <p> If this channel is currently a member of the group on the given
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   146
     * interface to receive all datagrams then the membership key, representing
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   147
     * that membership, is returned. Otherwise this channel joins the group and
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   148
     * the resulting new membership key is returned. The resulting membership key
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   149
     * is not {@link MembershipKey#sourceAddress source-specific}.
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   150
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   151
     * <p> A multicast channel may join several multicast groups, including
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   152
     * the same group on more than one interface. An implementation may impose a
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   153
     * limit on the number of groups that may be joined at the same time.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   154
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   155
     * @param   group
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   156
     *          The multicast address to join
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   157
     * @param   interf
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   158
     *          The network interface on which to join the group
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   159
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   160
     * @return  The membership key
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   161
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   162
     * @throws  IllegalArgumentException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   163
     *          If the group parameter is not a {@link InetAddress#isMulticastAddress
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   164
     *          multicast} address, or the group parameter is an address type
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   165
     *          that is not supported by this channel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   166
     * @throws  IllegalStateException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   167
     *          If the channel already has source-specific membership of the
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   168
     *          group on the interface
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   169
     * @throws  UnsupportedOperationException
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   170
     *          If the channel's socket is not an Internet Protocol socket
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   171
     * @throws  ClosedChannelException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   172
     *          If this channel is closed
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   173
     * @throws  IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   174
     *          If an I/O error occurs
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   175
     * @throws  SecurityException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   176
     *          If a security manager is set, and its
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   177
     *          {@link SecurityManager#checkMulticast(InetAddress) checkMulticast}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   178
     *          method denies access to the multiast group
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   179
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   180
    MembershipKey join(InetAddress group, NetworkInterface interf)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   181
        throws IOException;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   182
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   183
    /**
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   184
     * Joins a multicast group to begin receiving datagrams sent to the group
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   185
     * from a given source address.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   186
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   187
     * <p> If this channel is currently a member of the group on the given
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   188
     * interface to receive datagrams from the given source address then the
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   189
     * membership key, representing that membership, is returned. Otherwise this
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   190
     * channel joins the group and the resulting new membership key is returned.
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   191
     * The resulting membership key is {@link MembershipKey#sourceAddress
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   192
     * source-specific}.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   193
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   194
     * <p> Membership is <em>cumulative</em> and this method may be invoked
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   195
     * again with the same group and interface to allow receiving datagrams sent
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   196
     * by other source addresses to the group.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   197
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   198
     * @param   group
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   199
     *          The multicast address to join
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   200
     * @param   interf
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   201
     *          The network interface on which to join the group
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   202
     * @param   source
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   203
     *          The source address
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   204
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   205
     * @return  The membership key
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   206
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   207
     * @throws  IllegalArgumentException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   208
     *          If the group parameter is not a {@link
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   209
     *          InetAddress#isMulticastAddress multicast} address, the
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   210
     *          source parameter is not a unicast address, the group
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   211
     *          parameter is an address type that is not supported by this channel,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   212
     *          or the source parameter is not the same address type as the group
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   213
     * @throws  IllegalStateException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   214
     *          If the channel is currently a member of the group on the given
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   215
     *          interface to receive all datagrams
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   216
     * @throws  UnsupportedOperationException
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   217
     *          If the channel's socket is not an Internet Protocol socket or
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   218
     *          source filtering is not supported
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   219
     * @throws  ClosedChannelException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   220
     *          If this channel is closed
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   221
     * @throws  IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   222
     *          If an I/O error occurs
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   223
     * @throws  SecurityException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   224
     *          If a security manager is set, and its
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   225
     *          {@link SecurityManager#checkMulticast(InetAddress) checkMulticast}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   226
     *          method denies access to the multiast group
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   227
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   228
    MembershipKey join(InetAddress group, NetworkInterface interf, InetAddress source)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   229
        throws IOException;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   230
}