*/
private static final Condition doneCondition = stateLock.newCondition();
+ /**
+ * Condition lock used to notify waiters when state is consistent (not PREPARE_*).
+ */
+ private static final Condition preparedCondition = stateLock.newCondition();
+
public static DAState getCurrentState() {
return currentState;
}
case DONE:
currentState = state;
doneCondition.signalAll();
+ preparedCondition.signalAll();
ret = true;
break;
case RUNNING:
if (currentState == PREPARE_START) {
currentState = state;
+ preparedCondition.signalAll();
ret = true;
}
break;
}
}
+ /**
+ * Blocks caller thread until DA state doesn't become consistent.
+ *
+ * @throws InterruptedException if waiting was interrupted
+ */
+ public static void waitPrepared() throws InterruptedException {
+ stateLock.lock();
+ try {
+ while (!isRunning() && !isStartable()) {
+ preparedCondition.await();
+ }
+ } finally {
+ stateLock.unlock();
+ }
+ }
+
public static boolean isRunning() {
return (currentState == RUNNING);
}