public static byte[] waitForProcedureToComplete(
    final ProcedureExecutor<MasterProcedureEnv> procExec, final Procedure<?> proc,
    final long timeout) throws IOException {
    waitFor(procExec.getEnvironment(), timeout, "pid=" + proc.getProcId(),
      new ProcedureSyncWait.Predicate<Boolean>() {
        @Override
        public Boolean evaluate() throws IOException {
          if (!procExec.isRunning()) {
            return true;
          }
          ProcedureState state = proc.getState();
          if (state == ProcedureState.INITIALIZING || state == ProcedureState.RUNNABLE) {
            // under these states the procedure may have not been added to procExec yet, so do not
            // use isFinished to test whether it is finished, as this method will just check if the
            // procedure is in the running procedure list
            return false;
          }
          return procExec.isFinished(proc.getProcId());
        }
      });
    if (!procExec.isRunning()) {
      throw new IOException("The Master is Aborting");
    }

    // If the procedure fails, we should always have an exception captured. Throw it.
    // Needs to be an IOE to get out of here.
    if (proc.hasException()) {
      throw MasterProcedureUtil.unwrapRemoteIOException(proc);
    } else {
      return proc.getResult();
    }
  }
Helper to synchronously wait on conditions. This will be removed in the future (mainly when the
AssignmentManager will be replaced with a Procedure version) by using ProcedureYieldException,
and the queue will handle waiting and scheduling based on events.
hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ProcedureSyncWait.java