- java.lang.Object
-
- java.nio.channels.MembershipKey
-
public abstract class MembershipKey extends Object
A token representing the membership of an Internet Protocol (IP) multicast group.A membership key may represent a membership to receive all datagrams sent to the group, or it may be source-specific, meaning that it represents a membership that receives only datagrams from a specific source address. Whether or not a membership key is source-specific may be determined by invoking its
sourceAddress
method.A membership key is valid upon creation and remains valid until the membership is dropped by invoking the
drop
method, or the channel is closed. The validity of the membership key may be tested by invoking itsisValid
method.Where a membership key is not source-specific and the underlying operation system supports source filtering, then the
block
andunblock
methods can be used to block or unblock multicast datagrams from particular source addresses.- Since:
- 1.7
- See Also:
MulticastChannel
-
-
Constructor Summary
Constructors Modifier Constructor and Description protected
MembershipKey()
Initializes a new instance of this class.
-
Method Summary
Methods Modifier and Type Method and Description abstract MembershipKey
block(InetAddress source)
Block multicast datagrams from the given source address.abstract MulticastChannel
channel()
Returns the channel for which this membership key was created.abstract void
drop()
Drop membership.abstract InetAddress
group()
Returns the multicast group for which this membership key was created.abstract boolean
isValid()
Tells whether or not this membership is valid.abstract NetworkInterface
networkInterface()
Returns the network interface for which this membership key was created.abstract InetAddress
sourceAddress()
Returns the source address if this membership key is source-specific, ornull
if this membership is not source-specific.abstract MembershipKey
unblock(InetAddress source)
Unblock multicast datagrams from the given source address that was previously blocked using theblock
method.
-
-
-
Constructor Detail
-
MembershipKey
protected MembershipKey()
Initializes a new instance of this class.
-
-
Method Detail
-
isValid
public abstract boolean isValid()
Tells whether or not this membership is valid.A multicast group membership is valid upon creation and remains valid until the membership is dropped by invoking the
drop
method, or the channel is closed.- Returns:
true
if this membership key is valid,false
otherwise
-
drop
public abstract void drop()
Drop membership.If the membership key represents a membership to receive all datagrams then the membership is dropped and the channel will no longer receive any datagrams sent to the group. If the membership key is source-specific then the channel will no longer receive datagrams sent to the group from that source address.
After membership is dropped it may still be possible to receive datagrams sent to the group. This can arise when datagrams are waiting to be received in the socket's receive buffer. After membership is dropped then the channel may
join
the group again in which case a new membership key is returned.Upon return, this membership object will be
invalid
. If the multicast group membership is already invalid then invoking this method has no effect. Once a multicast group membership is invalid, it remains invalid forever.
-
block
public abstract MembershipKey block(InetAddress source) throws IOException
Block multicast datagrams from the given source address.If this membership key is not source-specific, and the underlying operating system supports source filtering, then this method blocks multicast datagrams from the given source address. If the given source address is already blocked then this method has no effect. After a source address is blocked it may still be possible to receive datagams from that source. This can arise when datagrams are waiting to be received in the socket's receive buffer.
- Parameters:
source
- The source address to block- Returns:
- This membership key
- Throws:
IllegalArgumentException
- If thesource
parameter is not a unicast address or is not the same address type as the multicast groupIllegalStateException
- If this membership key is source-specific or is no longer validUnsupportedOperationException
- If the underlying operating system does not support source filteringIOException
- If an I/O error occurs
-
unblock
public abstract MembershipKey unblock(InetAddress source)
Unblock multicast datagrams from the given source address that was previously blocked using theblock
method.- Parameters:
source
- The source address to unblock- Returns:
- This membership key
- Throws:
IllegalStateException
- If the given source address is not currently blocked or the membership key is no longer valid
-
channel
public abstract MulticastChannel channel()
Returns the channel for which this membership key was created. This method will continue to return the channel even after the membership becomesinvalid
.- Returns:
- the channel
-
group
public abstract InetAddress group()
Returns the multicast group for which this membership key was created. This method will continue to return the group even after the membership becomesinvalid
.- Returns:
- the multicast group
-
networkInterface
public abstract NetworkInterface networkInterface()
Returns the network interface for which this membership key was created. This method will continue to return the network interface even after the membership becomesinvalid
.- Returns:
- the network interface
-
sourceAddress
public abstract InetAddress sourceAddress()
Returns the source address if this membership key is source-specific, ornull
if this membership is not source-specific.- Returns:
- The source address if this membership key is source-specific,
otherwise
null
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/nio/channels/membershipkey.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.