minor renaming
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / validation / ValidationDaemon.java
1 package eu.etaxonomy.taxeditor.editor.validation;
2
3 import java.util.List;
4
5 import org.apache.log4j.Logger;
6 import org.eclipse.core.runtime.IProgressMonitor;
7 import org.eclipse.core.runtime.IStatus;
8 import org.eclipse.core.runtime.Status;
9 import org.eclipse.core.runtime.jobs.Job;
10
11 import eu.etaxonomy.cdm.api.service.IEntityValidationService;
12 import eu.etaxonomy.cdm.model.validation.EntityValidation;
13 import eu.etaxonomy.taxeditor.model.MessagingUtils;
14 import eu.etaxonomy.taxeditor.store.CdmStore;
15
16 /**
17 * A job that repeatedly checks the error tables and refreshes the problem
18 * markers created from them.
19 *
20 * @author ayco_holleman
21 *
22 */
23 public class ValidationDaemon extends Job {
24 @SuppressWarnings("unused")
25 private static final Logger logger = Logger.getLogger(ValidationDaemon.class);
26
27 private final IEntityValidationService entityValidationService;
28
29 // Might want to make this configurable:
30 private int SLEEP_TIME = 5000;
31
32 private boolean cancelRequested = false;
33
34
35
36 public ValidationDaemon(){
37 super("Running validation daemon");
38 entityValidationService = CdmStore.getService(IEntityValidationService.class);
39 }
40
41
42 @Override
43 protected void canceling(){
44 cancelRequested = true;
45 }
46
47
48 /**
49 * This method is called by {@link ValidationContextListener} rather than
50 * {@link Job#cancel()}, because that method does not have the desired
51 * effect.
52 */
53 public void setCancelRequested(){
54 cancelRequested = true;
55 }
56
57
58 @Override
59 protected IStatus run(IProgressMonitor monitor){
60 MarkerManager markerManager;
61 List<EntityValidation> results;
62 try {
63 while (!cancelRequested) {
64 results = entityValidationService.getValidationResults();
65 markerManager = new MarkerManager(results);
66 markerManager.deleteObsoleteMarkers();
67 markerManager.createMarkers();
68 Thread.sleep(SLEEP_TIME);
69 }
70 MessagingUtils.info("Validation module stopped");
71 return Status.OK_STATUS;
72 }
73 catch (Throwable t) {
74 MessagingUtils.info("Validation module terminated unexpectedly: " + t.getMessage());
75 return Status.CANCEL_STATUS;
76 }
77 }
78
79 }