org.apache.hadoop.io.nativeio.NativeIO#isAvailable ( )源码实例Demo

下面列出了org.apache.hadoop.io.nativeio.NativeIO#isAvailable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hadoop   文件: RawLocalFileSystem.java
private LocalFSFileOutputStream(Path f, boolean append,
    FsPermission permission) throws IOException {
  File file = pathToFile(f);
  if (permission == null) {
    this.fos = new FileOutputStream(file, append);
  } else {
    if (Shell.WINDOWS && NativeIO.isAvailable()) {
      this.fos = NativeIO.Windows.createFileOutputStreamWithMode(file,
          append, permission.toShort());
    } else {
      this.fos = new FileOutputStream(file, append);
      boolean success = false;
      try {
        setPermission(f, permission);
        success = true;
      } finally {
        if (!success) {
          IOUtils.cleanup(LOG, this.fos);
        }
      }
    }
  }
}
 
源代码2 项目: hadoop   文件: RawLocalFileSystem.java
protected boolean mkOneDirWithMode(Path p, File p2f, FsPermission permission)
    throws IOException {
  if (permission == null) {
    return p2f.mkdir();
  } else {
    if (Shell.WINDOWS && NativeIO.isAvailable()) {
      try {
        NativeIO.Windows.createDirectoryWithMode(p2f, permission.toShort());
        return true;
      } catch (IOException e) {
        if (LOG.isDebugEnabled()) {
          LOG.debug(String.format(
              "NativeIO.createDirectoryWithMode error, path = %s, mode = %o",
              p2f, permission.toShort()), e);
        }
        return false;
      }
    } else {
      boolean b = p2f.mkdir();
      if (b) {
        setPermission(p, permission);
      }
      return b;
    }
  }
}
 
源代码3 项目: big-c   文件: RawLocalFileSystem.java
private LocalFSFileOutputStream(Path f, boolean append,
    FsPermission permission) throws IOException {
  File file = pathToFile(f);
  if (permission == null) {
    this.fos = new FileOutputStream(file, append);
  } else {
    if (Shell.WINDOWS && NativeIO.isAvailable()) {
      this.fos = NativeIO.Windows.createFileOutputStreamWithMode(file,
          append, permission.toShort());
    } else {
      this.fos = new FileOutputStream(file, append);
      boolean success = false;
      try {
        setPermission(f, permission);
        success = true;
      } finally {
        if (!success) {
          IOUtils.cleanup(LOG, this.fos);
        }
      }
    }
  }
}
 
源代码4 项目: lucene-solr   文件: RawLocalFileSystem.java
protected boolean mkOneDirWithMode(Path p, File p2f, FsPermission permission)
    throws IOException {
  if (permission == null) {
    permission = FsPermission.getDirDefault();
  }
  permission = permission.applyUMask(FsPermission.getUMask(getConf()));
  if (Shell.WINDOWS && NativeIO.isAvailable()) {
    try {
      NativeIO.Windows.createDirectoryWithMode(p2f, permission.toShort());
      return true;
    } catch (IOException e) {
      if (LOG.isDebugEnabled()) {
        LOG.debug(String.format(
            "NativeIO.createDirectoryWithMode error, path = %s, mode = %o",
            p2f, permission.toShort()), e);
      }
      return false;
    }
  } else {
    boolean b = p2f.mkdir();
    if (b) {
      setPermission(p, permission);
    }
    return b;
  }
}
 
源代码5 项目: hadoop   文件: ShortCircuitShm.java
/**
 * Create the ShortCircuitShm.
 * 
 * @param shmId       The ID to use.
 * @param stream      The stream that we're going to use to create this 
 *                    shared memory segment.
 *                    
 *                    Although this is a FileInputStream, we are going to
 *                    assume that the underlying file descriptor is writable
 *                    as well as readable. It would be more appropriate to use
 *                    a RandomAccessFile here, but that class does not have
 *                    any public accessor which returns a FileDescriptor,
 *                    unlike FileInputStream.
 */
public ShortCircuitShm(ShmId shmId, FileInputStream stream)
      throws IOException {
  if (!NativeIO.isAvailable()) {
    throw new UnsupportedOperationException("NativeIO is not available.");
  }
  if (Shell.WINDOWS) {
    throw new UnsupportedOperationException(
        "DfsClientShm is not yet implemented for Windows.");
  }
  if (unsafe == null) {
    throw new UnsupportedOperationException(
        "can't use DfsClientShm because we failed to " +
        "load misc.Unsafe.");
  }
  this.shmId = shmId;
  this.mmappedLength = getUsableLength(stream);
  this.baseAddress = POSIX.mmap(stream.getFD(), 
      POSIX.MMAP_PROT_READ | POSIX.MMAP_PROT_WRITE, true, mmappedLength);
  this.slots = new Slot[mmappedLength / BYTES_PER_SLOT];
  this.allocatedSlots = new BitSet(slots.length);
  if (LOG.isTraceEnabled()) {
    LOG.trace("creating " + this.getClass().getSimpleName() +
        "(shmId=" + shmId +
        ", mmappedLength=" + mmappedLength +
        ", baseAddress=" + String.format("%x", baseAddress) +
        ", slots.length=" + slots.length + ")");
  }
}
 
源代码6 项目: hadoop   文件: FileUtil.java
/**
 * Set permissions to the required value. Uses the java primitives instead
 * of forking if group == other.
 * @param f the file to change
 * @param permission the new permissions
 * @throws IOException
 */
public static void setPermission(File f, FsPermission permission
                                 ) throws IOException {
  FsAction user = permission.getUserAction();
  FsAction group = permission.getGroupAction();
  FsAction other = permission.getOtherAction();

  // use the native/fork if the group/other permissions are different
  // or if the native is available or on Windows
  if (group != other || NativeIO.isAvailable() || Shell.WINDOWS) {
    execSetPermission(f, permission);
    return;
  }
  
  boolean rv = true;
  
  // read perms
  rv = f.setReadable(group.implies(FsAction.READ), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.READ) != user.implies(FsAction.READ)) {
    rv = f.setReadable(user.implies(FsAction.READ), true);
    checkReturnValue(rv, f, permission);
  }

  // write perms
  rv = f.setWritable(group.implies(FsAction.WRITE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) {
    rv = f.setWritable(user.implies(FsAction.WRITE), true);
    checkReturnValue(rv, f, permission);
  }

  // exec perms
  rv = f.setExecutable(group.implies(FsAction.EXECUTE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) {
    rv = f.setExecutable(user.implies(FsAction.EXECUTE), true);
    checkReturnValue(rv, f, permission);
  }
}
 
源代码7 项目: hadoop   文件: FileUtil.java
private static void execSetPermission(File f, 
                                      FsPermission permission
                                     )  throws IOException {
  if (NativeIO.isAvailable()) {
    NativeIO.POSIX.chmod(f.getCanonicalPath(), permission.toShort());
  } else {
    execCommand(f, Shell.getSetPermissionCommand(
                String.format("%04o", permission.toShort()), false));
  }
}
 
源代码8 项目: hadoop   文件: RawLocalFileSystem.java
/**
 * Use the command chmod to set permission.
 */
@Override
public void setPermission(Path p, FsPermission permission)
  throws IOException {
  if (NativeIO.isAvailable()) {
    NativeIO.POSIX.chmod(pathToFile(p).getCanonicalPath(),
                   permission.toShort());
  } else {
    String perm = String.format("%04o", permission.toShort());
    Shell.execCommand(Shell.getSetPermissionCommand(perm, false,
      FileUtil.makeShellPath(pathToFile(p), true)));
  }
}
 
源代码9 项目: hadoop   文件: ReadaheadPool.java
/**
 * Return the singleton instance for the current process.
 */
public static ReadaheadPool getInstance() {
  synchronized (ReadaheadPool.class) {
    if (instance == null && NativeIO.isAvailable()) {
      instance = new ReadaheadPool();
    }
    return instance;
  }
}
 
源代码10 项目: big-c   文件: ShortCircuitShm.java
/**
 * Create the ShortCircuitShm.
 * 
 * @param shmId       The ID to use.
 * @param stream      The stream that we're going to use to create this 
 *                    shared memory segment.
 *                    
 *                    Although this is a FileInputStream, we are going to
 *                    assume that the underlying file descriptor is writable
 *                    as well as readable. It would be more appropriate to use
 *                    a RandomAccessFile here, but that class does not have
 *                    any public accessor which returns a FileDescriptor,
 *                    unlike FileInputStream.
 */
public ShortCircuitShm(ShmId shmId, FileInputStream stream)
      throws IOException {
  if (!NativeIO.isAvailable()) {
    throw new UnsupportedOperationException("NativeIO is not available.");
  }
  if (Shell.WINDOWS) {
    throw new UnsupportedOperationException(
        "DfsClientShm is not yet implemented for Windows.");
  }
  if (unsafe == null) {
    throw new UnsupportedOperationException(
        "can't use DfsClientShm because we failed to " +
        "load misc.Unsafe.");
  }
  this.shmId = shmId;
  this.mmappedLength = getUsableLength(stream);
  this.baseAddress = POSIX.mmap(stream.getFD(), 
      POSIX.MMAP_PROT_READ | POSIX.MMAP_PROT_WRITE, true, mmappedLength);
  this.slots = new Slot[mmappedLength / BYTES_PER_SLOT];
  this.allocatedSlots = new BitSet(slots.length);
  if (LOG.isTraceEnabled()) {
    LOG.trace("creating " + this.getClass().getSimpleName() +
        "(shmId=" + shmId +
        ", mmappedLength=" + mmappedLength +
        ", baseAddress=" + String.format("%x", baseAddress) +
        ", slots.length=" + slots.length + ")");
  }
}
 
源代码11 项目: big-c   文件: FileUtil.java
/**
 * Set permissions to the required value. Uses the java primitives instead
 * of forking if group == other.
 * @param f the file to change
 * @param permission the new permissions
 * @throws IOException
 */
public static void setPermission(File f, FsPermission permission
                                 ) throws IOException {
  FsAction user = permission.getUserAction();
  FsAction group = permission.getGroupAction();
  FsAction other = permission.getOtherAction();

  // use the native/fork if the group/other permissions are different
  // or if the native is available or on Windows
  if (group != other || NativeIO.isAvailable() || Shell.WINDOWS) {
    execSetPermission(f, permission);
    return;
  }
  
  boolean rv = true;
  
  // read perms
  rv = f.setReadable(group.implies(FsAction.READ), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.READ) != user.implies(FsAction.READ)) {
    rv = f.setReadable(user.implies(FsAction.READ), true);
    checkReturnValue(rv, f, permission);
  }

  // write perms
  rv = f.setWritable(group.implies(FsAction.WRITE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) {
    rv = f.setWritable(user.implies(FsAction.WRITE), true);
    checkReturnValue(rv, f, permission);
  }

  // exec perms
  rv = f.setExecutable(group.implies(FsAction.EXECUTE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) {
    rv = f.setExecutable(user.implies(FsAction.EXECUTE), true);
    checkReturnValue(rv, f, permission);
  }
}
 
源代码12 项目: big-c   文件: FileUtil.java
private static void execSetPermission(File f, 
                                      FsPermission permission
                                     )  throws IOException {
  if (NativeIO.isAvailable()) {
    NativeIO.POSIX.chmod(f.getCanonicalPath(), permission.toShort());
  } else {
    execCommand(f, Shell.getSetPermissionCommand(
                String.format("%04o", permission.toShort()), false));
  }
}
 
源代码13 项目: RDFS   文件: ReadaheadPool.java
/**
 * Return the singleton instance for the current process.
 */
public static ReadaheadPool getInstance() {
  synchronized (ReadaheadPool.class) {
    if (instance == null && NativeIO.isAvailable()) {
      instance = new ReadaheadPool();
    }
    return instance;
  }
}
 
源代码14 项目: big-c   文件: RawLocalFileSystem.java
/**
 * Use the command chmod to set permission.
 */
@Override
public void setPermission(Path p, FsPermission permission)
  throws IOException {
  if (NativeIO.isAvailable()) {
    NativeIO.POSIX.chmod(pathToFile(p).getCanonicalPath(),
                   permission.toShort());
  } else {
    String perm = String.format("%04o", permission.toShort());
    Shell.execCommand(Shell.getSetPermissionCommand(perm, false,
      FileUtil.makeShellPath(pathToFile(p), true)));
  }
}
 
源代码15 项目: big-c   文件: ReadaheadPool.java
/**
 * Return the singleton instance for the current process.
 */
public static ReadaheadPool getInstance() {
  synchronized (ReadaheadPool.class) {
    if (instance == null && NativeIO.isAvailable()) {
      instance = new ReadaheadPool();
    }
    return instance;
  }
}
 
源代码16 项目: lucene-solr   文件: FileUtil.java
/**
 * Set permissions to the required value. Uses the java primitives instead
 * of forking if group == other.
 * @param f the file to change
 * @param permission the new permissions
 * @throws IOException exception on setPermission
 */
public static void setPermission(File f, FsPermission permission
) throws IOException {
  FsAction user = permission.getUserAction();
  FsAction group = permission.getGroupAction();
  FsAction other = permission.getOtherAction();

  // use the native/fork if the group/other permissions are different
  // or if the native is available or on Windows
  if (group != other || NativeIO.isAvailable() || Shell.WINDOWS) {
    execSetPermission(f, permission);
    return;
  }

  boolean rv = true;

  // read perms
  rv = f.setReadable(group.implies(FsAction.READ), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.READ) != user.implies(FsAction.READ)) {
    rv = f.setReadable(user.implies(FsAction.READ), true);
    checkReturnValue(rv, f, permission);
  }

  // write perms
  rv = f.setWritable(group.implies(FsAction.WRITE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) {
    rv = f.setWritable(user.implies(FsAction.WRITE), true);
    checkReturnValue(rv, f, permission);
  }

  // exec perms
  rv = f.setExecutable(group.implies(FsAction.EXECUTE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) {
    rv = f.setExecutable(user.implies(FsAction.EXECUTE), true);
    checkReturnValue(rv, f, permission);
  }
}
 
源代码17 项目: lucene-solr   文件: FileUtil.java
private static void execSetPermission(File f,
                                      FsPermission permission
)  throws IOException {
  if (NativeIO.isAvailable()) {
    NativeIO.POSIX.chmod(f.getCanonicalPath(), permission.toShort());
  } else {
    execCommand(f, Shell.getSetPermissionCommand(
        String.format("%04o", permission.toShort()), false));
  }
}
 
源代码18 项目: lucene-solr   文件: RawLocalFileSystem.java
private LocalFSFileOutputStream(Path f, boolean append,
                                FsPermission permission) throws IOException {
  File file = pathToFile(f);
  if (!append && permission == null) {
    permission = FsPermission.getFileDefault();
  }
  if (permission == null) {
    this.fos = new FileOutputStream(file, append);
  } else {
    permission = permission.applyUMask(FsPermission.getUMask(getConf()));
    if (Shell.WINDOWS && NativeIO.isAvailable()) {
      this.fos = NativeIO.Windows.createFileOutputStreamWithMode(file,
          append, permission.toShort());
    } else {
      this.fos = new FileOutputStream(file, append);
      boolean success = false;
      try {
        setPermission(f, permission);
        success = true;
      } finally {
        if (!success) {
          IOUtils.cleanup(LOG, this.fos);
        }
      }
    }
  }
}
 
源代码19 项目: lucene-solr   文件: RawLocalFileSystem.java
/**
 * Load file permission information (UNIX symbol rwxrwxrwx, sticky bit info).
 *
 * To improve peformance, give priority to native stat() call. First try get
 * permission information by using native JNI call then fall back to use non
 * native (ProcessBuilder) call in case native lib is not loaded or native
 * call is not successful
 */
private synchronized void loadPermissionInfo() {
  if (!isPermissionLoaded() && NativeIO.isAvailable()) {
    try {
      loadPermissionInfoByNativeIO();
    } catch (IOException ex) {
      LOG.debug("Native call failed", ex);
    }
  }

  if (!isPermissionLoaded()) {
    loadPermissionInfoByNonNativeIO();
  }
}
 
源代码20 项目: lucene-solr   文件: RawLocalFileSystem.java
/**
 * Use the command chmod to set permission.
 */
@Override
public void setPermission(Path p, FsPermission permission)
    throws IOException {
  if (NativeIO.isAvailable()) {
    NativeIO.POSIX.chmod(pathToFile(p).getCanonicalPath(),
        permission.toShort());
  } else {
    Files.setPosixFilePermissions(Paths.get(p.toUri()),
        PosixFilePermissions.fromString(permission.toString()));
  }
}