OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 83 | Rev 180 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 83 Rev 93
Line 20... Line 20...
20
import java.util.LinkedList;
20
import java.util.LinkedList;
21
import java.util.concurrent.locks.Condition;
21
import java.util.concurrent.locks.Condition;
22
import java.util.concurrent.locks.Lock;
22
import java.util.concurrent.locks.Lock;
23
import java.util.concurrent.locks.ReentrantLock;
23
import java.util.concurrent.locks.ReentrantLock;
24
 
24
 
-
 
25
import net.jcip.annotations.GuardedBy;
-
 
26
import net.jcip.annotations.ThreadSafe;
-
 
27
 
25
/**
28
/**
26
 * Holds items and give them one at a time to {@link #process(Object)}. At any time this process can
29
 * Holds items and give them one at a time to {@link #process(Object)}. At any time this process can
27
 * be put on hold by setting it to sleep.
30
 * be put on hold by setting it to sleep. All actions in a thread modifying ({@link #put(Object)},
-
 
31
 * {@link #itemsDo(IClosure)}) the queue happens-before the processing of this modification.
28
 * 
32
 * 
29
 * @author Sylvain
33
 * @author Sylvain
30
 * @param <T> type of item
34
 * @param <T> type of item
31
 */
35
 */
-
 
36
@ThreadSafe
32
public abstract class DropperQueue<T> extends Thread {
37
public abstract class DropperQueue<T> extends Thread {
33
 
38
 
-
 
39
    @GuardedBy("itemsLock")
34
    private final Deque<T> items;
40
    private final Deque<T> items;
35
    private final Lock itemsLock;
41
    private final Lock itemsLock;
36
    private final Condition notEmpty;
42
    private final Condition notEmpty;
-
 
43
    @GuardedBy("this")
37
    private boolean stop;
44
    private boolean stop;
-
 
45
    @GuardedBy("this")
38
    private boolean sleeping;
46
    private boolean sleeping;
-
 
47
    @GuardedBy("this")
39
    private boolean executing;
48
    private boolean executing;
40
 
49
 
41
    /**
50
    /**
42
     * Construct a new instance.
51
     * Construct a new instance.
43
     * 
52
     * 
Line 150... Line 159...
150
     * @return <code>true</code> if {@link #process(Object)} isn't executed and won't ever be again.
159
     * @return <code>true</code> if {@link #process(Object)} isn't executed and won't ever be again.
151
     * @see #isDying()
160
     * @see #isDying()
152
     */
161
     */
153
    public final boolean isDead() {
162
    public final boolean isDead() {
154
        // either we're dead because die() has been called, or because process() threw an Error
163
        // either we're dead because die() has been called, or because process() threw an Error
155
        return !this.isAlive();
164
        return this.getState().equals(State.TERMINATED);
156
    }
165
    }
157
 
166
 
158
    public synchronized final boolean dieCalled() {
167
    public synchronized final boolean dieCalled() {
159
        return this.stop;
168
        return this.stop;
160
    }
169
    }
Line 196... Line 205...
196
    abstract protected void process(final T item);
205
    abstract protected void process(final T item);
197
 
206
 
198
    // *** items
207
    // *** items
199
 
208
 
200
    /**
209
    /**
-
 
210
     * Adds an item to this queue. Actions in the thread prior to calling this method happen-before
201
     * Adds an item to this queue.
211
     * the passed argument is {@link #process(Object) processed}.
202
     * 
212
     * 
203
     * @param item the item to add.
213
     * @param item the item to add.
204
     */
214
     */
205
    public final void put(T item) {
215
    public final void put(T item) {
206
        this.itemsLock.lock();
216
        this.itemsLock.lock();