| 1 | package fr.sii.ogham.core.sender; | |
| 2 | ||
| 3 | import static fr.sii.ogham.core.retry.NamedCallable.named; | |
| 4 | ||
| 5 | import fr.sii.ogham.core.exception.MessageException; | |
| 6 | import fr.sii.ogham.core.exception.MessageNotSentException; | |
| 7 | import fr.sii.ogham.core.exception.retry.RetryException; | |
| 8 | import fr.sii.ogham.core.exception.retry.RetryExecutionInterruptedException; | |
| 9 | import fr.sii.ogham.core.message.Message; | |
| 10 | import fr.sii.ogham.core.retry.RetryExecutor; | |
| 11 | import fr.sii.ogham.core.retry.RetryStrategy; | |
| 12 | ||
| 13 | /** | |
| 14 | * If a message couldn't be sent, the message may be sent again several times | |
| 15 | * until it succeeds or maximum attempts are reached. | |
| 16 | * | |
| 17 | * <p> | |
| 18 | * The retry management is delegated to a {@link RetryExecutor}. | |
| 19 | * | |
| 20 | * @author Aurélien Baudet | |
| 21 | * @see RetryExecutor | |
| 22 | * @see RetryStrategy | |
| 23 | */ | |
| 24 | public class AutoRetrySender implements ConditionalSender { | |
| 25 | private final MessageSender delegate; | |
| 26 | private final RetryExecutor retry; | |
| 27 | ||
| 28 | /** | |
| 29 | * Initializes with the wrapped sender that will really send the message and | |
| 30 | * the {@link RetryExecutor} used to execute the action several times if | |
| 31 | * needed. | |
| 32 | * | |
| 33 | * @param delegate | |
| 34 | * the sender that really sends the messages | |
| 35 | * @param retry | |
| 36 | * the retry manager | |
| 37 | */ | |
| 38 | public AutoRetrySender(MessageSender delegate, RetryExecutor retry) { | |
| 39 | super(); | |
| 40 | this.delegate = delegate; | |
| 41 | this.retry = retry; | |
| 42 | } | |
| 43 | ||
| 44 | @Override | |
| 45 | public void send(Message message) throws MessageException { | |
| 46 | try { | |
| 47 |
4
1. lambda$send$0 : removed call to fr/sii/ogham/core/sender/MessageSender::send → NO_COVERAGE 2. lambda$send$0 : removed call to fr/sii/ogham/core/sender/MessageSender::send → KILLED 3. lambda$send$0 : removed call to fr/sii/ogham/core/sender/MessageSender::send → KILLED 4. lambda$send$0 : removed call to fr/sii/ogham/core/sender/MessageSender::send → KILLED |
retry.execute(named("Send message", () -> delegate.send(message))); |
| 48 | } catch (RetryExecutionInterruptedException e) { | |
| 49 |
1
1. send : removed call to java/lang/Thread::interrupt → NO_COVERAGE |
Thread.currentThread().interrupt(); |
| 50 | throw new MessageNotSentException("Failed to send message (interrupted)", message, e); | |
| 51 | } catch (RetryException e) { | |
| 52 | throw new MessageNotSentException("Failed to send message", message, e); | |
| 53 | } | |
| 54 | } | |
| 55 | ||
| 56 | @Override | |
| 57 | public boolean supports(Message message) { | |
| 58 |
4
1. supports : negated conditional → SURVIVED 2. supports : negated conditional → NO_COVERAGE 3. supports : negated conditional → KILLED 4. supports : negated conditional → KILLED |
if (delegate instanceof ConditionalSender) { |
| 59 |
8
1. supports : replaced boolean return with false for fr/sii/ogham/core/sender/AutoRetrySender::supports → NO_COVERAGE 2. supports : replaced boolean return with true for fr/sii/ogham/core/sender/AutoRetrySender::supports → NO_COVERAGE 3. supports : replaced boolean return with true for fr/sii/ogham/core/sender/AutoRetrySender::supports → SURVIVED 4. supports : replaced boolean return with false for fr/sii/ogham/core/sender/AutoRetrySender::supports → KILLED 5. supports : replaced boolean return with false for fr/sii/ogham/core/sender/AutoRetrySender::supports → KILLED 6. supports : replaced boolean return with false for fr/sii/ogham/core/sender/AutoRetrySender::supports → KILLED 7. supports : replaced boolean return with true for fr/sii/ogham/core/sender/AutoRetrySender::supports → KILLED 8. supports : replaced boolean return with true for fr/sii/ogham/core/sender/AutoRetrySender::supports → KILLED |
return ((ConditionalSender) delegate).supports(message); |
| 60 | } | |
| 61 |
1
1. supports : replaced boolean return with false for fr/sii/ogham/core/sender/AutoRetrySender::supports → NO_COVERAGE |
return true; |
| 62 | } | |
| 63 | ||
| 64 | @Override | |
| 65 | public String toString() { | |
| 66 | StringBuilder builder = new StringBuilder(); | |
| 67 | builder.append("AutoRetrySender [executor=").append(retry).append(", delegate=").append(delegate).append("]"); | |
| 68 |
2
1. toString : replaced return value with "" for fr/sii/ogham/core/sender/AutoRetrySender::toString → SURVIVED 2. toString : replaced return value with "" for fr/sii/ogham/core/sender/AutoRetrySender::toString → NO_COVERAGE |
return builder.toString(); |
| 69 | } | |
| 70 | } | |
Mutations | ||
| 47 |
1.1 2.2 3.3 4.4 |
|
| 49 |
1.1 |
|
| 58 |
1.1 2.2 3.3 4.4 |
|
| 59 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 61 |
1.1 |
|
| 68 |
1.1 2.2 |