Class EConfigure.ConnectionBuilder

  • Enclosing class:
    EConfigure

    public static final class EConfigure.ConnectionBuilder
    extends EConfigure.AbstractBuilder<EConfigure.ConnectionBuilder>
    Constructs an EConfigure.RemoteConnection instance based on the parameters set via the builder's API. The minimally allowed configuration is the connection name and address. The remaining parameters are set to the following defaults:
    • connection type: EConfigure.ConnectionType.TCP - plain text TCP connection.
    • bind port: ERemoteApp.ANY_PORT.
    • input buffer size: zero - use system default buffer size.
    • output buffer size: zero - use system default buffer size.
    • byte order: little-endian.
    • maximum message queue size: zero - unlimited queue size.
    • connection selector thread: AsyncChannel.defaultSelector.
    • reconnect flag and delay: reconnection is turned off and delay set to zero.
    • heartbeat millisecond delay: zero - heartbeating off.
    • heartbeat millisecond reply delay: zero - wait indefinitely for a reply.

    Example building an ERemoteApp

    final InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), 12345);
    final SSLContext secureContext = ...;
    final EConfigure.ConnectionBuilder builder = EConfigure.connectionBuilder();
    
    ERemoteApp.openConnection(builder.name("Conn0")
                                     .address(address)
                                     .bindPort(0)
                                     .connectionType(EConfigure.ConnectionType.SECURE_TCP)
                                     .sslContext(secureContext)
                                     .inputBufferSize(4_996)
                                     .outputBufferSize(8_192)
                                     .byteOrder(ByteOrder.BIG_ENDIAN)
                                     .messageQueueSize(0)
                                     .selector("connSelector")
                                     .reconnect(true)
                                     .reconnectDelay(500L)
                                     .heartbeatDelay(0L)
                                     .heartbeatReplyDelay(0L)
                                     .build());
    Author:
    Charles W. Rapp
    See Also:
    EConfigure.ServerBuilder
    • Method Detail

      • configuration

        public EConfigure.ConnectionBuilder configuration​(EConfigure.RemoteConnection config)
        Copies in the settings from config to this builder. This method is provided for making changes to an existing configuration since EConfigure.RemoteConnection is immutable.

        if config is null, then nothing is done and the builder remains unchanged.

        Parameters:
        config - copy settings from this configuration.
        Returns:
        this connection builder.
      • address

        public EConfigure.ConnectionBuilder address​(InetSocketAddress address)
        Set the connection address.
        Parameters:
        address - connection address.
        Returns:
        this connection builder.
        Throws:
        com.typesafe.config.ConfigException - if address is null.
      • selector

        public EConfigure.ConnectionBuilder selector​(String selector)
        Sets the selector used for the connection.
        Parameters:
        selector - eBus selector name.
        Returns:
        this connection builder.
        Throws:
        com.typesafe.config.ConfigException - if name is null, an empty string or not a known selector.
      • reconnect

        public EConfigure.ConnectionBuilder reconnect​(boolean flag)
        Sets the reconnect flag to the given value. true means the connection will be re-established if lost; false means a lost connection is left down.
        Parameters:
        flag - establish lost connection flag.
        Returns:
        this connection builder.
        See Also:
        reconnectDelay(Duration)
      • reconnectDelay

        public EConfigure.ConnectionBuilder reconnectDelay​(Duration time)
        Sets the reconnect delay to the given value. This value is used on if the reconnect flag is true.
        Parameters:
        time - reconnect a lost connect after this millisecond delay.
        Returns:
        this connection builder.
        Throws:
        com.typesafe.config.ConfigException - if time is null or < zero.
        See Also:
        reconnect(boolean)
      • build

        public EConfigure.RemoteConnection build()
        Returns the eBus connection configuration built from the previously set parameters.
        Returns:
        an eBus connection configuration.
        Throws:
        com.typesafe.config.ConfigException - if either connection name or address is not set or if reconnect flag is set to true but the reconnect delay is not set.
      • validate

        protected void validate()
        Validates the builder parameters. Called for effect only.
        Overrides:
        validate in class EConfigure.AbstractBuilder<EConfigure.ConnectionBuilder>
        Throws:
        com.typesafe.config.ConfigException - if a required parameter is not set or if a parameter is not set to a valid value with respect to another parameter.