Package net.sf.eBus.config
Class EConfigure.ConnectionBuilder
- java.lang.Object
-
- net.sf.eBus.config.EConfigure.AbstractBuilder<EConfigure.ConnectionBuilder>
-
- net.sf.eBus.config.EConfigure.ConnectionBuilder
-
- Enclosing class:
- EConfigure
public static final class EConfigure.ConnectionBuilder extends EConfigure.AbstractBuilder<EConfigure.ConnectionBuilder>
Constructs anEConfigure.RemoteConnectioninstance 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 address:
ERemoteApp.ANY_PORTand wildcard address. - 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
ERemoteAppfinal 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
-
-
Field Summary
-
Fields inherited from class net.sf.eBus.config.EConfigure.AbstractBuilder
mByteOrder, mCanPause, mHbDelay, mHbReplyDelay, mInputBufferSize, mLoaderFlag, mMsgQueueSize, mName, mOutputBufferSize, mPauseConfig, mRetransmitDelay, mRetransmitLimit, mSSLContext
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EConfigure.ConnectionBuilderaddress(InetSocketAddress address)Set the connection address.EConfigure.ConnectionBuilderbindAddress(InetSocketAddress address)Bind the connection local address to given address.EConfigure.ConnectionBuilderbindPort(int port)Bind the connection local port to this port and the wildcard address.EConfigure.RemoteConnectionbuild()Returns the eBus connection configuration built from the previously set parameters.EConfigure.ConnectionBuilderconfiguration(EConfigure.RemoteConnection config)Copies in the settings fromconfigto this builder.EConfigure.ConnectionBuilderreconnect(boolean flag)Sets the reconnect flag to the given value.EConfigure.ConnectionBuilderreconnectDelay(Duration time)Sets the reconnect delay to the given value.EConfigure.ConnectionBuilderselector(String selector)Sets the selector used for the connection.protected Validatorvalidate(Validator problems)Validates the builder parameters.-
Methods inherited from class net.sf.eBus.config.EConfigure.AbstractBuilder
byteOrder, canPause, configuration, connectionType, heartbeatDelay, heartbeatReplyDelay, inputBufferSize, loaderFlag, messageQueueSize, name, outputBufferSize, pauseConfig, retransmitDelay, retransmitLimit, sslContext
-
-
-
-
Method Detail
-
configuration
public EConfigure.ConnectionBuilder configuration(EConfigure.RemoteConnection config)
Copies in the settings fromconfigto this builder. This method is provided for making changes to an existing configuration sinceEConfigure.RemoteConnectionis immutable.if
configisnull, then nothing is done and the builder remains unchanged.- Parameters:
config- copy settings from this configuration.- Returns:
thisconnection builder.
-
address
public EConfigure.ConnectionBuilder address(InetSocketAddress address)
Set the connection address.- Parameters:
address- connection address.- Returns:
thisconnection builder.- Throws:
com.typesafe.config.ConfigException- ifaddressisnull.
-
bindPort
public EConfigure.ConnectionBuilder bindPort(int port)
Bind the connection local port to this port and the wildcard address.- Parameters:
port- connection local bind port.- Returns:
thisconnection builder.- Throws:
com.typesafe.config.ConfigException- ifportis either <ENetConfigure.ANY_PORTor >ENetConfigure.MAX_PORT.
-
bindAddress
public EConfigure.ConnectionBuilder bindAddress(@Nullable InetSocketAddress address)
Bind the connection local address to given address. Ifaddressis set tonull, then connection local address is set to an automatically assigned socket address and port.- Parameters:
address- connection local bind address.- Returns:
thisconnection builder.
-
selector
public EConfigure.ConnectionBuilder selector(String selector)
Sets the selector used for the connection.- Parameters:
selector- eBus selector name.- Returns:
thisconnection builder.- Throws:
com.typesafe.config.ConfigException- ifnameisnull, an empty string or not a known selector.
-
reconnect
public EConfigure.ConnectionBuilder reconnect(boolean flag)
Sets the reconnect flag to the given value.truemeans the connection will be re-established if lost;falsemeans a lost connection is left down.- Parameters:
flag- establish lost connection flag.- Returns:
thisconnection 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 istrue.- Parameters:
time- reconnect a lost connect after this millisecond delay.- Returns:
thisconnection builder.- Throws:
com.typesafe.config.ConfigException- iftimeisnullor < 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 totruebut the reconnect delay is not set.
-
validate
protected Validator validate(Validator problems)
Validates the builder parameters. This validation is "fail slow" meaning that a single validation call will determine all configuration errors.- Overrides:
validatein classEConfigure.AbstractBuilder<EConfigure.ConnectionBuilder>- Parameters:
problems- record configuration problems in this list.- Returns:
problemssovalidatecalls may be chained together.
-
-