# MembershipKey

public abstract class **MembershipKey** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#sourceAddress()` method.

A membership key is valid upon creation and remains valid until the
membership is dropped by invoking the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#drop()` method, or
the channel is closed. The validity of the membership key may be tested
by invoking its `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#isValid()` method.

Where a membership key is not source-specific and the underlying operation
system supports source filtering, then the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#block(java.net.InetAddress)` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#unblock(java.net.InetAddress)` methods can be used to block or unblock multicast datagrams
from particular source addresses.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MulticastChannel.html`

### Protected Constructor Summary

|---|---|
|   | [MembershipKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#MembershipKey())() Initializes a new instance of this class. |

### Public Method Summary

|---|---|
| abstract [MembershipKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html) | [block](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#block(java.net.InetAddress))([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) source) Block multicast datagrams from the given source address. |
| abstract [MulticastChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MulticastChannel.html) | [channel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#channel())() Returns the channel for which this membership key was created. |
| abstract void | [drop](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#drop())() Drop membership. |
| abstract [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) | [group](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#group())() Returns the multicast group for which this membership key was created. |
| abstract boolean | [isValid](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#isValid())() Tells whether or not this membership is valid. |
| abstract [NetworkInterface](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetworkInterface.html) | [networkInterface](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#networkInterface())() Returns the network interface for which this membership key was created. |
| abstract [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) | [sourceAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#sourceAddress())() Returns the source address if this membership key is source-specific, or `null` if this membership is not source-specific. |
| abstract [MembershipKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html) | [unblock](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#unblock(java.net.InetAddress))([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) source) Unblock multicast datagrams from the given source address that was previously blocked using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#block(java.net.InetAddress)` method. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Protected Constructors

#### protected
**MembershipKey**
()

Initializes a new instance of this class.

## Public Methods

#### public abstract [MembershipKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html)
**block**
([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) source)

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
datagrams 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](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | If the `source` parameter is not a unicast address or is not the same address type as the multicast group |
| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | If this membership key is source-specific or is no longer valid |
| [UnsupportedOperationException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/UnsupportedOperationException.html) | If the underlying operating system does not support source filtering |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

#### public abstract [MulticastChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MulticastChannel.html)
**channel**
()

Returns the channel for which this membership key was created. This
method will continue to return the channel even after the membership
becomes `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#isValid()`.

##### Returns

- the channel

#### 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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MulticastChannel.html#join(java.net.InetAddress,%20java.net.NetworkInterface)` the group again
in which case a new membership key is returned.

Upon return, this membership object will be `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#isValid()`.
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.

#### public abstract [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html)
**group**
()

Returns the multicast group for which this membership key was created.
This method will continue to return the group even after the membership
becomes `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#isValid()`.

##### Returns

- the multicast group

#### 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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#drop()`
method, or the channel is closed.

##### Returns

- `true` if this membership key is valid, `false` otherwise

#### public abstract [NetworkInterface](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetworkInterface.html)
**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 becomes `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#isValid()`.

##### Returns

- the network interface

#### public abstract [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html)
**sourceAddress**
()

Returns the source address if this membership key is source-specific,
or `null` if this membership is not source-specific.

##### Returns

- The source address if this membership key is source-specific, otherwise `null`

#### public abstract [MembershipKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html)
**unblock**
([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) source)

Unblock multicast datagrams from the given source address that was
previously blocked using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/MembershipKey.html#block(java.net.InetAddress)` method.

##### Parameters

| source | The source address to unblock |
|---|---|

##### Returns

- This membership key

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | If the given source address is not currently blocked or the membership key is no longer valid |
|---|---|