Class ConnectionBuilder<T extends Client<Connection<T>>>


  • public class ConnectionBuilder<T extends Client<Connection<T>>>
    extends java.lang.Object
    Builds the ConnectionHandler responsible to manage all incoming connections.
    • Constructor Detail

      • ConnectionBuilder

        public ConnectionBuilder()
    • Method Detail

      • create

        public static <T extends Client<Connection<T>>> ConnectionBuilder<T> create​(java.net.InetSocketAddress address,
                                                                                    ClientFactory<T> clientFactory,
                                                                                    PacketHandler<T> packetHandler,
                                                                                    PacketExecutor<T> executor)
        Creates a ConnectionBuilder holding the minimum requirements to create a ConnectionHandler.
        Type Parameters:
        T - - The Type of client that ConnectionBuilder will handle.
        Parameters:
        address - - The socket address to listen the incoming connections.
        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.
      • filter

        public ConnectionBuilder<T> filter​(ConnectionFilter filter)
        Sets a filter to be used on incoming connections. The filter must decide if a connection is acceptable or not.
        Parameters:
        filter - - the ConnectionFilter to be set.
        Returns:
        this.
      • threadPoolSize

        public ConnectionBuilder<T> threadPoolSize​(int size)
        Set the size of the threadPool used to manage the connections and data sending. If the size is less than or equal to zero or greater than Short.MAX_VALUE then a cachedThreadPool is used. Otherwise a FixedThreadPool with the size set is used.
        Parameters:
        size - - the size to be Set
        Returns:
        this
      • useNagle

        public ConnectionBuilder<T> useNagle​(boolean useNagle)
        Defines if small outgoing packets must be combined to be sent all at once. This improves the network performance, but can cause lags on clients waiting for the packet.
        Parameters:
        useNagle - - true if the Nagle's algorithm must be used.
        Returns:
        this.
      • shutdownWaitTime

        public ConnectionBuilder<T> shutdownWaitTime​(long waitTime)
        Sets the shutdown wait time.
        Parameters:
        waitTime - - the wait time to close all connections resources after a ConnectionHandler.shutdown() is called.
        Returns:
        this
      • bufferDefaultSize

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

        public ConnectionBuilder<T> bufferMinSize​(int bufferSize)
        Sets the min size of the data sent/received.
        Parameters:
        bufferSize - - the buffer size to be set
        Returns:
        this.
      • bufferLargeSize

        public ConnectionBuilder<T> bufferLargeSize​(int bufferSize)
        Sets the large size of the data sent/received.
        Parameters:
        bufferSize - - the buffer size to be set
        Returns:
        this.
      • bufferMediumSize

        public ConnectionBuilder<T> bufferMediumSize​(int bufferSize)
        Sets the medium size of the data sent/received.
        Parameters:
        bufferSize - - the buffer size to be set
        Returns:
        this.
      • bufferPoolSize

        public ConnectionBuilder<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.
        Parameters:
        bufferPoolSize - - the size of the buffer pool size.
        Returns:
        this
      • bufferMinPoolSize

        public ConnectionBuilder<T> bufferMinPoolSize​(int bufferPoolSize)
        Sets the maximum amount of buffer with min 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.
        Parameters:
        bufferPoolSize - - the size of the buffer pool size.
        Returns:
        this
      • bufferMediumPoolSize

        public ConnectionBuilder<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.
        Parameters:
        bufferPoolSize - - the size of the buffer pool size.
        Returns:
        this
      • bufferLargePoolSize

        public ConnectionBuilder<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.
        Parameters:
        bufferPoolSize - - the size of the buffer pool size.
        Returns:
        this
      • byteOrder

        public ConnectionBuilder<T> byteOrder​(java.nio.ByteOrder order)
        Sets the byte order used to send and receive packets.
        Parameters:
        order - - the order to be used.
        Returns:
        this.
      • build

        public ConnectionHandler<T> build()
                                   throws java.io.IOException
        Builds a new ConnectionHandler based on the options configured.
        Returns:
        a ConnectionHandler
        Throws:
        java.io.IOException - - If the Socket Address configured can't be used.