Class Connector<T extends Client<Connection<T>>>


  • public class Connector<T extends Client<Connection<T>>>
    extends java.lang.Object
    • Constructor Detail

      • Connector

        public Connector()
    • Method Detail

      • create

        public static <T extends Client<Connection<T>>> Connector<T> create​(ClientFactory<T> clientFactory,
                                                                            PacketHandler<T> packetHandler,
                                                                            PacketExecutor<T> executor)
        Creates a Connector holding the minimum requirements to create a Client.
        Type Parameters:
        T - - The Type of client that ConnectionBuilder will handle.
        Parameters:
        clientFactory - - The factory responsible to create a new Client when a new connection is accepted.
        packetHandler - - The handle responsible to convert the data received into a ReadablePacket
        executor - - The responsible to execute the incoming packets.
        Returns:
        A ConnectionBuilder with default configuration.
      • bufferDefaultSize

        public Connector<T> bufferDefaultSize​(int bufferSize)
        Sets the size limit of the data buffer sent/received. The size must be as bigger as the biggest packet received. The default value is 8KB.
        Parameters:
        bufferSize - - the buffer size to be set
        Returns:
        this.
      • bufferSmallSize

        public Connector<T> bufferSmallSize​(int bufferSize)
        Sets the small size of the data buffer sent/received. The default value is 1KB.
        Parameters:
        bufferSize - - the buffer size to be set
        Returns:
        this.
      • bufferMediumSize

        public Connector<T> bufferMediumSize​(int bufferSize)
        Sets the medium size of the data buffer sent/received. The default value is 2KB.
        Parameters:
        bufferSize - - the buffer size to be set
        Returns:
        this.
      • bufferLargeSize

        public Connector<T> bufferLargeSize​(int bufferSize)
        Sets the large size of the data buffer sent/received. The default value is 4KB.
        Parameters:
        bufferSize - - the buffer size to be set
        Returns:
        this.
      • bufferPoolSize

        public Connector<T> bufferPoolSize​(int bufferPoolSize)
        Sets the maximum amount of buffer with default size that can be holder on the BufferPool. A small value can be lead to buffer overhead creation. Otherwise a too big size can be lead to unwanted memory usage. The size must be restricted related to the number of expected clients and taking considerations of system resources. The default value is 100.
        Parameters:
        bufferPoolSize - - the size of the buffer pool size.
        Returns:
        this
      • bufferSmallPoolSize

        public Connector<T> bufferSmallPoolSize​(int bufferPoolSize)
        Sets the maximum amount of buffer with small size that can be holder on the BufferPool. A small value can be lead to buffer overhead creation. Otherwise a too big size can be lead to unwanted memory usage. The size must be restricted related to the number of expected clients and taking considerations of system resources. The default value is 100.
        Parameters:
        bufferPoolSize - - the size of the buffer pool size.
        Returns:
        this
      • bufferMediumPoolSize

        public Connector<T> bufferMediumPoolSize​(int bufferPoolSize)
        Sets the maximum amount of buffer with medium size that can be holder on the BufferPool. A small value can be lead to buffer overhead creation. Otherwise a too big size can be lead to unwanted memory usage. The size must be restricted related to the number of expected clients and taking considerations of system resources. The default value is 50.
        Parameters:
        bufferPoolSize - - the size of the buffer pool size.
        Returns:
        this
      • bufferLargePoolSize

        public Connector<T> bufferLargePoolSize​(int bufferPoolSize)
        Sets the maximum amount of buffer with large size that can be holder on the BufferPool. A small value can be lead to buffer overhead creation. Otherwise a too big size can be lead to unwanted memory usage. The size must be restricted related to the number of expected clients and taking considerations of system resources. The default value is 25.
        Parameters:
        bufferPoolSize - - the size of the buffer pool size.
        Returns:
        this
      • connect

        public T connect​(java.lang.String host,
                         int port)
                  throws java.io.IOException,
                         java.util.concurrent.ExecutionException,
                         java.lang.InterruptedException
        Connects to a host using the address and port.
        Parameters:
        host - the address to be connected to
        port - the port of the host
        Returns:
        A client connected to the host and port
        Throws:
        java.io.IOException - if a IO error happens during the connection.
        java.util.concurrent.ExecutionException - if the computation threw an exception
        java.lang.InterruptedException - if the current thread was interrupted while waiting
      • connect

        public T connect​(java.net.InetSocketAddress socketAddress)
                  throws java.io.IOException,
                         java.util.concurrent.ExecutionException,
                         java.lang.InterruptedException
        Connects to a host with socketAddress
        Parameters:
        socketAddress - the address which will be connected
        Returns:
        a client that represents the connection with the socketAddress
        Throws:
        java.io.IOException - if a IO error happens during the connection.
        java.util.concurrent.ExecutionException - if the computation threw an exception
        java.lang.InterruptedException - if the current thread was interrupted while waiting