Clover Coverage Report
Coverage timestamp: Fri Feb 14 2014 07:28:57 UTC
../../../../../img/srcFileCovDistChart5.png 86% of files have more coverage
78   310   49   2
20   199   0.63   39
39     1.26  
1    
 
  InternalModuleServiceCallImpl       Line # 33 78 49 42.3% 0.42335767
 
  (108)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.bo.job;
17   
18    import org.qedeq.base.io.Parameters;
19    import org.qedeq.kernel.bo.common.ModuleServiceCall;
20    import org.qedeq.kernel.bo.common.ModuleServiceResult;
21    import org.qedeq.kernel.bo.common.QedeqBo;
22    import org.qedeq.kernel.bo.common.ServiceJob;
23    import org.qedeq.kernel.bo.module.InternalModuleServiceCall;
24    import org.qedeq.kernel.bo.module.InternalServiceJob;
25    import org.qedeq.kernel.se.common.Service;
26    import org.qedeq.kernel.se.common.ServiceCompleteness;
27   
28    /**
29    * Single call for a service.
30    *
31    * @author Michael Meyling
32    */
 
33    public class InternalModuleServiceCallImpl implements InternalModuleServiceCall {
34   
35    /** Counter for each service call. */
36    private static volatile long globalCounter;
37   
38    /** The service the thread works for. */
39    private final Service service;
40   
41    /** QEDEQ module the process is working on. */
42    private final QedeqBo qedeq;
43   
44    /** Current global config parameters for the service. */
45    private final Parameters config;
46   
47    /** Call specific parameters for this service call. */
48    private final Parameters parameters;
49   
50    /** Begin time for service call. */
51    private long begin;
52   
53    /** End time for service call. */
54    private long end;
55   
56    /** Last time we started. */
57    private long start;
58   
59    /** Call duration time without being blocked. */
60    private long duration;
61   
62    /** Is this process paused? */
63    private boolean paused;
64   
65    /** Is this process running (even if its paused)? */
66    private boolean running;
67   
68    /** Percentage of currently running service execution. */
69    private double executionPercentage;
70   
71    /** Currently taken action. */
72    private String action = "not yet started";
73   
74    /** Service process. */
75    private final InternalServiceJob process;
76   
77    /** Parent service call. Might be <code>null</code>. */
78    private final ModuleServiceCall parent;
79   
80    /** Call id. */
81    private final long id;
82   
83    /** Result of service call. */
84    private ModuleServiceResult result;
85   
86    /** Was the module newly blocked by this call. Otherwise a previous service call might have locked the module
87    * for the process already. */
88    private boolean newlyBlockedModule;
89   
90    /** Answers completeness questions if not <code>null</code>. */
91    private ServiceCompleteness completeness;
92   
93    /**
94    * A new service process within the current thread.
95    *
96    * @param service This service is executed.
97    * @param qedeq Module we work on.
98    * @param config Current global config parameters for this call.
99    * @param parameters Call specific parameters..
100    * @param process Service process we run within.
101    * @param parent Parent service call if any.
102    */
 
103  1891 toggle public InternalModuleServiceCallImpl(final Service service, final QedeqBo qedeq,
104    final Parameters config, final Parameters parameters, final InternalServiceJob process,
105    final ModuleServiceCall parent) {
106  1891 this.id = inc();
107  1891 this.qedeq = qedeq;
108  1891 this.service = service;
109  1891 this.config = config;
110  1891 this.parameters = parameters;
111  1891 this.process = process;
112  1891 this.parent = parent;
113  1891 running = false;
114  1891 begin();
115    }
116   
 
117  1891 toggle private synchronized long inc() {
118  1891 return globalCounter++;
119    }
120   
 
121  1696 toggle public Service getService() {
122  1696 return service;
123    }
124   
 
125  2788 toggle public QedeqBo getQedeq() {
126  2788 return qedeq;
127    }
128   
 
129  0 toggle public synchronized Parameters getConfigParameters() {
130  0 return config;
131    }
132   
 
133  0 toggle public String getConfigParametersString() {
134  0 return config.getParameterString();
135    }
136   
 
137  0 toggle public synchronized Parameters getParameters() {
138  0 return parameters;
139    }
140   
 
141  0 toggle public String getParametersString() {
142  0 return parameters.getParameterString();
143    }
144   
 
145  0 toggle public long getBeginTime() {
146  0 return begin;
147    }
148   
 
149  0 toggle public synchronized long getEndTime() {
150  0 return end;
151    }
152   
 
153  0 toggle public synchronized long getDuration() {
154  0 return duration;
155    }
156   
 
157  1891 toggle private synchronized void begin() {
158  1891 begin = System.currentTimeMillis();
159  1891 start = begin;
160  1891 action = "started";
161  1891 running = true;
162    }
163   
 
164  0 toggle public synchronized boolean isPaused() {
165  0 return paused;
166    }
167   
 
168  1589 toggle public synchronized void pause() {
169  1589 duration += System.currentTimeMillis() - start;
170  1589 paused = true;
171    }
172   
 
173  1589 toggle public synchronized void resume() {
174  1589 paused = false;
175  1589 start = System.currentTimeMillis();
176    }
177   
 
178  1589 toggle private synchronized void end() {
179  1589 end = System.currentTimeMillis();
180  1589 duration += end - start;
181  1589 paused = false;
182  1589 running = false;
183    }
184   
 
185  1589 toggle public void setNewlyBlockedModule(final boolean newlyBlockedModule) {
186  1589 this.newlyBlockedModule = newlyBlockedModule;
187    }
188   
 
189  1741 toggle public boolean getNewlyBlockedModule() {
190  1741 return this.newlyBlockedModule;
191    }
192   
 
193  1566 toggle public synchronized void finishOk() {
194  1566 finish(ServiceResultImpl.SUCCESSFUL);
195    }
196   
 
197  23 toggle public synchronized void finishError(final String errorMessage) {
198  23 finish(new ServiceResultImpl(errorMessage));
199    }
200   
 
201  1589 toggle public synchronized void finish(final ModuleServiceResult result) {
202  1589 if (running) {
203  1589 action = "finished";
204  1589 executionPercentage = 100;
205  1589 completeness = null;
206  1589 this.result = result;
207  1589 end();
208    }
209    }
210   
 
211  0 toggle public synchronized void halt(final ModuleServiceResult result) {
212  0 if (running) {
213  0 this.result = result;
214  0 if (completeness != null) {
215  0 executionPercentage = completeness.getVisitPercentage();
216    } else {
217  0 completeness = null;
218    }
219  0 end();
220    }
221    }
222   
 
223  0 toggle public synchronized void halt(final String errorMessage) {
224  0 halt(new ServiceResultImpl(errorMessage));
225    }
226   
 
227  0 toggle public synchronized void interrupt() {
228  0 if (running) {
229  0 this.result = ServiceResultImpl.INTERRUPTED;
230  0 if (completeness != null) {
231  0 executionPercentage = completeness.getVisitPercentage();
232    } else {
233  0 completeness = null;
234    }
235  0 process.setInterruptedState();
236  0 end();
237    }
238    }
239   
 
240  0 toggle public synchronized boolean isRunning() {
241  0 return running;
242    }
243   
 
244  0 toggle public synchronized ServiceJob getServiceProcess() {
245  0 return process;
246    }
247   
 
248  0 toggle public synchronized double getExecutionPercentage() {
249  0 if (completeness != null) {
250  0 executionPercentage = completeness.getVisitPercentage();
251    }
252  0 return executionPercentage;
253    }
254   
 
255  0 toggle public synchronized void setExecutionPercentage(final double percentage) {
256  0 this.executionPercentage = percentage;
257    }
258   
 
259  0 toggle public synchronized String getAction() {
260  0 return action;
261    }
262   
 
263  0 toggle public synchronized String getLocation() {
264  0 if (completeness != null) {
265  0 return completeness.getLocationDescription();
266    }
267  0 return action;
268    }
269   
 
270  457 toggle public synchronized void setAction(final String action) {
271  457 this.action = action;
272    }
273   
 
274  0 toggle public long getId() {
275  0 return id;
276    }
277   
 
278  0 toggle public int hashCode() {
279  0 return (int) id;
280    }
281   
 
282  0 toggle public boolean equals(final Object obj) {
283  0 return 0 == compareTo(obj);
284    }
285   
 
286  0 toggle public int compareTo(final Object o) {
287  0 if (!(o instanceof ModuleServiceCall)) {
288  0 return -1;
289    }
290  0 final ModuleServiceCall s = (ModuleServiceCall) o;
291  0 return (getId() < s.getId() ? -1 : (getId() == s.getId() ? 0 : 1));
292    }
293   
 
294  1126 toggle public ModuleServiceCall getParentServiceCall() {
295  1126 return parent;
296    }
297   
 
298  463 toggle public synchronized ModuleServiceResult getServiceResult() {
299  463 return result;
300    }
301   
 
302  8691 toggle public InternalServiceJob getInternalServiceProcess() {
303  8691 return process;
304    }
305   
 
306  1126 toggle public synchronized void setServiceCompleteness(final ServiceCompleteness completeness) {
307  1126 this.completeness = completeness;
308    }
309   
310    }