1 package eu
.etaxonomy
.taxeditor
.editor
.validation
;
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
;
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
;
17 * A job that repeatedly checks the error tables and refreshes the problem
18 * markers created from them.
20 * @author ayco_holleman
23 public class ValidationDaemon
extends Job
{
24 @SuppressWarnings("unused")
25 private static final Logger logger
= Logger
.getLogger(ValidationDaemon
.class);
27 private final IEntityValidationService entityValidationService
;
29 // Might want to make this configurable:
30 private int SLEEP_TIME
= 5000;
32 private boolean cancelRequested
= false;
36 public ValidationDaemon(){
37 super("Running validation daemon");
38 entityValidationService
= CdmStore
.getService(IEntityValidationService
.class);
43 protected void canceling(){
44 cancelRequested
= true;
49 * This method is called by {@link ValidationContextListener} rather than
50 * {@link Job#cancel()}, because that method does not have the desired
53 public void setCancelRequested(){
54 cancelRequested
= true;
59 protected IStatus
run(IProgressMonitor monitor
){
60 MarkerManager markerManager
;
61 List
<EntityValidation
> results
;
63 while (!cancelRequested
) {
64 results
= entityValidationService
.getValidationResults();
65 markerManager
= new MarkerManager(results
);
66 markerManager
.deleteObsoleteMarkers();
67 markerManager
.createMarkers();
68 Thread
.sleep(SLEEP_TIME
);
70 MessagingUtils
.info("Validation module stopped");
71 return Status
.OK_STATUS
;
74 MessagingUtils
.info("Validation module terminated unexpectedly: " + t
.getMessage());
75 return Status
.CANCEL_STATUS
;