Class SynchronizedSocketFactory

java.lang.Object
javax.net.SocketFactory
com.unboundid.util.SynchronizedSocketFactory

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 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 the SocketFactory instance wrapped by this synchronized socket factory.
      Returns:
      The SocketFactory instance wrapped by this synchronized socket factory.
    • createSocket

      @NotNull public Socket createSocket(@NotNull String host, int port) throws IOException
      Creates a new socket to the specified server.
      Specified by:
      createSocket in class SocketFactory
      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:
      createSocket in class SocketFactory
      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

      @NotNull public Socket createSocket(@NotNull InetAddress address, int port) throws IOException
      Creates a new socket to the specified server.
      Specified by:
      createSocket in class SocketFactory
      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:
      createSocket in class SocketFactory
      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.