Skip to content

Optionally replace junixsocket with JEP-380 #1626

Closed

Description

@Sineaggi

Now that JEP-380 has shipped in java 16, we should be able to replace the current usage of junixsocket with SocketChannel and UnixDomainSocketAddress for users of java 16 and above.

Activity

  1. Sineaggi commented on May 11, 2021

    @Sineaggi
    ContributorAuthor

    This is most likely an oversimplification, but for simple queries like ping, info, listImage and listContainers this code seemed to work pretty well.

    public class JavaUnixSocket extends Socket {
    
        private final SocketChannel socketChannel;
    
        public UnixSocket(String path) throws IOException {
            this.socketChannel = SocketChannel.open(UnixDomainSocketAddress.of(path));
        }
    
        public static JavaUnixSocket get(String path) throws IOException {
            return new JavaUnixSocket(path);
        }
    
        @Override
        public InputStream getInputStream() throws IOException {
            if (isClosed())
                throw new SocketException("Socket is closed");
            if (!isConnected())
                throw new SocketException("Socket is not connected");
            if (isInputShutdown())
                throw new SocketException("Socket input is shutdown");
    
            return Channels.newInputStream(socketChannel);
        }
    
        @Override
        public OutputStream getOutputStream() throws IOException {
            if (isClosed())
                throw new SocketException("Socket is closed");
            if (!isConnected())
                throw new SocketException("Socket is not connected");
            if (isOutputShutdown())
                throw new SocketException("Socket output is shutdown");
    
            return Channels.newOutputStream(socketChannel);
        }
    
        @Override
        public void close() throws IOException {
            super.close();
            this.socketChannel.close();
        }
    }

    Alternatively, reflectively calling UnixDomainSocketAddress.of(path) might be enough, since the rest of the functions should be java 8 compatible.

  2. bsideup commented on May 11, 2021

    @bsideup
    Member

    Hi @Sineaggi,

    Thanks for checking, looks very promising! I am setting up Java 16 on my machine, but could you please check, perhaps there is some Java 8-compatible factory that calls UnixDomainSocketAddress.of(path), so that we can avoid figuring out the linking question? Thanks in advance!

  3. Sineaggi commented on May 11, 2021

    @Sineaggi
    ContributorAuthor

    A quick glance at the docs and Find Usages in Intellij unfortunately doesn't reveal any factory methods.

  4. stale commented on Aug 9, 2021

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  5. bsideup commented on Sep 13, 2021

    @bsideup
    Member

    Implemented in #1627

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions