Package com.unboundid.util
Class SynchronizedSocketFactory
java.lang.Object
javax.net.SocketFactory
com.unboundid.util.SynchronizedSocketFactory
@NotMutable
@ThreadSafety(level=COMPLETELY_THREADSAFE)
public final class SynchronizedSocketFactory
extends SocketFactory
This class provides an implementation of a Java socket factory that will
wrap a provided socket factory but will synchronize on each use of that
factory to ensure that only a single thread may use that factory to create
a socket at any given time.
-
Constructor Summary
ConstructorsConstructorDescriptionSynchronizedSocketFactory(SocketFactory factory) Creates a new synchronous socket factory instance that will wrap the provided socket factory. -
Method Summary
Modifier and TypeMethodDescriptioncreateSocket(String host, int port) Creates a new socket to the specified server.createSocket(String host, int port, InetAddress localAddress, int localPort) Creates a new socket to the specified server.createSocket(InetAddress address, int port) Creates a new socket to the specified server.createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) Creates a new socket to the specified server.Retrieves theSocketFactoryinstance wrapped by this synchronized socket factory.Methods inherited from class javax.net.SocketFactory
createSocket, getDefault
-
Constructor Details
-
SynchronizedSocketFactory
Creates a new synchronous socket factory instance that will wrap the provided socket factory.- Parameters:
factory- The socket factory to be wrapped.
-
-
Method Details
-
getWrappedSocketFactory
Retrieves theSocketFactoryinstance wrapped by this synchronized socket factory.- Returns:
- The
SocketFactoryinstance wrapped by this synchronized socket factory.
-
createSocket
Creates a new socket to the specified server.- Specified by:
createSocketin classSocketFactory- Parameters:
host- The host to which the connection should be established.port- The port to which the connection should be established.- Returns:
- The socket that was created.
- Throws:
IOException- If a problem occurs while creating the socket.
-
createSocket
@NotNull public Socket createSocket(@NotNull String host, int port, @NotNull InetAddress localAddress, int localPort) throws IOException Creates a new socket to the specified server.- Specified by:
createSocketin classSocketFactory- Parameters:
host- The host to which the connection should be established.port- The port to which the connection should be established.localAddress- The local address to use for the connection.localPort- The local port to use for the connection.- Returns:
- The socket that was created.
- Throws:
IOException- If a problem occurs while creating the socket.
-
createSocket
Creates a new socket to the specified server.- Specified by:
createSocketin classSocketFactory- Parameters:
address- The address to which the connection should be established.port- The port to which the connection should be established.- Returns:
- The socket that was created.
- Throws:
IOException- If a problem occurs while creating the socket.
-
createSocket
@NotNull public Socket createSocket(@NotNull InetAddress address, int port, @NotNull InetAddress localAddress, int localPort) throws IOException Creates a new socket to the specified server.- Specified by:
createSocketin classSocketFactory- Parameters:
address- The address to which the connection should be established.port- The port to which the connection should be established.localAddress- The local address to use for the connection.localPort- The local port to use for the connection.- Returns:
- The socket that was created.
- Throws:
IOException- If a problem occurs while creating the socket.
-