public class ReuseSessionBuilder extends AbstractParent<SessionBuilder> implements Builder<ReuseSessionOptions>
When sending the first message, a new session is created. Later, when sending
the next message, if the session is still alive, this session is reused. As
the connection is not actively maintained, the session may be killed by the
server. Therefore to check if the session is still alive, an
EnquireLink
request is sent. If a response is received from the
server, then the session is still alive and the message can be sent using the
same session. If a failure response or no response is received after some
time from the server, then a new session must be created.
To check if the session is still alive, the EnquireLink
request is
sent just before sending the real message. In order to prevent sending an
EnquireLink
request before every message, the date
of the last sent message or EnquireLink
is kept. This date is
compared to a delay to ensure that no EnquireLink
is sent during this
delay.
This builder let you configure:
EnquireLink
requestEnquireLink
request
againparent
Constructor and Description |
---|
ReuseSessionBuilder(SessionBuilder parent,
BuildContext buildContext) |
Modifier and Type | Method and Description |
---|---|
ReuseSessionOptions |
build()
Instantiate and configures the instance.
|
ConfigurationValueBuilder<ReuseSessionBuilder,Boolean> |
enable()
Enable or disable the reuse the same session (if possible) for sending
messages.
|
ReuseSessionBuilder |
enable(Boolean enable)
Enable or disable the reuse the same session (if possible) for sending
messages.
|
ConfigurationValueBuilder<ReuseSessionBuilder,Long> |
lastInteractionExpiration()
To check if the session is still alive, an
EnquireLink request is
sent. |
ReuseSessionBuilder |
lastInteractionExpiration(Long delay)
To check if the session is still alive, an
EnquireLink request is
sent. |
ConfigurationValueBuilder<ReuseSessionBuilder,Long> |
responseTimeout()
To check if the session is still alive, an
EnquireLink request is
sent. |
ReuseSessionBuilder |
responseTimeout(Long timeout)
To check if the session is still alive, an
EnquireLink request is
sent. |
and
public ReuseSessionBuilder(SessionBuilder parent, BuildContext buildContext)
public ReuseSessionBuilder enable(Boolean enable)
The value set using this method takes precedence over any property and
default value configured using enable()
.
.enable(true) .enable() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(false)
.enable(true) .enable() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(false)In both cases,
enable(true)
is used.
If this method is called several times, only the last value is used.
If null
value is set, it is like not setting a value at all. The
property/default value configuration is applied.
enable
- enable reuse of same sessionpublic ConfigurationValueBuilder<ReuseSessionBuilder,Boolean> enable()
This method is mainly used by Configurer
s to register some
property keys and/or a default value. The aim is to let developer be able
to externalize its configuration (using system properties, configuration
file or anything else). If the developer doesn't configure any value for
the registered properties, the default value is used (if set).
.enable() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(false)
Non-null value set using enable(Boolean)
takes precedence over
property values and default value.
.enable(true) .enable() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(false)The value
true
is used regardless of the value of the properties
and default value.
See ConfigurationValueBuilder
for more information.
public ReuseSessionBuilder responseTimeout(Long timeout)
EnquireLink
request is
sent. This request may fail since the session may be killed by the
server. The timeout ensures that the client doesn't wait too long for a
response that may never come.
The maximum amount of time (in milliseconds) to wait for receiving a
response from the server to an EnquireLink
request.
The value set using this method takes precedence over any property and
default value configured using responseTimeout()
.
.responseTimeout(10000L) .responseTimeout() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(5000L)
.responseTimeout(10000L) .responseTimeout() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(5000L)In both cases,
responseTimeout(10000L)
is used.
If this method is called several times, only the last value is used.
If null
value is set, it is like not setting a value at all. The
property/default value configuration is applied.
timeout
- the maximum amount of time (in milliseconds) to wait for the
responsepublic ConfigurationValueBuilder<ReuseSessionBuilder,Long> responseTimeout()
EnquireLink
request is
sent. This request may fail since the session may be killed by the
server. The timeout ensures that the client doesn't wait too long for a
response that may never come.
The maximum amount of time (in milliseconds) to wait for receiving a
response from the server to an EnquireLink
request.
This method is mainly used by Configurer
s to register some
property keys and/or a default value. The aim is to let developer be able
to externalize its configuration (using system properties, configuration
file or anything else). If the developer doesn't configure any value for
the registered properties, the default value is used (if set).
.responseTimeout() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(5000L)
Non-null value set using responseTimeout(Long)
takes precedence
over property values and default value.
.responseTimeout(10000L) .responseTimeout() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(5000L)The value
10000L
is used regardless of the value of the
properties and default value.
See ConfigurationValueBuilder
for more information.
public ReuseSessionBuilder lastInteractionExpiration(Long delay)
EnquireLink
request is
sent. The request is sent just before sending the message.
This is the time (in milliseconds) to wait before considering last
EnquireLink
response as expired (need to send a new
EnquireLink
request to check if session is still alive).
This is needed to prevent sending EnquireLink
request every time
a message has to be sent. Instead it considers that the time elapsed
between now and the last EnquireLink
response (or the last sent
message) is not enough so a new EnquireLink
is not necessary to
check if session is still alive.
Set to 0 to always check session before sending message.
The value set using this method takes precedence over any property and
default value configured using lastInteractionExpiration()
.
.delay(60000L) .delay() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(60000L)
.delay(60000L) .delay() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(60000L)In both cases,
delay(60000L)
is used.
If this method is called several times, only the last value is used.
If null
value is set, it is like not setting a value at all. The
property/default value configuration is applied.
delay
- The time to wait (in milliseconds) to wait before sending a
new EnquireLink
request to check if session is still
alive.public ConfigurationValueBuilder<ReuseSessionBuilder,Long> lastInteractionExpiration()
EnquireLink
request is
sent. The request is sent just before sending the message.
This is the time (in milliseconds) to wait before considering last
EnquireLink
response as expired (need to send a new
EnquireLink
request to check if session is still alive).
This is needed to prevent sending EnquireLink
request every time
a message has to be sent. Instead it considers that the time elapsed
between now and the last EnquireLink
response (or the last sent
message) is not enough so a new EnquireLink
is not necessary to
check if session is still alive.
Set to 0 to always check session before sending message.
This method is mainly used by Configurer
s to register some
property keys and/or a default value. The aim is to let developer be able
to externalize its configuration (using system properties, configuration
file or anything else). If the developer doesn't configure any value for
the registered properties, the default value is used (if set).
.delay() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(60000L)
Non-null value set using lastInteractionExpiration(Long)
takes precedence over
property values and default value.
.delay(60000L) .delay() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(60000L)The value
60000L
is used regardless of the value of the
properties and default value.
See ConfigurationValueBuilder
for more information.
public ReuseSessionOptions build()
Builder
build
in interface Builder<ReuseSessionOptions>
Copyright © 2021. All rights reserved.