2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.persistence
.validation
;
11 import javax
.validation
.ConstraintValidator
;
12 import javax
.validation
.Validator
;
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.
21 * @see {@link #isTerminationRequested()}.
23 * @author ayco holleman
26 public final class EntityValidationThread
extends Thread
{
28 private final Validator validator
;
30 private boolean terminationRequested
;
31 private EntityValidationTaskBase currentTask
;
34 EntityValidationThread(ThreadGroup group
, Runnable runnable
, String name
, Validator validator
)
36 super(group
, runnable
, name
);
37 this.validator
= validator
;
38 setPriority(MIN_PRIORITY
);
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>
47 * if(Thread.currentThread() instanceof ValidationThread) {
48 * ValidationThread vt = (ValidationThread) Thread.currentThread();
49 * if(vt.isTerminationRequested()) {
50 * // Stop with what I am doing
55 * @return Whether or not the currently running {@link ConstraintValidator} is
56 * requested to terminate itself
58 public boolean isTerminationRequested()
60 return terminationRequested
;
64 void setTerminationRequested(boolean b
)
66 this.terminationRequested
= b
;
70 Validator
getValidator()
76 EntityValidationTaskBase
getCurrentTask()
82 void setCurrentTask(EntityValidationTaskBase currentTask
)
84 this.currentTask
= currentTask
;