Package org.apache.hadoop.net.unix
Class DomainSocket
java.lang.Object
org.apache.hadoop.net.unix.DomainSocket
- All Implemented Interfaces:
Closeable,AutoCloseable
The implementation of UNIX domain sockets in Java.
See
DomainSocket for more information about UNIX domain sockets.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassclassInput stream for UNIX domain sockets.classOutput stream for UNIX domain sockets. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionaccept()Accept a new UNIX domain connection.static DomainSocketbindAndListen(String path) Create a new DomainSocket listening on the given path.voidclose()Close the Socket.voidclose(boolean force) Close the Server Socket without check refCount.static DomainSocketCreate a new DomainSocket connected to the given path.static voidDisable validation of the server bind paths.intgetAttribute(int type) static StringgetEffectivePath(String path, int port) Given a path and a port, compute the effective path by replacing occurrences of _PORT with the port.static StringReturn true only if UNIX domain sockets are available.getPath()booleanisOpen()Return true if the file descriptor is currently open.intrecvFileInputStreams(FileInputStream[] streams, byte[] buf, int offset, int length) Receive some FileDescriptor objects from the process on the other side of this socket, and wrap them in FileInputStream objects.voidsendFileDescriptors(FileDescriptor[] descriptors, byte[] jbuf, int offset, int length) Send some FileDescriptor objects to the process on the other side of this socket.voidsetAttribute(int type, int size) voidshutdown()Call shutdown(SHUT_RDWR) on the UNIX domain socket.static DomainSocket[]Create a pair of UNIX domain sockets which are connected to each other by calling socketpair(2).toString()
-
Field Details
-
SEND_BUFFER_SIZE
public static final int SEND_BUFFER_SIZE- See Also:
-
RECEIVE_BUFFER_SIZE
public static final int RECEIVE_BUFFER_SIZE- See Also:
-
SEND_TIMEOUT
public static final int SEND_TIMEOUT- See Also:
-
RECEIVE_TIMEOUT
public static final int RECEIVE_TIMEOUT- See Also:
-
-
Method Details
-
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
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 pathport- Port number to use- Returns:
- The effective path
-
bindAndListen
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
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
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
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
- Returns:
- The socket path.
-
getInputStream
- Returns:
- The socket InputStream
-
getOutputStream
- Returns:
- The socket OutputStream
-
getChannel
- Returns:
- The socket Channel
-
setAttribute
- Throws:
IOException
-
getAttribute
- Throws:
IOException
-
close
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
Close the Socket.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
shutdown
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
-