Project

General

Profile

Download (2.07 KB) Statistics
| Branch: | Tag: | Revision:
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

    
25
	@SuppressWarnings("unused")
26
	private static final Logger logger = Logger.getLogger(ValidationDaemon.class);
27

    
28
	private final IEntityValidationService validationResultService;
29

    
30
	private boolean cancelRequested = false;
31

    
32

    
33

    
34
	public ValidationDaemon()
35
	{
36
		super("Running validation daemon");
37
		validationResultService = CdmStore.getService(IEntityValidationService.class);
38
	}
39

    
40

    
41
	@Override
42
	protected void canceling()
43
	{
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
	{
55
		cancelRequested = true;
56
	}
57

    
58

    
59
	@Override
60
	protected IStatus run(IProgressMonitor monitor)
61
	{
62
		MarkerManager markerManager;
63
		List<EntityValidation> results;
64
		try {
65
			while (!cancelRequested) {
66
				results = validationResultService.getValidationResults();
67
				markerManager = new MarkerManager(results);
68
				markerManager.deleteObsoleteMarkers();
69
				markerManager.createMarkers();
70
				// Might want to make this configurable:
71
				Thread.sleep(5000);
72
			}
73
			MessagingUtils.info("Validation module stopped");
74
			return Status.OK_STATUS;
75
		}
76
		catch (Throwable t) {
77
			MessagingUtils.info("Validation module terminated unexpectedly: " + t.getMessage());
78
			return Status.CANCEL_STATUS;
79
		}
80
	}
81

    
82
}
(3-3/3)