1 | package fr.sii.ogham.sms.sender.impl.cloudhopper.session; | |
2 | ||
3 | import org.slf4j.Logger; | |
4 | import org.slf4j.LoggerFactory; | |
5 | ||
6 | import com.cloudhopper.smpp.SmppSession; | |
7 | import com.cloudhopper.smpp.pdu.EnquireLink; | |
8 | import com.cloudhopper.smpp.type.RecoverablePduException; | |
9 | import com.cloudhopper.smpp.type.SmppChannelException; | |
10 | import com.cloudhopper.smpp.type.SmppTimeoutException; | |
11 | import com.cloudhopper.smpp.type.UnrecoverablePduException; | |
12 | ||
13 | import fr.sii.ogham.sms.sender.impl.cloudhopper.exception.KeepAliveException; | |
14 | ||
15 | /** | |
16 | * Task that regularly sends {@link EnquireLink} requests to keep the current | |
17 | * session alive. | |
18 | * | |
19 | * <p> | |
20 | * Sending the {@link EnquireLink} may fail in several situations such as: | |
21 | * <ul> | |
22 | * <li>No response is received before the configured timeout is expired</li> | |
23 | * <li>The {@link EnquireLink} is received but the server indicates that there | |
24 | * is an issue with the sent PDU</li> | |
25 | * <li>The session is closed by the server</li> | |
26 | * <li>The server is not reachable</li> | |
27 | * <li>... | |
28 | * <li> | |
29 | * </ul> | |
30 | * | |
31 | * In any case, the error is not treated here but delegated to an | |
32 | * {@link ErrorHandler}. The {@link ErrorHandler} may either skip, log or | |
33 | * properly handle the error. | |
34 | * | |
35 | * @author Aurélien Baudet | |
36 | * @see ErrorHandler | |
37 | * @see KeepSessionAliveStrategy | |
38 | */ | |
39 | public class EnquireLinkTask implements Runnable { | |
40 | private static final Logger LOG = LoggerFactory.getLogger(EnquireLinkTask.class); | |
41 | ||
42 | private final SmppSession session; | |
43 | private final ErrorHandler errorHandler; | |
44 | private final long enquireLinkRequestTimeout; | |
45 | private int consecutiveFailures; | |
46 | ||
47 | public EnquireLinkTask(SmppSession session, ErrorHandler errorHandler, long enquireLinkRequestTimeout) { | |
48 | super(); | |
49 | this.session = session; | |
50 | this.errorHandler = errorHandler; | |
51 | this.enquireLinkRequestTimeout = enquireLinkRequestTimeout; | |
52 | } | |
53 | ||
54 | @Override | |
55 | public void run() { | |
56 |
6
1. run : negated conditional → NO_COVERAGE 2. run : negated conditional → NO_COVERAGE 3. run : negated conditional → NO_COVERAGE 4. run : negated conditional → TIMED_OUT 5. run : negated conditional → TIMED_OUT 6. run : negated conditional → TIMED_OUT |
if (session == null || !session.isBound() || session.isClosed()) { |
57 | return; | |
58 | } | |
59 | try { | |
60 | LOG.debug("Sending EnquireLink to keep session alive..."); | |
61 | session.enquireLink(new EnquireLink(), enquireLinkRequestTimeout); | |
62 | LOG.debug("EnquireLink to keep session alive sent"); | |
63 | consecutiveFailures = 0; | |
64 | } catch (RecoverablePduException | UnrecoverablePduException | SmppTimeoutException | SmppChannelException e) { | |
65 | LOG.debug("Failed to send EnquireLink", e); | |
66 |
2
1. run : Replaced integer addition with subtraction → NO_COVERAGE 2. run : Replaced integer addition with subtraction → TIMED_OUT |
consecutiveFailures++; |
67 |
2
1. run : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/ErrorHandler::handleFailure → NO_COVERAGE 2. run : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/ErrorHandler::handleFailure → TIMED_OUT |
errorHandler.handleFailure(new KeepAliveException("Failed to keep session alive", e, consecutiveFailures)); |
68 | } catch (InterruptedException e) { | |
69 | LOG.debug("Failed to send EnquireLink (interrupted)", e); | |
70 |
1
1. run : removed call to java/lang/Thread::interrupt → NO_COVERAGE |
Thread.currentThread().interrupt(); |
71 |
1
1. run : Replaced integer addition with subtraction → NO_COVERAGE |
consecutiveFailures++; |
72 |
1
1. run : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/ErrorHandler::handleFailure → NO_COVERAGE |
errorHandler.handleFailure(new KeepAliveException("Failed to keep session alive", e, consecutiveFailures)); |
73 | } | |
74 | } | |
75 | ||
76 | } | |
Mutations | ||
56 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
66 |
1.1 2.2 |
|
67 |
1.1 2.2 |
|
70 |
1.1 |
|
71 |
1.1 |
|
72 |
1.1 |