java.nio.channels.MembershipKey API

David M. Lloyd david.lloyd at redhat.com
Thu Nov 27 10:42:19 PST 2008


On 11/27/2008 03:06 AM, Alan Bateman wrote:
> David M. Lloyd wrote:
>> Ressurrecting this old thread - I have one additional comment about 
>> the MembershipKey interface.  Rather than have drop()/isValid(), why 
>> not extend Channel (or at least Closeable) and have close()/isOpen() 
>> instead?  This way any code which has a common resource cleanup 
>> mechanism based on Closeable will be able to clean up MembershipKeys 
>> in the same way.
>>
>> - DML
> For resource cleanup, I would expect the multicast channel to be 
> registered for close rather than the membership keys. When the multicast 
> channel is closed then it drops membership of all groups and invalidates 
> all keys. Looking at the javadoc again, I see that this isn't as clear 
> as it should. There is wording in MembershipKey to require the key to be 
> invalidated when the channel is closed but we don't have wording in 
> MulticsatChannel to make it clear that membership is dropped when the 
> channel is closed - I will fix that (thanks!). With that fixed, I am 
> happy with "drop" (same thing in FileLock with the "release" method).

Well, that wasn't my point.  I don't think anyone would reasonably expect a 
multicast membership key to outlive the channel.  My point is that, given 
that there's a standard resource cleanup I/O interface (Closeable), and 
that drop() conforms to it exactly apart from the name, why not use it?

- DML



More information about the nio-dev mailing list