Class DomainSocket

java.lang.Object
org.apache.hadoop.net.unix.DomainSocket
All Implemented Interfaces:
Closeable, AutoCloseable

@LimitedPrivate("HDFS") public class DomainSocket extends Object implements Closeable
The implementation of UNIX domain sockets in Java. See DomainSocket for more information about UNIX domain sockets.
  • Field Details

  • Method Details

    • getLoadingFailureReason

      public static String getLoadingFailureReason()
      Return true only if UNIX domain sockets are available.
      Returns:
      loadingFailureReason.
    • disableBindPathValidation

      @VisibleForTesting public static void disableBindPathValidation()
      Disable validation of the server bind paths.
    • getEffectivePath

      public static String getEffectivePath(String path, int port)
      Given a path and a port, compute the effective path by replacing occurrences of _PORT with the port. This is mainly to make it possible to run multiple DataNodes locally for testing purposes.
      Parameters:
      path - The source path
      port - Port number to use
      Returns:
      The effective path
    • bindAndListen

      public static DomainSocket bindAndListen(String path) throws IOException
      Create a new DomainSocket listening on the given path.
      Parameters:
      path - The path to bind and listen on.
      Returns:
      The new DomainSocket.
      Throws:
      IOException - raised on errors performing I/O.
    • socketpair

      public static DomainSocket[] socketpair() throws IOException
      Create a pair of UNIX domain sockets which are connected to each other by calling socketpair(2).
      Returns:
      An array of two UNIX domain sockets connected to each other.
      Throws:
      IOException - on error.
    • accept

      public DomainSocket accept() throws IOException
      Accept a new UNIX domain connection. This method can only be used on sockets that were bound with bind().
      Returns:
      The new connection.
      Throws:
      IOException - If there was an I/O error performing the accept-- such as the socket being closed from under us. Particularly when the accept is timed out, it throws SocketTimeoutException.
    • connect

      public static DomainSocket connect(String path) throws IOException
      Create a new DomainSocket connected to the given path.
      Parameters:
      path - The path to connect to.
      Returns:
      The new DomainSocket.
      Throws:
      IOException - If there was an I/O error performing the connect.
    • isOpen

      public boolean isOpen()
      Return true if the file descriptor is currently open.
      Returns:
      True if the file descriptor is currently open.
    • getPath

      public String getPath()
      Returns:
      The socket path.
    • getInputStream

      public DomainSocket.DomainInputStream getInputStream()
      Returns:
      The socket InputStream
    • getOutputStream

      public DomainSocket.DomainOutputStream getOutputStream()
      Returns:
      The socket OutputStream
    • getChannel

      public DomainSocket.DomainChannel getChannel()
      Returns:
      The socket Channel
    • setAttribute

      public void setAttribute(int type, int size) throws IOException
      Throws:
      IOException
    • getAttribute

      public int getAttribute(int type) throws IOException
      Throws:
      IOException
    • close

      public void close(boolean force) throws IOException
      Close the Server Socket without check refCount. When Server Socket is blocked on accept(), its refCount is 1. close() call on Server Socket will be stuck in the while loop count check.
      Parameters:
      force - if true, will not check refCount before close socket.
      Throws:
      IOException - raised on errors performing I/O.
    • close

      public void close() throws IOException
      Close the Socket.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • shutdown

      public void shutdown() throws IOException
      Call shutdown(SHUT_RDWR) on the UNIX domain socket.
      Throws:
      IOException - raised on errors performing I/O.
    • sendFileDescriptors

      public void sendFileDescriptors(FileDescriptor[] descriptors, byte[] jbuf, int offset, int length) throws IOException
      Send some FileDescriptor objects to the process on the other side of this socket.
      Parameters:
      descriptors - The file descriptors to send.
      jbuf - Some bytes to send. You must send at least one byte.
      offset - The offset in the jbuf array to start at.
      length - Length of the jbuf array to use.
      Throws:
      IOException - raised on errors performing I/O.
    • recvFileInputStreams

      public int recvFileInputStreams(FileInputStream[] streams, byte[] buf, int offset, int length) throws IOException
      Receive some FileDescriptor objects from the process on the other side of this socket, and wrap them in FileInputStream objects.
      Parameters:
      streams - input stream.
      buf - input buf.
      offset - input offset.
      length - input length.
      Returns:
      wrap them in FileInputStream objects.
      Throws:
      IOException - raised on errors performing I/O.
    • toString

      public String toString()
      Overrides:
      toString in class Object