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