1 | package com.jsql.model.suspendable; | |
2 | ||
3 | import com.jsql.model.InjectionModel; | |
4 | import com.jsql.model.exception.JSqlException; | |
5 | import com.jsql.util.LogLevelUtil; | |
6 | import org.apache.logging.log4j.LogManager; | |
7 | import org.apache.logging.log4j.Logger; | |
8 | ||
9 | /** | |
10 | * A thread used to inject database ; stoppable and pausable. | |
11 | */ | |
12 | public abstract class AbstractSuspendable { | |
13 | | |
14 | /** | |
15 | * Log4j logger sent to view. | |
16 | */ | |
17 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
18 | ||
19 | /** | |
20 | * Make the action to stop if true. | |
21 | */ | |
22 | private boolean isStopped = false; | |
23 | | |
24 | /** | |
25 | * Make the action to pause if true, else make it unpause. | |
26 | */ | |
27 | private boolean isPaused = false; | |
28 | ||
29 | protected final InjectionModel injectionModel; | |
30 | | |
31 | protected AbstractSuspendable(InjectionModel injectionModel) { | |
32 | this.injectionModel = injectionModel; | |
33 | } | |
34 | | |
35 | /** | |
36 | * The pausable/stoppable action. | |
37 | * @param args | |
38 | * @return | |
39 | * @throws JSqlException | |
40 | */ | |
41 | public abstract String run(Object... args) throws JSqlException; | |
42 | ||
43 | /** | |
44 | * Thread's states Pause and Stop are processed by this method.<br> | |
45 | * - Pause action in infinite loop if invoked while shouldPauseThread is set to true,<br> | |
46 | * - Return stop state. | |
47 | * @return Stop state | |
48 | */ | |
49 | public synchronized boolean isSuspended() { | |
50 | | |
51 | // Make application loop until shouldPauseThread is set to false by another user action | |
52 |
1
1. isSuspended : negated conditional → NO_COVERAGE |
while (this.isPaused) { |
53 | try { | |
54 |
1
1. isSuspended : removed call to java/lang/Object::wait → NO_COVERAGE |
this.wait(); |
55 | } catch (InterruptedException e) { | |
56 | | |
57 | LOGGER.log(LogLevelUtil.IGNORE, e, e); | |
58 |
1
1. isSuspended : removed call to java/lang/Thread::interrupt → NO_COVERAGE |
Thread.currentThread().interrupt(); |
59 | } | |
60 | } | |
61 | ||
62 |
3
1. isSuspended : negated conditional → NO_COVERAGE 2. isSuspended : replaced boolean return with true for com/jsql/model/suspendable/AbstractSuspendable::isSuspended → NO_COVERAGE 3. isSuspended : negated conditional → NO_COVERAGE |
return this.isStopped || this.injectionModel.isStoppedByUser(); // Return true if stop requested, else return false |
63 | } | |
64 | | |
65 | /** | |
66 | * Mark as stopped. | |
67 | */ | |
68 | public void stop() { | |
69 | ||
70 |
1
1. stop : removed call to com/jsql/model/suspendable/AbstractSuspendable::unpause → NO_COVERAGE |
this.unpause(); |
71 | this.isStopped = true; | |
72 | } | |
73 | | |
74 | /** | |
75 | * Mark as paused. | |
76 | */ | |
77 | public void pause() { | |
78 | this.isPaused = true; | |
79 | } | |
80 | | |
81 | /** | |
82 | * Mark as unpaused. | |
83 | */ | |
84 | public void unpause() { | |
85 | | |
86 | this.isPaused = false; | |
87 |
1
1. unpause : removed call to com/jsql/model/suspendable/AbstractSuspendable::resume → NO_COVERAGE |
this.resume(); // Restart the action after unpause |
88 | } | |
89 | | |
90 | /** | |
91 | * Return true if thread is paused, false otherwise. | |
92 | * @return Pause state | |
93 | */ | |
94 | public boolean isPaused() { | |
95 |
2
1. isPaused : replaced boolean return with false for com/jsql/model/suspendable/AbstractSuspendable::isPaused → NO_COVERAGE 2. isPaused : replaced boolean return with true for com/jsql/model/suspendable/AbstractSuspendable::isPaused → NO_COVERAGE |
return this.isPaused; |
96 | } | |
97 | | |
98 | /** | |
99 | * Wake threads. | |
100 | */ | |
101 | public synchronized void resume() { | |
102 |
1
1. resume : removed call to java/lang/Object::notifyAll → NO_COVERAGE |
this.notifyAll(); |
103 | } | |
104 | } | |
Mutations | ||
52 |
1.1 |
|
54 |
1.1 |
|
58 |
1.1 |
|
62 |
1.1 2.2 3.3 |
|
70 |
1.1 |
|
87 |
1.1 |
|
95 |
1.1 2.2 |
|
102 |
1.1 |