-
Enhancement
-
Resolution: Fixed
-
P3
-
15
-
b09
Evaluate how to write a custom DatagramSocket/MulticastSocket without using DatagramSocketImplFactory.
This issue has been file as a result of a discussion raised during a code view for 8236925, see https://mail.openjdk.java.net/pipermail/net-dev/2020-January/013514.html
Though DatagramSocket has a protected constructor that allows to pass a DatagramSocketImpl instance, MulticastSocket doesn't.
There are two ways to provide a complete custom implementation of DatagramSocket:
- Subclass DatagramSocket and pass a custom DatagramSocketImpl instance that reimplement the whole functionality
- Subclass DatagramSocket and pass a non functional DatagramSocketImpl instance, and override all methods in DatagramSocket so that DatagramSocketImpl is never called.
In both cases, the default DatagramSocket implementation will not be created - and there will be no file descriptor leak.
This is unfortunately not possible with MulticastSocket: if you subclass MulticlassSocket, the default implementation will *always* be created, even if it's never used. The only solution to avoid that is currently to replace the default DatagramSocketImplFactory by calling the static DatagramSocket.setDatagramSocketImplFactory. We need a better solution.
The solution proposed in this RFE is to allow DatagramSocket to both send and receive multicast datagrams. An application that need to completely replace the default multicast implementation, and that cannot be easily updated to use DatagramChannel, can do so by subclassing DatagramSocket instead.
This issue has been file as a result of a discussion raised during a code view for 8236925, see https://mail.openjdk.java.net/pipermail/net-dev/2020-January/013514.html
Though DatagramSocket has a protected constructor that allows to pass a DatagramSocketImpl instance, MulticastSocket doesn't.
There are two ways to provide a complete custom implementation of DatagramSocket:
- Subclass DatagramSocket and pass a custom DatagramSocketImpl instance that reimplement the whole functionality
- Subclass DatagramSocket and pass a non functional DatagramSocketImpl instance, and override all methods in DatagramSocket so that DatagramSocketImpl is never called.
In both cases, the default DatagramSocket implementation will not be created - and there will be no file descriptor leak.
This is unfortunately not possible with MulticastSocket: if you subclass MulticlassSocket, the default implementation will *always* be created, even if it's never used. The only solution to avoid that is currently to replace the default DatagramSocketImplFactory by calling the static DatagramSocket.setDatagramSocketImplFactory. We need a better solution.
The solution proposed in this RFE is to allow DatagramSocket to both send and receive multicast datagrams. An application that need to completely replace the default multicast implementation, and that cannot be easily updated to use DatagramChannel, can do so by subclassing DatagramSocket instead.
- blocks
-
JDK-8235139 Deprecate the socket impl factory mechanism
-
- Resolved
-
- csr for
-
JDK-8260667 Update DatagramSocket to add support for joining multicast groups
-
- Closed
-
- relates to
-
JDK-8263080 Obsolete relationship in MulticastSocket API documentation.
-
- Resolved
-
-
JDK-8301463 Code in DatagramSocket still refers to resolved JDK-8237352
-
- Resolved
-
(1 links to)
There are no Sub-Tasks for this issue.