| 1 | package fr.sii.ogham.sms.builder.cloudhopper; | |
| 2 | ||
| 3 | import com.cloudhopper.smpp.pdu.EnquireLink; | |
| 4 | ||
| 5 | import fr.sii.ogham.core.builder.Builder; | |
| 6 | import fr.sii.ogham.core.builder.configuration.ConfigurationValueBuilder; | |
| 7 | import fr.sii.ogham.core.builder.configuration.ConfigurationValueBuilderHelper; | |
| 8 | import fr.sii.ogham.core.builder.configurer.Configurer; | |
| 9 | import fr.sii.ogham.core.builder.context.BuildContext; | |
| 10 | import fr.sii.ogham.core.fluent.AbstractParent; | |
| 11 | import fr.sii.ogham.sms.sender.impl.cloudhopper.ReuseSessionOptions; | |
| 12 | ||
| 13 | /** | |
| 14 | * Builder to configure how reuse session management should behave. | |
| 15 | * | |
| 16 | * <p> | |
| 17 | * When sending the first message, a new session is created. Later, when sending | |
| 18 | * the next message, if the session is still alive, this session is reused. As | |
| 19 | * the connection is not actively maintained, the session may be killed by the | |
| 20 | * server. Therefore to check if the session is still alive, an | |
| 21 | * {@link EnquireLink} request is sent. If a response is received from the | |
| 22 | * server, then the session is still alive and the message can be sent using the | |
| 23 | * same session. If a failure response or no response is received after some | |
| 24 | * time from the server, then a new session must be created. | |
| 25 | * | |
| 26 | * <p> | |
| 27 | * To check if the session is still alive, the {@link EnquireLink} request is | |
| 28 | * sent just before sending the real message. In order to prevent sending an | |
| 29 | * {@link EnquireLink} request before <strong>every</strong> message, the date | |
| 30 | * of the last sent message or {@link EnquireLink} is kept. This date is | |
| 31 | * compared to a delay to ensure that no {@link EnquireLink} is sent during this | |
| 32 | * delay. | |
| 33 | * | |
| 34 | * <p> | |
| 35 | * This builder let you configure: | |
| 36 | * <ul> | |
| 37 | * <li>Enable/disable reuse session management</li> | |
| 38 | * <li>The maximum time to wait for a response from the server for | |
| 39 | * {@link EnquireLink} request</li> | |
| 40 | * <li>The time to wait before sending a new {@link EnquireLink} request | |
| 41 | * again</li> | |
| 42 | * </ul> | |
| 43 | * | |
| 44 | * @author Aurélien Baudet | |
| 45 | * | |
| 46 | */ | |
| 47 | public class ReuseSessionBuilder extends AbstractParent<SessionBuilder> implements Builder<ReuseSessionOptions> { | |
| 48 | private final ConfigurationValueBuilderHelper<ReuseSessionBuilder, Boolean> enableValueBuilder; | |
| 49 | private final ConfigurationValueBuilderHelper<ReuseSessionBuilder, Long> lastInteractionExpirationDelayValueBuilder; | |
| 50 | private final ConfigurationValueBuilderHelper<ReuseSessionBuilder, Long> enquireLinkTimeoutValueBuilder; | |
| 51 | ||
| 52 | public ReuseSessionBuilder(SessionBuilder parent, BuildContext buildContext) { | |
| 53 | super(parent); | |
| 54 | this.enableValueBuilder = buildContext.newConfigurationValueBuilder(this, Boolean.class); | |
| 55 | this.lastInteractionExpirationDelayValueBuilder = buildContext.newConfigurationValueBuilder(this, Long.class); | |
| 56 | this.enquireLinkTimeoutValueBuilder = buildContext.newConfigurationValueBuilder(this, Long.class); | |
| 57 | } | |
| 58 | ||
| 59 | /** | |
| 60 | * Enable or disable the reuse the same session (if possible) for sending | |
| 61 | * messages. | |
| 62 | * | |
| 63 | * <p> | |
| 64 | * The value set using this method takes precedence over any property and | |
| 65 | * default value configured using {@link #enable()}. | |
| 66 | * | |
| 67 | * <pre> | |
| 68 | * .enable(true) | |
| 69 | * .enable() | |
| 70 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 71 | * .defaultValue(false) | |
| 72 | * </pre> | |
| 73 | * | |
| 74 | * <pre> | |
| 75 | * .enable(true) | |
| 76 | * .enable() | |
| 77 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 78 | * .defaultValue(false) | |
| 79 | * </pre> | |
| 80 | * | |
| 81 | * In both cases, {@code enable(true)} is used. | |
| 82 | * | |
| 83 | * <p> | |
| 84 | * If this method is called several times, only the last value is used. | |
| 85 | * | |
| 86 | * <p> | |
| 87 | * If {@code null} value is set, it is like not setting a value at all. The | |
| 88 | * property/default value configuration is applied. | |
| 89 | * | |
| 90 | * @param enable | |
| 91 | * enable reuse of same session | |
| 92 | * @return this instance for fluent chaining | |
| 93 | */ | |
| 94 | public ReuseSessionBuilder enable(Boolean enable) { | |
| 95 |
2
1. enable : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → NO_COVERAGE 2. enable : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → KILLED |
enableValueBuilder.setValue(enable); |
| 96 |
2
1. enable : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::enable → NO_COVERAGE 2. enable : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::enable → KILLED |
return this; |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * Enable or disable the reuse the same session (if possible) for sending | |
| 101 | * messages. | |
| 102 | * | |
| 103 | * <p> | |
| 104 | * This method is mainly used by {@link Configurer}s to register some | |
| 105 | * property keys and/or a default value. The aim is to let developer be able | |
| 106 | * to externalize its configuration (using system properties, configuration | |
| 107 | * file or anything else). If the developer doesn't configure any value for | |
| 108 | * the registered properties, the default value is used (if set). | |
| 109 | * | |
| 110 | * <pre> | |
| 111 | * .enable() | |
| 112 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 113 | * .defaultValue(false) | |
| 114 | * </pre> | |
| 115 | * | |
| 116 | * <p> | |
| 117 | * Non-null value set using {@link #enable(Boolean)} takes precedence over | |
| 118 | * property values and default value. | |
| 119 | * | |
| 120 | * <pre> | |
| 121 | * .enable(true) | |
| 122 | * .enable() | |
| 123 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 124 | * .defaultValue(false) | |
| 125 | * </pre> | |
| 126 | * | |
| 127 | * The value {@code true} is used regardless of the value of the properties | |
| 128 | * and default value. | |
| 129 | * | |
| 130 | * <p> | |
| 131 | * See {@link ConfigurationValueBuilder} for more information. | |
| 132 | * | |
| 133 | * | |
| 134 | * @return the builder to configure property keys/default value | |
| 135 | */ | |
| 136 | public ConfigurationValueBuilder<ReuseSessionBuilder, Boolean> enable() { | |
| 137 |
5
1. enable : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::enable → KILLED 2. enable : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::enable → KILLED 3. enable : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::enable → KILLED 4. enable : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::enable → KILLED 5. enable : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::enable → KILLED |
return enableValueBuilder; |
| 138 | } | |
| 139 | ||
| 140 | /** | |
| 141 | * To check if the session is still alive, an {@link EnquireLink} request is | |
| 142 | * sent. This request may fail since the session may be killed by the | |
| 143 | * server. The timeout ensures that the client doesn't wait too long for a | |
| 144 | * response that may never come. | |
| 145 | * | |
| 146 | * The maximum amount of time (in milliseconds) to wait for receiving a | |
| 147 | * response from the server to an {@link EnquireLink} request. | |
| 148 | * | |
| 149 | * <p> | |
| 150 | * The value set using this method takes precedence over any property and | |
| 151 | * default value configured using {@link #responseTimeout()}. | |
| 152 | * | |
| 153 | * <pre> | |
| 154 | * .responseTimeout(10000L) | |
| 155 | * .responseTimeout() | |
| 156 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 157 | * .defaultValue(5000L) | |
| 158 | * </pre> | |
| 159 | * | |
| 160 | * <pre> | |
| 161 | * .responseTimeout(10000L) | |
| 162 | * .responseTimeout() | |
| 163 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 164 | * .defaultValue(5000L) | |
| 165 | * </pre> | |
| 166 | * | |
| 167 | * In both cases, {@code responseTimeout(10000L)} is used. | |
| 168 | * | |
| 169 | * <p> | |
| 170 | * If this method is called several times, only the last value is used. | |
| 171 | * | |
| 172 | * <p> | |
| 173 | * If {@code null} value is set, it is like not setting a value at all. The | |
| 174 | * property/default value configuration is applied. | |
| 175 | * | |
| 176 | * @param timeout | |
| 177 | * the maximum amount of time (in milliseconds) to wait for the | |
| 178 | * response | |
| 179 | * @return this instance for fluent chaining | |
| 180 | */ | |
| 181 | public ReuseSessionBuilder responseTimeout(Long timeout) { | |
| 182 |
2
1. responseTimeout : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → NO_COVERAGE 2. responseTimeout : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → KILLED |
enquireLinkTimeoutValueBuilder.setValue(timeout); |
| 183 |
2
1. responseTimeout : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::responseTimeout → NO_COVERAGE 2. responseTimeout : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::responseTimeout → KILLED |
return this; |
| 184 | } | |
| 185 | ||
| 186 | /** | |
| 187 | * To check if the session is still alive, an {@link EnquireLink} request is | |
| 188 | * sent. This request may fail since the session may be killed by the | |
| 189 | * server. The timeout ensures that the client doesn't wait too long for a | |
| 190 | * response that may never come. | |
| 191 | * | |
| 192 | * The maximum amount of time (in milliseconds) to wait for receiving a | |
| 193 | * response from the server to an {@link EnquireLink} request. | |
| 194 | * | |
| 195 | * <p> | |
| 196 | * This method is mainly used by {@link Configurer}s to register some | |
| 197 | * property keys and/or a default value. The aim is to let developer be able | |
| 198 | * to externalize its configuration (using system properties, configuration | |
| 199 | * file or anything else). If the developer doesn't configure any value for | |
| 200 | * the registered properties, the default value is used (if set). | |
| 201 | * | |
| 202 | * <pre> | |
| 203 | * .responseTimeout() | |
| 204 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 205 | * .defaultValue(5000L) | |
| 206 | * </pre> | |
| 207 | * | |
| 208 | * <p> | |
| 209 | * Non-null value set using {@link #responseTimeout(Long)} takes precedence | |
| 210 | * over property values and default value. | |
| 211 | * | |
| 212 | * <pre> | |
| 213 | * .responseTimeout(10000L) | |
| 214 | * .responseTimeout() | |
| 215 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 216 | * .defaultValue(5000L) | |
| 217 | * </pre> | |
| 218 | * | |
| 219 | * The value {@code 10000L} is used regardless of the value of the | |
| 220 | * properties and default value. | |
| 221 | * | |
| 222 | * <p> | |
| 223 | * See {@link ConfigurationValueBuilder} for more information. | |
| 224 | * | |
| 225 | * | |
| 226 | * @return the builder to configure property keys/default value | |
| 227 | */ | |
| 228 | public ConfigurationValueBuilder<ReuseSessionBuilder, Long> responseTimeout() { | |
| 229 |
5
1. responseTimeout : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::responseTimeout → KILLED 2. responseTimeout : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::responseTimeout → KILLED 3. responseTimeout : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::responseTimeout → KILLED 4. responseTimeout : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::responseTimeout → KILLED 5. responseTimeout : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::responseTimeout → KILLED |
return enquireLinkTimeoutValueBuilder; |
| 230 | } | |
| 231 | ||
| 232 | /** | |
| 233 | * To check if the session is still alive, an {@link EnquireLink} request is | |
| 234 | * sent. The request is sent just before sending the message. | |
| 235 | * | |
| 236 | * This is the time (in milliseconds) to wait before considering last | |
| 237 | * {@link EnquireLink} response as expired (need to send a new | |
| 238 | * {@link EnquireLink} request to check if session is still alive). | |
| 239 | * | |
| 240 | * <p> | |
| 241 | * This is needed to prevent sending {@link EnquireLink} request every time | |
| 242 | * a message has to be sent. Instead it considers that the time elapsed | |
| 243 | * between now and the last {@link EnquireLink} response (or the last sent | |
| 244 | * message) is not enough so a new {@link EnquireLink} is not necessary to | |
| 245 | * check if session is still alive. | |
| 246 | * | |
| 247 | * <p> | |
| 248 | * Set to 0 to always check session before sending message. | |
| 249 | * | |
| 250 | * <p> | |
| 251 | * The value set using this method takes precedence over any property and | |
| 252 | * default value configured using {@link #lastInteractionExpiration()}. | |
| 253 | * | |
| 254 | * <pre> | |
| 255 | * .delay(60000L) | |
| 256 | * .delay() | |
| 257 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 258 | * .defaultValue(60000L) | |
| 259 | * </pre> | |
| 260 | * | |
| 261 | * <pre> | |
| 262 | * .delay(60000L) | |
| 263 | * .delay() | |
| 264 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 265 | * .defaultValue(60000L) | |
| 266 | * </pre> | |
| 267 | * | |
| 268 | * In both cases, {@code delay(60000L)} is used. | |
| 269 | * | |
| 270 | * <p> | |
| 271 | * If this method is called several times, only the last value is used. | |
| 272 | * | |
| 273 | * <p> | |
| 274 | * If {@code null} value is set, it is like not setting a value at all. The | |
| 275 | * property/default value configuration is applied. | |
| 276 | * | |
| 277 | * @param delay | |
| 278 | * The time to wait (in milliseconds) to wait before sending a | |
| 279 | * new {@link EnquireLink} request to check if session is still | |
| 280 | * alive. | |
| 281 | * @return this instance for fluent chaining | |
| 282 | */ | |
| 283 | public ReuseSessionBuilder lastInteractionExpiration(Long delay) { | |
| 284 |
2
1. lastInteractionExpiration : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → NO_COVERAGE 2. lastInteractionExpiration : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → KILLED |
lastInteractionExpirationDelayValueBuilder.setValue(delay); |
| 285 |
2
1. lastInteractionExpiration : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::lastInteractionExpiration → NO_COVERAGE 2. lastInteractionExpiration : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::lastInteractionExpiration → KILLED |
return this; |
| 286 | } | |
| 287 | ||
| 288 | /** | |
| 289 | * To check if the session is still alive, an {@link EnquireLink} request is | |
| 290 | * sent. The request is sent just before sending the message. | |
| 291 | * | |
| 292 | * This is the time (in milliseconds) to wait before considering last | |
| 293 | * {@link EnquireLink} response as expired (need to send a new | |
| 294 | * {@link EnquireLink} request to check if session is still alive). | |
| 295 | * | |
| 296 | * <p> | |
| 297 | * This is needed to prevent sending {@link EnquireLink} request every time | |
| 298 | * a message has to be sent. Instead it considers that the time elapsed | |
| 299 | * between now and the last {@link EnquireLink} response (or the last sent | |
| 300 | * message) is not enough so a new {@link EnquireLink} is not necessary to | |
| 301 | * check if session is still alive. | |
| 302 | * | |
| 303 | * <p> | |
| 304 | * Set to 0 to always check session before sending message. | |
| 305 | * | |
| 306 | * <p> | |
| 307 | * This method is mainly used by {@link Configurer}s to register some | |
| 308 | * property keys and/or a default value. The aim is to let developer be able | |
| 309 | * to externalize its configuration (using system properties, configuration | |
| 310 | * file or anything else). If the developer doesn't configure any value for | |
| 311 | * the registered properties, the default value is used (if set). | |
| 312 | * | |
| 313 | * <pre> | |
| 314 | * .delay() | |
| 315 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 316 | * .defaultValue(60000L) | |
| 317 | * </pre> | |
| 318 | * | |
| 319 | * <p> | |
| 320 | * Non-null value set using {@link #lastInteractionExpiration(Long)} takes precedence over | |
| 321 | * property values and default value. | |
| 322 | * | |
| 323 | * <pre> | |
| 324 | * .delay(60000L) | |
| 325 | * .delay() | |
| 326 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
| 327 | * .defaultValue(60000L) | |
| 328 | * </pre> | |
| 329 | * | |
| 330 | * The value {@code 60000L} is used regardless of the value of the | |
| 331 | * properties and default value. | |
| 332 | * | |
| 333 | * <p> | |
| 334 | * See {@link ConfigurationValueBuilder} for more information. | |
| 335 | * | |
| 336 | * | |
| 337 | * @return the builder to configure property keys/default value | |
| 338 | */ | |
| 339 | public ConfigurationValueBuilder<ReuseSessionBuilder, Long> lastInteractionExpiration() { | |
| 340 |
5
1. lastInteractionExpiration : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::lastInteractionExpiration → KILLED 2. lastInteractionExpiration : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::lastInteractionExpiration → KILLED 3. lastInteractionExpiration : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::lastInteractionExpiration → KILLED 4. lastInteractionExpiration : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::lastInteractionExpiration → KILLED 5. lastInteractionExpiration : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::lastInteractionExpiration → KILLED |
return lastInteractionExpirationDelayValueBuilder; |
| 341 | } | |
| 342 | ||
| 343 | @Override | |
| 344 | public ReuseSessionOptions build() { | |
| 345 | ReuseSessionOptions reuseSessionOptions = new ReuseSessionOptions(); | |
| 346 |
2
1. build : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/ReuseSessionOptions::setEnable → SURVIVED 2. build : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/ReuseSessionOptions::setEnable → KILLED |
reuseSessionOptions.setEnable(enableValueBuilder.getValue(false)); |
| 347 |
2
1. build : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/ReuseSessionOptions::setLastInteractionExpirationDelay → SURVIVED 2. build : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/ReuseSessionOptions::setLastInteractionExpirationDelay → KILLED |
reuseSessionOptions.setLastInteractionExpirationDelay(lastInteractionExpirationDelayValueBuilder.getValue(0L)); |
| 348 |
3
1. build : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/ReuseSessionOptions::setEnquireLinkTimeout → SURVIVED 2. build : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/ReuseSessionOptions::setEnquireLinkTimeout → TIMED_OUT 3. build : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/ReuseSessionOptions::setEnquireLinkTimeout → KILLED |
reuseSessionOptions.setEnquireLinkTimeout(enquireLinkTimeoutValueBuilder.getValue(0L)); |
| 349 |
2
1. build : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::build → SURVIVED 2. build : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReuseSessionBuilder::build → KILLED |
return reuseSessionOptions; |
| 350 | } | |
| 351 | } | |
Mutations | ||
| 95 |
1.1 2.2 |
|
| 96 |
1.1 2.2 |
|
| 137 |
1.1 2.2 3.3 4.4 5.5 |
|
| 182 |
1.1 2.2 |
|
| 183 |
1.1 2.2 |
|
| 229 |
1.1 2.2 3.3 4.4 5.5 |
|
| 284 |
1.1 2.2 |
|
| 285 |
1.1 2.2 |
|
| 340 |
1.1 2.2 3.3 4.4 5.5 |
|
| 346 |
1.1 2.2 |
|
| 347 |
1.1 2.2 |
|
| 348 |
1.1 2.2 3.3 |
|
| 349 |
1.1 2.2 |