rename abstract class
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / persistence / validation / EntityValidationThread.java
1 /**
2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.persistence.validation;
10
11 import javax.validation.ConstraintValidator;
12 import javax.validation.Validator;
13
14 /**
15 * A subclass of {@code Thread} specialized in running validation tasks. Each
16 * {@code ValidationThread} has its own {@link Validator} instance. In addition it allows
17 * a flag to be set (by the main thread) that the currently running
18 * {@link ConstraintValidator} may query to see if there is a termination request. See
19 * {@link ValidationExecutor} for the rationale behind this.
20 *
21 * @see {@link #isTerminationRequested()}.
22 *
23 * @author ayco holleman
24 *
25 */
26 public final class EntityValidationThread extends Thread {
27
28 private final Validator validator;
29
30 private boolean terminationRequested;
31 private EntityValidationTaskBase currentTask;
32
33
34 EntityValidationThread(ThreadGroup group, Runnable runnable, String name, Validator validator)
35 {
36 super(group, runnable, name);
37 this.validator = validator;
38 setPriority(MIN_PRIORITY);
39 }
40
41
42 /**
43 * Flag indicating that the {@link ConstraintValidator} currently running in this
44 * {@code ValidationThread} is requested to terminate itself. Constraint validators
45 * can check whether to abort the validation like so:<br>
46 * <code>
47 * if(Thread.currentThread() instanceof ValidationThread) {
48 * ValidationThread vt = (ValidationThread) Thread.currentThread();
49 * if(vt.isTerminationRequested()) {
50 * // Stop with what I am doing
51 * }
52 * }
53 * </code>
54 *
55 * @return Whether or not the currently running {@link ConstraintValidator} is
56 * requested to terminate itself
57 */
58 public boolean isTerminationRequested()
59 {
60 return terminationRequested;
61 }
62
63
64 void setTerminationRequested(boolean b)
65 {
66 this.terminationRequested = b;
67 }
68
69
70 Validator getValidator()
71 {
72 return validator;
73 }
74
75
76 EntityValidationTaskBase getCurrentTask()
77 {
78 return currentTask;
79 }
80
81
82 void setCurrentTask(EntityValidationTaskBase currentTask)
83 {
84 this.currentTask = currentTask;
85 }
86
87 }