io.micronaut.context.ApplicationContext.isRunning()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(3.0k)|赞(0)|评价(0)|浏览(156)

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

ApplicationContext.isRunning介绍

暂无

代码示例

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * @param context A platform specific context object
 * @return Build the {@link ApplicationContext} to use
 */
protected ApplicationContext buildApplicationContext(@Nullable C context) {
  if (applicationContext == null) {
    final ApplicationContextBuilder contextBuilder = newApplicationContextBuilder();
    final Package pkg = getClass().getPackage();
    if (pkg != null) {
      final String name = pkg.getName();
      if (StringUtils.isNotEmpty(name)) {
        contextBuilder.packages(name);
      }
    }
    applicationContext = contextBuilder.build();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
      if (applicationContext != null && applicationContext.isRunning()) {
        applicationContext.close();
        applicationContext = null;
      }
    }));
  }
  return applicationContext;
}

代码示例来源:origin: micronaut-projects/micronaut-core

/**
   * Start the environment specified.
   * @param applicationContext the application context with the environment
   * @return The environment within the context
   */
  protected Environment startEnvironment(ApplicationContext applicationContext) {
    if (!applicationContext.isRunning()) {
      if (this instanceof PropertySource) {
        applicationContext.getEnvironment().addPropertySource((PropertySource) this);
      }

      return applicationContext
          .start()
          .getEnvironment();
    } else {
      return applicationContext.getEnvironment();
    }
  }
}

代码示例来源:origin: micronaut-projects/micronaut-core

private void stopInternal() {
  try {
    workerGroup.shutdownGracefully()
        .addListener(this::logShutdownErrorIfNecessary);
    parentGroup.shutdownGracefully()
        .addListener(this::logShutdownErrorIfNecessary);
    webSocketSessions.close();
    applicationContext.publishEvent(new ServerShutdownEvent(this));
    if (serviceInstance != null) {
      applicationContext.publishEvent(new ServiceShutdownEvent(serviceInstance));
    }
    if (applicationContext.isRunning()) {
      applicationContext.stop();
    }
  } catch (Throwable e) {
    if (LOG.isErrorEnabled()) {
      LOG.error("Error stopping Micronaut server: " + e.getMessage(), e);
    }
  }
}

代码示例来源:origin: micronaut-projects/micronaut-spring

@Override
  public boolean isRunning() {
    return micronautContext.isRunning();
  }
}

代码示例来源:origin: micronaut-projects/micronaut-examples

@Override
public void onTerminate() {
  super.onTerminate();
  if(ctx != null && ctx.isRunning()) {
    ctx.stop();
  }
}

代码示例来源:origin: io.micronaut/inject

@SuppressWarnings("unchecked")
  @Override
  default T stop() {
    ApplicationContext applicationContext = getApplicationContext();
    if (applicationContext != null && applicationContext.isRunning()) {
      applicationContext.stop();
    }
    return (T) this;
  }
}

代码示例来源:origin: io.micronaut/micronaut-inject

@SuppressWarnings("unchecked")
  @Override
  default T stop() {
    ApplicationContext applicationContext = getApplicationContext();
    if (applicationContext != null && applicationContext.isRunning()) {
      applicationContext.stop();
    }
    return (T) this;
  }
}

相关文章