Class NetServerBuilder

java.lang.Object
org.omegazero.net.common.NetworkApplicationBuilder
org.omegazero.net.server.NetServerBuilder
Direct Known Subclasses:
NioServerBuilder

public abstract class NetServerBuilder extends NetworkApplicationBuilder
A NetworkApplicationBuilder for creating NetServers.
Since:
2.1.0
  • Field Details

    • bindAddresses

      protected Collection<InetAddress> bindAddresses
    • ports

      protected Collection<Integer> ports
    • listenPath

      protected String listenPath
    • connectionBacklog

      protected int connectionBacklog
    • connectionIdleTimeout

      protected int connectionIdleTimeout
    • applicationLayerProtocols

      protected String[] applicationLayerProtocols
  • Constructor Details

    • NetServerBuilder

      public NetServerBuilder()
  • Method Details

    • build

      public abstract NetServer build()
      Description copied from class: NetworkApplicationBuilder
      Creates the NetworkApplication from the previously set parameters.
      Specified by:
      build in class NetworkApplicationBuilder
      Returns:
      The NetworkApplication
    • transportType

      public NetServerBuilder transportType(NetworkApplicationBuilder.TransportType transportType)
      Description copied from class: NetworkApplicationBuilder
      Overrides:
      transportType in class NetworkApplicationBuilder
      Parameters:
      transportType - The TransportType
      Returns:
      This builder
    • encrypted

      public NetServerBuilder encrypted(boolean encrypted)
      Description copied from class: NetworkApplicationBuilder
      Sets whether to use encryption. Specific implementation or types may require additional parameters to enable encryption.

      The default is false.

      Overrides:
      encrypted in class NetworkApplicationBuilder
      Parameters:
      encrypted - Whether encryption is enabled
      Returns:
      This builder
    • workerCreator

      public NetServerBuilder workerCreator(Function<SocketConnection,Consumer<Runnable>> workerCreator)
      Description copied from class: NetworkApplicationBuilder
      Sets a worker creator which creates a worker instance for each connection created.

      The default is null (no workers).

      Overrides:
      workerCreator in class NetworkApplicationBuilder
      Parameters:
      workerCreator - The function
      Returns:
      This builder
    • sslContext

      public NetServerBuilder sslContext(SSLContext sslContext)
      Description copied from class: NetworkApplicationBuilder
      Sets the SSLContext to use for encryption.

      This method implicitly enables encryption if the given parameter is not null, and disables it otherwise.

      The default is null. Setting this parameter may be required by the implementation if encryption is enabled.

      Overrides:
      sslContext in class NetworkApplicationBuilder
      Parameters:
      sslContext - The SSLContext
      Returns:
      This builder
    • set

      public NetServerBuilder set(String option, Object value)
      Description copied from class: NetworkApplicationBuilder
      Sets an implementation specific configuration parameter.
      Overrides:
      set in class NetworkApplicationBuilder
      Parameters:
      option - The name of the parameter
      value - The value
    • bindAddresses

      public NetServerBuilder bindAddresses(Collection<InetAddress> bindAddresses)
      Sets the local addresses the server should bind to.

      This method overrides any previous local address settings.

      null or a collection with a single null element may be passed to bind to the default addresses chosen by the system or implementation. This is also the default.

      Parameters:
      bindAddresses - The local addresses
      Returns:
      This builder
      Throws:
      NullPointerException - If the collection has more than one element and any element is null
    • bindAddresses

      public NetServerBuilder bindAddresses(InetAddress... bindAddresses)
      Sets the local addresses the server should bind to. See bindAddresses(Collection).

      This method overrides any previous local address settings.

      Parameters:
      bindAddresses - The local addresses
      Returns:
      This builder
      Throws:
      NullPointerException - If the collection has more than one element and any element is null
    • bindAddress

      public NetServerBuilder bindAddress(InetAddress bindAddress)
      Sets the single local address the server should bind to.

      This method overrides any previous local address settings.

      Parameters:
      bindAddress - The local address
      Returns:
      This builder
      Throws:
      NullPointerException - If the given value is null
    • addBindAddress

      public NetServerBuilder addBindAddress(InetAddress bindAddress)
      Adds a local address to bind to.
      Parameters:
      bindAddress - The local address
      Returns:
      This builder
      Throws:
      NullPointerException - If the given value is null
      See Also:
    • ports

      public NetServerBuilder ports(Collection<Integer> ports)
      Sets the network ports this server should listen on.

      This method overrides any previous port settings.

      This method and listenPath(String) are mutually exclusive, but one of them is required.

      Parameters:
      ports - The ports
      Returns:
      This builder
      Throws:
      NullPointerException - If an element is null
      IllegalArgumentException - If a port is not positive
    • ports

      public NetServerBuilder ports(int... ports)
      Sets the network ports this server should listen on.

      This method overrides any previous port settings.

      This method and listenPath(String) are mutually exclusive, but one of them is required.

      Parameters:
      ports - The ports
      Returns:
      This builder
      Throws:
      IllegalArgumentException - If a port is not positive
    • port

      public NetServerBuilder port(int port)
      Sets a single network port this server should listen on.

      This method overrides any previous port settings.

      This method and listenPath(String) are mutually exclusive, but one of them is required.

      Parameters:
      port - The port
      Returns:
      This builder
      Throws:
      IllegalArgumentException - If the port is not positive
    • addPort

      public NetServerBuilder addPort(int port)
      Adds a network port this server should listen on.

      This method and listenPath(String) are mutually exclusive, but one of them is required.

      Parameters:
      port - The port
      Returns:
      This builder
      Throws:
      IllegalArgumentException - If the port is not positive
    • listenPath

      public NetServerBuilder listenPath(String listenPath)
      Sets the local file system path the server should listen on.

      This method and ports(Collection) (and other methods to set ports) are mutually exclusive, but one of them is required.

      Parameters:
      listenPath - The path
      Returns:
      This builder
    • connectionBacklog

      public NetServerBuilder connectionBacklog(int connectionBacklog)
      Sets the maximum length of the queue for pending connections, if applicable.

      The default, 0, may be set to let the system or implementation choose an appropriate value.

      Parameters:
      connectionBacklog - The queue length
      Returns:
      This builder
      Throws:
      IllegalArgumentException - If the given value is negative
    • connectionIdleTimeout

      public NetServerBuilder connectionIdleTimeout(int connectionIdleTimeout)
      Sets the minimum time in seconds to keep an idle connection with no traffic.

      The default, 0, may be set to disable idle timeouts.

      Parameters:
      connectionIdleTimeout - The idle timeout in seconds
      Returns:
      This builder
      Throws:
      IllegalArgumentException - If the given value is negative
    • applicationLayerProtocols

      public NetServerBuilder applicationLayerProtocols(Collection<String> applicationLayerProtocols)
      Sets the application protocol name options the server presents, for example during TLS Application-Layer Protocol Negotiation. The elements in this list should be ordered from most-preferred to least-preferred protocol name.

      The default is null (protocol presented by client is selected, or negotiation is disabled).

      Parameters:
      applicationLayerProtocols - The protocol names
      Returns:
      This builder
    • applicationLayerProtocols

      public NetServerBuilder applicationLayerProtocols(String... applicationLayerProtocols)
      Sets the application protocol name options the server presents. See applicationLayerProtocols(Collection).
      Parameters:
      applicationLayerProtocols - The protocol names
      Returns:
      This builder
    • prepareBuild

      protected void prepareBuild()
      Description copied from class: NetworkApplicationBuilder
      This method does parameter validation and preparations.
      Overrides:
      prepareBuild in class NetworkApplicationBuilder