On 16/01/2020 11:45, Chris Hegarty wrote:
:
Generally, I agree with updating the socket adapter to support
multicast. It will certainly help with future work in this area.

The instanceof checks in the constructors highlight that there is an
abstraction missing here - to support creating a custom MulticastSocket
implementation. If / When DatagramSocketImpl is deprecated, the advise
will likely be to subclass MulticastSocket if one wants to provide a
custom implementation. I believe that this cannot be done efficiently
with the current API - and that is the issue that this change is running
into that results in the instanceof checks in the constructors.
The main API issues date back to choices made in JDK 1.0 but it's not clear to me that it's worth trying to fix them now. The extensibility could have been looked in JDK 1.4 when the protected constructor was added but even then, it's not clear that there was any interest in completely different implementations outside of the JDK. So if someone really wants to this now then they could create a DatagramSocketImpl and use the factory method to set it system-wide. I don't think we've ever seen anyone do that, maybe because that mechanism is very under specified, maybe because it would require accessing the internal representation of FileDescriptor and DatagramPacket. If that mechanism is deprecated and eventually removed (which is probably the right thing to do) then the only choice would be to extend and override all methods. Yes, I agree the check for the sub-class is ugly. The legacy implementation also has to check if it's a MulticastSocket so that the right impl is chosen.

-Alan

Reply via email to