private boolean canBlockTillFileAvailable(Path resolvedPath) throws InterruptedException {
    long oldLength;
    long newSize;

    long emptyCheck = 0;
    int fixed = 0;
    // get the underlying file
    File file = resolvedPath.toAbsolutePath().toFile();

    // empty file check
    while (file.length() == 0 && emptyCheck < 5) {
      sleep(FILE_CHECK_INTERVAL_MILLIS);
      emptyCheck++;
    }
    // The file seems to be empty
    if (emptyCheck == 5)
      return false;

    // check the file size
    oldLength = file.length();

    // Check if file copy is done
    while (true) {
      LOG.info("Waiting for file to be completely copied");
      sleep(FILE_CHECK_INTERVAL_MILLIS);
      newSize = file.length();
      if (newSize > oldLength) {
        oldLength = newSize;
        continue;
      } else if (oldLength == newSize) {
        fixed++;
      } else {
        // this can never happen,
        return false;
      }
      if (fixed > FIXED_FILE_COUNTER) {
        LOG.info("File " + resolvedPath + " has finished copying");
        return true;
      }
    }


  }
Routine to make the file watcher block the thread till the file is completely copied
Check the length of the file continuously till there are 20 consecutive intervals when
the file length does not change
FILE_CHECK_INTERVAL_MILLIS defines the check interval both for detecting empty files
and subsequent checks to detect if a file has finished copying

The process which copies the jar into the views dir is external and we dont really
know when it would finish, this is also highly OS and FS dependent. The following routine
introduces a heuristic to detect when a file has finished copying by looking at subsequent
lengths of the file which was detected as being created

This would block for ~ 7 seconds in most cases


@param resolvedPath
@return false if the file check failed, true otherwise
ambari-server/src/main/java/org/apache/ambari/server/view/ViewDirectoryWatcher.java