1 | package fr.sii.ogham.sms.sender.impl.cloudhopper.session; | |
2 | ||
3 | import java.nio.channels.ClosedChannelException; | |
4 | ||
5 | import com.cloudhopper.smpp.pdu.EnquireLink; | |
6 | import com.cloudhopper.smpp.type.SmppChannelException; | |
7 | import com.cloudhopper.smpp.type.SmppTimeoutException; | |
8 | import com.cloudhopper.smpp.type.UnrecoverablePduException; | |
9 | ||
10 | import fr.sii.ogham.sms.sender.impl.cloudhopper.exception.KeepAliveException; | |
11 | import fr.sii.ogham.sms.sender.impl.cloudhopper.exception.SmppException; | |
12 | ||
13 | /** | |
14 | * Default error analyzer that indicates to use a new session in the following | |
15 | * cases: | |
16 | * <ul> | |
17 | * <li>{@link KeepSessionAliveStrategy} is used for session handling and several | |
18 | * (configurable) {@link EnquireLink} requests have failed due to a timeout</li> | |
19 | * <li>The connection has been closed by the server</li> | |
20 | * <li>The error is unrecoverable (see {@link UnrecoverablePduException}</li> | |
21 | * </ul> | |
22 | * | |
23 | * <p> | |
24 | * This class can be extended if additional checks are needed. | |
25 | * | |
26 | * @author Aurélien Baudet | |
27 | * | |
28 | */ | |
29 | public class DefaultErrorAnalyzer implements ErrorAnalyzer { | |
30 | private final int maxConsecutiveTimeouts; | |
31 | ||
32 | public DefaultErrorAnalyzer(int maxConsecutiveTimeouts) { | |
33 | super(); | |
34 | this.maxConsecutiveTimeouts = maxConsecutiveTimeouts; | |
35 | } | |
36 | ||
37 | @Override | |
38 | public boolean requiresNewConnection(Throwable failure) { | |
39 |
2
1. requiresNewConnection : negated conditional → NO_COVERAGE 2. requiresNewConnection : negated conditional → KILLED |
if (failure == null) { |
40 |
1
1. requiresNewConnection : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::requiresNewConnection → NO_COVERAGE |
return false; |
41 | } | |
42 |
2
1. requiresNewConnection : negated conditional → NO_COVERAGE 2. requiresNewConnection : negated conditional → SURVIVED |
if (tooManyEnquireLinkTimeouts(failure)) { |
43 |
2
1. requiresNewConnection : replaced boolean return with false for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::requiresNewConnection → NO_COVERAGE 2. requiresNewConnection : replaced boolean return with false for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::requiresNewConnection → TIMED_OUT |
return true; |
44 | } | |
45 |
2
1. requiresNewConnection : negated conditional → NO_COVERAGE 2. requiresNewConnection : negated conditional → KILLED |
if (failure instanceof SmppException) { |
46 |
4
1. requiresNewConnection : replaced boolean return with false for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::requiresNewConnection → NO_COVERAGE 2. requiresNewConnection : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::requiresNewConnection → NO_COVERAGE 3. requiresNewConnection : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::requiresNewConnection → SURVIVED 4. requiresNewConnection : replaced boolean return with false for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::requiresNewConnection → KILLED |
return requiresNewConnection(failure.getCause()); |
47 | } | |
48 |
5
1. requiresNewConnection : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::requiresNewConnection → NO_COVERAGE 2. requiresNewConnection : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::requiresNewConnection → SURVIVED 3. requiresNewConnection : negated conditional → NO_COVERAGE 4. requiresNewConnection : negated conditional → NO_COVERAGE 5. requiresNewConnection : negated conditional → KILLED |
return connectionClosed(failure) || isUnrecoverableError(failure); |
49 | } | |
50 | ||
51 | protected boolean tooManyEnquireLinkTimeouts(Throwable failure) { | |
52 |
4
1. tooManyEnquireLinkTimeouts : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::tooManyEnquireLinkTimeouts → SURVIVED 2. tooManyEnquireLinkTimeouts : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::tooManyEnquireLinkTimeouts → NO_COVERAGE 3. tooManyEnquireLinkTimeouts : negated conditional → NO_COVERAGE 4. tooManyEnquireLinkTimeouts : negated conditional → TIMED_OUT |
return failure instanceof KeepAliveException |
53 |
2
1. tooManyEnquireLinkTimeouts : negated conditional → NO_COVERAGE 2. tooManyEnquireLinkTimeouts : negated conditional → TIMED_OUT |
&& failure.getCause() instanceof SmppTimeoutException |
54 |
4
1. tooManyEnquireLinkTimeouts : changed conditional boundary → NO_COVERAGE 2. tooManyEnquireLinkTimeouts : negated conditional → NO_COVERAGE 3. tooManyEnquireLinkTimeouts : negated conditional → TIMED_OUT 4. tooManyEnquireLinkTimeouts : changed conditional boundary → KILLED |
&& ((KeepAliveException) failure).getConsecutiveFailures() >= maxConsecutiveTimeouts; |
55 | } | |
56 | ||
57 | protected boolean connectionClosed(Throwable failure) { | |
58 |
6
1. connectionClosed : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::connectionClosed → SURVIVED 2. connectionClosed : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::connectionClosed → NO_COVERAGE 3. connectionClosed : negated conditional → NO_COVERAGE 4. connectionClosed : negated conditional → SURVIVED 5. connectionClosed : negated conditional → NO_COVERAGE 6. connectionClosed : negated conditional → KILLED |
return failure instanceof ClosedChannelException || failure instanceof SmppChannelException; |
59 | } | |
60 | ||
61 | protected boolean isUnrecoverableError(Throwable failure) { | |
62 |
2
1. isUnrecoverableError : replaced boolean return with false for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::isUnrecoverableError → NO_COVERAGE 2. isUnrecoverableError : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/session/DefaultErrorAnalyzer::isUnrecoverableError → NO_COVERAGE |
return failure instanceof UnrecoverablePduException; |
63 | } | |
64 | } | |
Mutations | ||
39 |
1.1 2.2 |
|
40 |
1.1 |
|
42 |
1.1 2.2 |
|
43 |
1.1 2.2 |
|
45 |
1.1 2.2 |
|
46 |
1.1 2.2 3.3 4.4 |
|
48 |
1.1 2.2 3.3 4.4 5.5 |
|
52 |
1.1 2.2 3.3 4.4 |
|
53 |
1.1 2.2 |
|
54 |
1.1 2.2 3.3 4.4 |
|
58 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
62 |
1.1 2.2 |