A new JDK Enhancement Proposal (JEP) has been put forward by Michael McMahon to add Unix-domain socket support to two APIs in the java.nio.channels package; the socket channel and server-socket channel. JEP 380 also aims to extend the inherited channel mechanism to support Unix-domain socket channels and server socket channels.
JEP 380: Unix-Domain Socket Channels
McMahon writes, “For local, inter-process communication, Unix-domain sockets are both more secure and more efficient than TCP/IP loopback connections.” This is why he proposes to add support for Unix-domain socket channels, especially now they are supported in Windows 10 and Windows Server 2019.
The intention is that Unix-domain socket channels behave much the same way as TCP/IP channels, and the features that will be supported are those that are common across the major Unix platforms as well as Windows.
SEE ALSO: Java 15 update news
So how will Unix-domain socket channels be supported in the JDK? By adding these API elements:
- A new socket address type,
java.nio.channels.UnixDomainSocketAddress
- A
UNIX
constant value in the existingjava.net.StandardProtocolFamily
enum - Static
open
factory methods which take aProtocolFamily
in theSocketChannel
andServerSocketChannel
classes, which are useful beyond Unix-domain socket channels - New normative text in the
SocketChannel
andServerSocketChannel
classes that will distinguish Unix-domain socket channels from the existing TCP/IP types
SEE ALSO: JEP 378 – Text blocks leave preview in JDK 15
Will these changes have an effect on existing code? McMahon writes, “Existing code that uses the SocketChannel
and ServerSocketChannel
classes often assumes that instances of SocketAddress
returned by those APIs can be blindly cast to InetSocketAddress
. This cast will fail with Unix-domain socket channels.”
Additionally, the JEP states that it is not the aim to support features that are not common across the major Unix and Windows platforms. However, McMahon notes that the topic (and unsupported features) can be revisited again later if the need arises.
For more information, take a look at JEP 380 over at the OpenJDK website, or see if it’s been targeted to JDK 15 by reading our Java 15 news updates.
The post JEP 380: Unix-domain socket channels appeared first on JAXenter.
Source : JAXenter