Class SynchronizedSocketFactory


  • @NotMutable
    @ThreadSafety(level=COMPLETELY_THREADSAFE)
    public final class SynchronizedSocketFactory
    extends javax.net.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

      Constructors 
      Constructor Description
      SynchronizedSocketFactory​(javax.net.SocketFactory factory)
      Creates a new synchronous socket factory instance that will wrap the provided socket factory.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.net.Socket createSocket​(java.lang.String host, int port)
      Creates a new socket to the specified server.
      java.net.Socket createSocket​(java.lang.String host, int port, java.net.InetAddress localAddress, int localPort)
      Creates a new socket to the specified server.
      java.net.Socket createSocket​(java.net.InetAddress address, int port)
      Creates a new socket to the specified server.
      java.net.Socket createSocket​(java.net.InetAddress address, int port, java.net.InetAddress localAddress, int localPort)
      Creates a new socket to the specified server.
      javax.net.SocketFactory getWrappedSocketFactory()
      Retrieves the SocketFactory instance wrapped by this synchronized socket factory.
      • Methods inherited from class javax.net.SocketFactory

        createSocket, getDefault
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SynchronizedSocketFactory

        public SynchronizedSocketFactory​(@NotNull
                                         javax.net.SocketFactory factory)
        Creates a new synchronous socket factory instance that will wrap the provided socket factory.
        Parameters:
        factory - The socket factory to be wrapped.
    • Method Detail

      • getWrappedSocketFactory

        @NotNull
        public javax.net.SocketFactory getWrappedSocketFactory()
        Retrieves the SocketFactory instance wrapped by this synchronized socket factory.
        Returns:
        The SocketFactory instance wrapped by this synchronized socket factory.
      • createSocket

        @NotNull
        public java.net.Socket createSocket​(@NotNull
                                            java.lang.String host,
                                            int port)
                                     throws java.io.IOException
        Creates a new socket to the specified server.
        Specified by:
        createSocket in class javax.net.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:
        java.io.IOException - If a problem occurs while creating the socket.
      • createSocket

        @NotNull
        public java.net.Socket createSocket​(@NotNull
                                            java.lang.String host,
                                            int port,
                                            @NotNull
                                            java.net.InetAddress localAddress,
                                            int localPort)
                                     throws java.io.IOException
        Creates a new socket to the specified server.
        Specified by:
        createSocket in class javax.net.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:
        java.io.IOException - If a problem occurs while creating the socket.
      • createSocket

        @NotNull
        public java.net.Socket createSocket​(@NotNull
                                            java.net.InetAddress address,
                                            int port)
                                     throws java.io.IOException
        Creates a new socket to the specified server.
        Specified by:
        createSocket in class javax.net.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:
        java.io.IOException - If a problem occurs while creating the socket.
      • createSocket

        @NotNull
        public java.net.Socket createSocket​(@NotNull
                                            java.net.InetAddress address,
                                            int port,
                                            @NotNull
                                            java.net.InetAddress localAddress,
                                            int localPort)
                                     throws java.io.IOException
        Creates a new socket to the specified server.
        Specified by:
        createSocket in class javax.net.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:
        java.io.IOException - If a problem occurs while creating the socket.