/** The number of reads so far */
private int fNbRead;
- private final CountDownLatch startedLatch = new CountDownLatch(1);
- private final CountDownLatch completedLatch = new CountDownLatch(1);
+ private final CountDownLatch fStartedLatch = new CountDownLatch(1);
+ private final CountDownLatch fCompletedLatch = new CountDownLatch(1);
- private boolean fRequestRunning;
- private boolean fRequestCompleted;
- private boolean fRequestFailed;
- private boolean fRequestCanceled;
+ private volatile boolean fRequestFailed = false;
+ private volatile boolean fRequestCanceled = false;
private ITmfFilter fEventFilter;
fNbRead = 0;
fDependencyLevel = dependencyLevel;
- fRequestRunning = false;
- fRequestCompleted = false;
- fRequestFailed = false;
- fRequestCanceled = false;
-
/* Setup the request tracing if it's enabled */
if (TmfCoreTracer.isRequestTraced()) {
String type = getClass().getName();
@Override
public synchronized boolean isRunning() {
- return fRequestRunning;
+ return (fStartedLatch.getCount() <= 0 && fCompletedLatch.getCount() > 0);
}
@Override
public synchronized boolean isCompleted() {
- return fRequestCompleted;
+ return (fCompletedLatch.getCount() <= 0);
}
@Override
* If the thread was interrupted while waiting
*/
public void waitForStart() throws InterruptedException {
- while (!fRequestRunning) {
- startedLatch.await();
- }
+ fStartedLatch.await();
}
@Override
public void waitForCompletion() throws InterruptedException {
- while (!fRequestCompleted) {
- completedLatch.await();
- }
+ fCompletedLatch.await();
}
@Override
- public void start() {
- synchronized (this) {
- fRequestRunning = true;
- }
+ public synchronized void start() {
handleStarted();
- startedLatch.countDown();
+ fStartedLatch.countDown();
}
@Override
- public void done() {
- synchronized (this) {
- if (!fRequestCompleted) {
- fRequestRunning = false;
- fRequestCompleted = true;
- } else {
- return;
- }
- }
- try {
- handleCompleted();
- } finally {
- completedLatch.countDown();
- }
+ public synchronized void done() {
+ handleCompleted();
+ fCompletedLatch.countDown();
}
/**
*/
@Override
public void fail(Exception e) {
- synchronized (this) {
- fRequestFailed = true;
- }
+ fRequestFailed = true;
fFailureCause = e;
done();
}
@Override
public void cancel() {
- synchronized (this) {
- fRequestCanceled = true;
- }
+ fRequestCanceled = true;
done();
}