org.apache.storm.utils.Utils.addShutdownHookWithForceKillIn1Sec()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中org.apache.storm.utils.Utils.addShutdownHookWithForceKillIn1Sec()方法的一些代码示例,展示了Utils.addShutdownHookWithForceKillIn1Sec()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.addShutdownHookWithForceKillIn1Sec()方法的具体详情如下:
包路径:org.apache.storm.utils.Utils
类名称:Utils
方法名:addShutdownHookWithForceKillIn1Sec

Utils.addShutdownHookWithForceKillIn1Sec介绍

[英]Adds the user supplied function as a shutdown hook for cleanup. Also adds a function that sleeps for a second and then halts the runtime to avoid any zombie process in case cleanup function hangs.
[中]添加用户提供的函数作为清理的关闭挂钩。还添加了一个函数,该函数会休眠一秒钟,然后停止运行时,以避免任何僵尸进程,以防清理功能挂起。

代码示例

代码示例来源:origin: apache/storm

public static void main(String[] args) throws Exception {
  Preconditions.checkArgument(args.length == 5, "Illegal number of arguments. Expected: 5, Actual: " + args.length);
  String stormId = args[0];
  String assignmentId = args[1];
  String supervisorPort = args[2];
  String portStr = args[3];
  String workerId = args[4];
  Map<String, Object> conf = ConfigUtils.readStormConfig();
  Utils.setupDefaultUncaughtExceptionHandler();
  StormCommon.validateDistributedMode(conf);
  Worker worker = new Worker(conf, null, stormId, assignmentId, Integer.parseInt(supervisorPort),
                Integer.parseInt(portStr), workerId);
  worker.start();
  Utils.addShutdownHookWithForceKillIn1Sec(worker::shutdown);
}

代码示例来源:origin: apache/storm

Utils.addShutdownHookWithForceKillIn1Sec(metricsRegistry::stopMetricsReporters);
try {
  jettyServer.start();

代码示例来源:origin: apache/storm

/**
 * start distribute supervisor.
 */
public void launchDaemon() {
  LOG.info("Starting supervisor for storm version '{}'.", VersionInfo.getVersion());
  try {
    Map<String, Object> conf = getConf();
    if (ConfigUtils.isLocalMode(conf)) {
      throw new IllegalArgumentException("Cannot start server in local mode!");
    }
    launch();
    metricsRegistry.registerGauge("supervisor:num-slots-used-gauge", () -> SupervisorUtils.supervisorWorkerIds(conf).size());
    //This will only get updated once
    metricsRegistry.registerMeter("supervisor:num-launched").mark();
    metricsRegistry.registerMeter("supervisor:num-shell-exceptions", ShellUtils.numShellExceptions);
    metricsRegistry.startMetricsReporters(conf);
    Utils.addShutdownHookWithForceKillIn1Sec(() -> {
      metricsRegistry.stopMetricsReporters();
      this.close();
    });
    // blocking call under the hood, must invoke after launch cause some services must be initialized
    launchSupervisorThriftServer(conf);
  } catch (Exception e) {
    LOG.error("Failed to start supervisor\n", e);
    System.exit(1);
  }
}

代码示例来源:origin: apache/storm

public static void main(String[] args) {
  SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
  Map<String, Object> conf = ConfigUtils.overrideLoginConfigWithSystemProperty(ConfigUtils.readStormConfig());
  StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
  final Pacemaker serverHandler = new Pacemaker(conf, metricsRegistry);
  serverHandler.launchServer();
  metricsRegistry.startMetricsReporters(conf);
  Utils.addShutdownHookWithForceKillIn1Sec(metricsRegistry::stopMetricsReporters);
}

代码示例来源:origin: apache/storm

/**
   * Main method to start the server.
   */
  public static void main(String [] args) throws Exception {
    Utils.setupDefaultUncaughtExceptionHandler();
    Map<String, Object> conf = ConfigUtils.readStormConfig();
    StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
    try (DRPCServer server = new DRPCServer(conf, metricsRegistry)) {
      metricsRegistry.startMetricsReporters(conf);
      Utils.addShutdownHookWithForceKillIn1Sec(() -> {
        server.meterShutdownCalls.mark();
        metricsRegistry.stopMetricsReporters();
        server.close();
      });
      server.start();
      server.awaitTermination();
    }
  }
}

代码示例来源:origin: apache/storm

/**
   * Main method to start the server.
   */
  public static void main(String [] args) throws Exception {
    Utils.setupDefaultUncaughtExceptionHandler();
    Map<String, Object> conf = ConfigUtils.readStormConfig();

    StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
    String logRoot = ConfigUtils.workerArtifactsRoot(conf);
    File logRootDir = new File(logRoot);
    logRootDir.mkdirs();
    WorkerLogs workerLogs = new WorkerLogs(conf, logRootDir, metricsRegistry);
    DirectoryCleaner directoryCleaner = new DirectoryCleaner(metricsRegistry);

    try (LogviewerServer server = new LogviewerServer(conf, metricsRegistry);
       LogCleaner logCleaner = new LogCleaner(conf, workerLogs, directoryCleaner, logRootDir, metricsRegistry)) {
      metricsRegistry.startMetricsReporters(conf);
      Utils.addShutdownHookWithForceKillIn1Sec(() -> {
        server.meterShutdownCalls.mark();
        metricsRegistry.stopMetricsReporters();
        server.close();
      });
      logCleaner.start();

      server.start();
      server.awaitTermination();
    }
  }
}

代码示例来源:origin: org.apache.storm/storm-core

/**
 * start distribute supervisor
 */
public void launchDaemon() {
  LOG.info("Starting supervisor for storm version '{}'.", VersionInfo.getVersion());
  try {
    Map<String, Object> conf = getConf();
    if (ConfigUtils.isLocalMode(conf)) {
      throw new IllegalArgumentException("Cannot start server in local mode!");
    }
    launch();
    Utils.addShutdownHookWithForceKillIn1Sec(new Runnable(){ 
      @Override
      public void run() {
        close();
      }
    });
    registerWorkerNumGauge("supervisor:num-slots-used-gauge", conf);
    StormMetricsRegistry.startMetricsReporters(conf);
  } catch (Exception e) {
    LOG.error("Failed to start supervisor\n", e);
    System.exit(1);
  }
}

相关文章

Utils类方法