当前位置: 首页>>代码示例>>Java>>正文


Java ShutdownHookManager类代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.util.ShutdownHookManager的典型用法代码示例。如果您正苦于以下问题:Java ShutdownHookManager类的具体用法?Java ShutdownHookManager怎么用?Java ShutdownHookManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ShutdownHookManager类属于org.apache.hadoop.hbase.util包,在下文中一共展示了ShutdownHookManager类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: suppressHdfsShutdownHook

import org.apache.hadoop.hbase.util.ShutdownHookManager; //导入依赖的package包/类
private static Runnable suppressHdfsShutdownHook(final FileSystem fs) {
  try {
    // This introspection has been updated to work for hadoop 0.20, 0.21 and for
    // cloudera 0.20.  0.21 and cloudera 0.20 both have hadoop-4829.  With the
    // latter in place, things are a little messy in that there are now two
    // instances of the data member clientFinalizer; an uninstalled one in
    // FileSystem and one in the innner class named Cache that actually gets
    // registered as a shutdown hook.  If the latter is present, then we are
    // on 0.21 or cloudera patched 0.20.
    Runnable hdfsClientFinalizer = null;
    // Look into the FileSystem#Cache class for clientFinalizer
    Class<?> [] classes = FileSystem.class.getDeclaredClasses();
    Class<?> cache = null;
    for (Class<?> c: classes) {
      if (c.getSimpleName().equals("Cache")) {
        cache = c;
        break;
      }
    }

    if (cache == null) {
      throw new RuntimeException(
          "This should not happen. Could not find the cache class in FileSystem.");
    }

    Field field = null;
    try {
      field = cache.getDeclaredField(CLIENT_FINALIZER_DATA_METHOD);
    } catch (NoSuchFieldException e) {
      // We can get here if the Cache class does not have a clientFinalizer
      // instance: i.e. we're running on straight 0.20 w/o hadoop-4829.
    }
    if (field != null) {
      field.setAccessible(true);
      Field cacheField = FileSystem.class.getDeclaredField("CACHE");
      cacheField.setAccessible(true);
      Object cacheInstance = cacheField.get(fs);
      hdfsClientFinalizer = (Runnable)field.get(cacheInstance);
    } else {
      // Then we didnt' find clientFinalizer in Cache.  Presume clean 0.20 hadoop.
      field = FileSystem.class.getDeclaredField(CLIENT_FINALIZER_DATA_METHOD);
      field.setAccessible(true);
      hdfsClientFinalizer = (Runnable)field.get(null);
    }
    if (hdfsClientFinalizer == null) {
      throw new RuntimeException("Client finalizer is null, can't suppress!");
    }
    synchronized (fsShutdownHooks) {
      if (!fsShutdownHooks.containsKey(hdfsClientFinalizer) &&
          !ShutdownHookManager.deleteShutdownHook(hdfsClientFinalizer)) {
        throw new RuntimeException("Failed suppression of fs shutdown hook: " +
          hdfsClientFinalizer);
      }
      Integer refs = fsShutdownHooks.get(hdfsClientFinalizer);
      fsShutdownHooks.put(hdfsClientFinalizer, refs == null ? 1 : refs + 1);
    }
    return hdfsClientFinalizer;
  } catch (NoSuchFieldException nsfe) {
    LOG.fatal("Couldn't find field 'clientFinalizer' in FileSystem!", nsfe);
    throw new RuntimeException("Failed to suppress HDFS shutdown hook");
  } catch (IllegalAccessException iae) {
    LOG.fatal("Couldn't access field 'clientFinalizer' in FileSystem!", iae);
    throw new RuntimeException("Failed to suppress HDFS shutdown hook");
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:66,代码来源:ShutdownHook.java

示例2: suppressHdfsShutdownHook

import org.apache.hadoop.hbase.util.ShutdownHookManager; //导入依赖的package包/类
private static Runnable suppressHdfsShutdownHook(final FileSystem fs) {
  try {
    // This introspection has been updated to work for hadoop 0.20, 0.21 and for
    // cloudera 0.20.  0.21 and cloudera 0.20 both have hadoop-4829.  With the
    // latter in place, things are a little messy in that there are now two
    // instances of the data member clientFinalizer; an uninstalled one in
    // FileSystem and one in the innner class named Cache that actually gets
    // registered as a shutdown hook.  If the latter is present, then we are
    // on 0.21 or cloudera patched 0.20.
    Runnable hdfsClientFinalizer = null;
    // Look into the FileSystem#Cache class for clientFinalizer
    Class<?> [] classes = FileSystem.class.getDeclaredClasses();
    Class<?> cache = null;
    for (Class<?> c: classes) {
      if (c.getSimpleName().equals("Cache")) {
        cache = c;
        break;
      }
    }
    Field field = null;
    try {
      field = cache.getDeclaredField(CLIENT_FINALIZER_DATA_METHOD);
    } catch (NoSuchFieldException e) {
      // We can get here if the Cache class does not have a clientFinalizer
      // instance: i.e. we're running on straight 0.20 w/o hadoop-4829.
    }
    if (field != null) {
      field.setAccessible(true);
      Field cacheField = FileSystem.class.getDeclaredField("CACHE");
      cacheField.setAccessible(true);
      Object cacheInstance = cacheField.get(fs);
      hdfsClientFinalizer = (Runnable)field.get(cacheInstance);
    } else {
      // Then we didnt' find clientFinalizer in Cache.  Presume clean 0.20 hadoop.
      field = FileSystem.class.getDeclaredField(CLIENT_FINALIZER_DATA_METHOD);
      field.setAccessible(true);
      hdfsClientFinalizer = (Runnable)field.get(null);
    }
    if (hdfsClientFinalizer == null) {
      throw new RuntimeException("Client finalizer is null, can't suppress!");
    }
    if (!fsShutdownHooks.containsKey(hdfsClientFinalizer) &&
        !ShutdownHookManager.deleteShutdownHook(hdfsClientFinalizer)) {
      throw new RuntimeException("Failed suppression of fs shutdown hook: " +
        hdfsClientFinalizer);
    }
    synchronized (fsShutdownHooks) {
      Integer refs = fsShutdownHooks.get(hdfsClientFinalizer);
      fsShutdownHooks.put(hdfsClientFinalizer, refs == null ? 1 : refs + 1);
    }
    return hdfsClientFinalizer;
  } catch (NoSuchFieldException nsfe) {
    LOG.fatal("Couldn't find field 'clientFinalizer' in FileSystem!", nsfe);
    throw new RuntimeException("Failed to suppress HDFS shutdown hook");
  } catch (IllegalAccessException iae) {
    LOG.fatal("Couldn't access field 'clientFinalizer' in FileSystem!", iae);
    throw new RuntimeException("Failed to suppress HDFS shutdown hook");
  }
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:60,代码来源:ShutdownHook.java

示例3: suppressHdfsShutdownHook

import org.apache.hadoop.hbase.util.ShutdownHookManager; //导入依赖的package包/类
private static Runnable suppressHdfsShutdownHook(final FileSystem fs) {
  try {
    // This introspection has been updated to work for hadoop 0.20, 0.21 and for
    // cloudera 0.20.  0.21 and cloudera 0.20 both have hadoop-4829.  With the
    // latter in place, things are a little messy in that there are now two
    // instances of the data member clientFinalizer; an uninstalled one in
    // FileSystem and one in the innner class named Cache that actually gets
    // registered as a shutdown hook.  If the latter is present, then we are
    // on 0.21 or cloudera patched 0.20.
    Runnable hdfsClientFinalizer = null;
    // Look into the FileSystem#Cache class for clientFinalizer
    Class<?> [] classes = FileSystem.class.getDeclaredClasses();
    Class<?> cache = null;
    for (Class<?> c: classes) {
      if (c.getSimpleName().equals("Cache")) {
        cache = c;
        break;
      }
    }

    if (cache == null) {
      throw new RuntimeException(
          "This should not happen. Could not find the cache class in FileSystem.");
    }

    Field field = null;
    try {
      field = cache.getDeclaredField(CLIENT_FINALIZER_DATA_METHOD);
    } catch (NoSuchFieldException e) {
      // We can get here if the Cache class does not have a clientFinalizer
      // instance: i.e. we're running on straight 0.20 w/o hadoop-4829.
    }
    if (field != null) {
      field.setAccessible(true);
      Field cacheField = FileSystem.class.getDeclaredField("CACHE");
      cacheField.setAccessible(true);
      Object cacheInstance = cacheField.get(fs);
      hdfsClientFinalizer = (Runnable)field.get(cacheInstance);
    } else {
      // Then we didnt' find clientFinalizer in Cache.  Presume clean 0.20 hadoop.
      field = FileSystem.class.getDeclaredField(CLIENT_FINALIZER_DATA_METHOD);
      field.setAccessible(true);
      hdfsClientFinalizer = (Runnable)field.get(null);
    }
    if (hdfsClientFinalizer == null) {
      throw new RuntimeException("Client finalizer is null, can't suppress!");
    }
    synchronized (fsShutdownHooks) {
      boolean isFSCacheDisabled = fs.getConf().getBoolean("fs.hdfs.impl.disable.cache", false);
      if (!isFSCacheDisabled && !fsShutdownHooks.containsKey(hdfsClientFinalizer)
          && !ShutdownHookManager.deleteShutdownHook(hdfsClientFinalizer)) {
        throw new RuntimeException(
            "Failed suppression of fs shutdown hook: " + hdfsClientFinalizer);
      }
      Integer refs = fsShutdownHooks.get(hdfsClientFinalizer);
      fsShutdownHooks.put(hdfsClientFinalizer, refs == null ? 1 : refs + 1);
    }
    return hdfsClientFinalizer;
  } catch (NoSuchFieldException nsfe) {
    LOG.error(HBaseMarkers.FATAL, "Couldn't find field 'clientFinalizer' in FileSystem!",
        nsfe);
    throw new RuntimeException("Failed to suppress HDFS shutdown hook");
  } catch (IllegalAccessException iae) {
    LOG.error(HBaseMarkers.FATAL, "Couldn't access field 'clientFinalizer' in FileSystem!",
        iae);
    throw new RuntimeException("Failed to suppress HDFS shutdown hook");
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:69,代码来源:ShutdownHook.java

示例4: suppressHdfsShutdownHook

import org.apache.hadoop.hbase.util.ShutdownHookManager; //导入依赖的package包/类
private static Runnable suppressHdfsShutdownHook(final FileSystem fs) {
  try {
    // This introspection has been updated to work for hadoop 0.20, 0.21 and for
    // cloudera 0.20.  0.21 and cloudera 0.20 both have hadoop-4829.  With the
    // latter in place, things are a little messy in that there are now two
    // instances of the data member clientFinalizer; an uninstalled one in
    // FileSystem and one in the innner class named Cache that actually gets
    // registered as a shutdown hook.  If the latter is present, then we are
    // on 0.21 or cloudera patched 0.20.
    Runnable hdfsClientFinalizer = null;
    // Look into the FileSystem#Cache class for clientFinalizer
    Class<?> [] classes = FileSystem.class.getDeclaredClasses();
    Class<?> cache = null;
    for (Class<?> c: classes) {
      if (c.getSimpleName().equals("Cache")) {
        cache = c;
        break;
      }
    }

    if (cache == null) {
      throw new RuntimeException(
          "This should not happen. Could not find the cache class in FileSystem.");
    }

    Field field = null;
    try {
      field = cache.getDeclaredField(CLIENT_FINALIZER_DATA_METHOD);
    } catch (NoSuchFieldException e) {
      // We can get here if the Cache class does not have a clientFinalizer
      // instance: i.e. we're running on straight 0.20 w/o hadoop-4829.
    }
    if (field != null) {
      field.setAccessible(true);
      Field cacheField = FileSystem.class.getDeclaredField("CACHE");
      cacheField.setAccessible(true);
      Object cacheInstance = cacheField.get(fs);
      hdfsClientFinalizer = (Runnable)field.get(cacheInstance);
    } else {
      // Then we didnt' find clientFinalizer in Cache.  Presume clean 0.20 hadoop.
      field = FileSystem.class.getDeclaredField(CLIENT_FINALIZER_DATA_METHOD);
      field.setAccessible(true);
      hdfsClientFinalizer = (Runnable)field.get(null);
    }
    if (hdfsClientFinalizer == null) {
      throw new RuntimeException("Client finalizer is null, can't suppress!");
    }
    if (!fsShutdownHooks.containsKey(hdfsClientFinalizer) &&
        !ShutdownHookManager.deleteShutdownHook(hdfsClientFinalizer)) {
      throw new RuntimeException("Failed suppression of fs shutdown hook: " +
        hdfsClientFinalizer);
    }
    synchronized (fsShutdownHooks) {
      Integer refs = fsShutdownHooks.get(hdfsClientFinalizer);
      fsShutdownHooks.put(hdfsClientFinalizer, refs == null ? 1 : refs + 1);
    }
    return hdfsClientFinalizer;
  } catch (NoSuchFieldException nsfe) {
    LOG.fatal("Couldn't find field 'clientFinalizer' in FileSystem!", nsfe);
    throw new RuntimeException("Failed to suppress HDFS shutdown hook");
  } catch (IllegalAccessException iae) {
    LOG.fatal("Couldn't access field 'clientFinalizer' in FileSystem!", iae);
    throw new RuntimeException("Failed to suppress HDFS shutdown hook");
  }
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:66,代码来源:ShutdownHook.java

示例5: install

import org.apache.hadoop.hbase.util.ShutdownHookManager; //导入依赖的package包/类
/**
 * Install a shutdown hook that calls stop on the passed Stoppable
 * and then thread joins against the passed <code>threadToJoin</code>.
 * When this thread completes, it then runs the hdfs thread (This install
 * removes the hdfs shutdown hook keeping a handle on it to run it after
 * <code>threadToJoin</code> has stopped).
 *
 * <p>To suppress all shutdown hook  handling -- both the running of the
 * regionserver hook and of the hdfs hook code -- set
 * {@link ShutdownHook#RUN_SHUTDOWN_HOOK} in {@link Configuration} to
 * <code>false</code>.
 * This configuration value is checked when the hook code runs.
 * @param conf
 * @param fs Instance of Filesystem used by the RegionServer
 * @param stop Installed shutdown hook will call stop against this passed
 * <code>Stoppable</code> instance.
 * @param threadToJoin After calling stop on <code>stop</code> will then
 * join this thread.
 */
public static void install(final Configuration conf, final FileSystem fs,
    final Stoppable stop, final Thread threadToJoin) {
  Runnable fsShutdownHook = suppressHdfsShutdownHook(fs);
  Thread t = new ShutdownHookThread(conf, stop, threadToJoin, fsShutdownHook);
  ShutdownHookManager.affixShutdownHook(t, 0);
  LOG.debug("Installed shutdown hook thread: " + t.getName());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:27,代码来源:ShutdownHook.java

示例6: install

import org.apache.hadoop.hbase.util.ShutdownHookManager; //导入依赖的package包/类
/**
 * Install a shutdown hook that calls stop on the passed Stoppable
 * and then thread joins against the passed <code>threadToJoin</code>.
 * When this thread completes, it then runs the hdfs thread (This install
 * removes the hdfs shutdown hook keeping a handle on it to run it after
 * <code>threadToJoin</code> has stopped).
 *
 * <p>To suppress all shutdown hook  handling -- both the running of the
 * regionserver hook and of the hdfs hook code -- set
 * {@link ShutdownHook#RUN_SHUTDOWN_HOOK} in {@link Configuration} to
 * <code>false</code>.
 * This configuration value is checked when the hook code runs.
 * @param conf
 * @param fs Instance of Filesystem used by the RegionServer
 * @param stop Installed shutdown hook will call stop against this passed
 * <code>Stoppable</code> instance.
 * @param threadToJoin After calling stop on <code>stop</code> will then
 * join this thread.
 */
public static void install(final Configuration conf, final FileSystem fs,
    final Stoppable stop, final Thread threadToJoin) {
  Runnable fsShutdownHook = suppressHdfsShutdownHook(fs);
  Thread t = new ShutdownHookThread(conf, stop, threadToJoin, fsShutdownHook);
  ShutdownHookManager.affixShutdownHook(t, 0);
  LOG.info("Installed shutdown hook thread: " + t.getName());
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:27,代码来源:ShutdownHook.java


注:本文中的org.apache.hadoop.hbase.util.ShutdownHookManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。