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

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

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

ApplicationContext.stop介绍

暂无

代码示例

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

/**
 * Main method.
 * @param args The arguments
 */
public static void main(String... args) {
  // enable Graal class analysis
  System.setProperty(GraalClassLoadingReporter.GRAAL_CLASS_ANALYSIS, Boolean.TRUE.toString());
  if (ArrayUtils.isNotEmpty(args)) {
    System.setProperty(GraalClassLoadingReporter.REFLECTION_JSON_FILE, args[0]);
  }
  try {
    ApplicationContext applicationContext = ApplicationContext.run();
    // following beans may impact classloading, so load them.
    applicationContext.findBean(EmbeddedServer.class);
    applicationContext.getBeansOfType(ExecutableMethodProcessor.class);
    // finish up
    applicationContext.stop();
  } catch (Throwable e) {
    System.err.println("An error occurred analyzing class requirements: " + e.getMessage());
    e.printStackTrace(System.err);
  }
}

代码示例来源: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-core

@Test
  public void testGetPojoList() {
    ApplicationContext applicationContext = ApplicationContext.run();
    EmbeddedServer server = applicationContext.getBean(EmbeddedServer.class).start();

    HttpClient client = applicationContext.createBean(HttpClient.class, server.getURL());

    Flowable<HttpResponse<List>> flowable = Flowable.fromPublisher(client.exchange(
        HttpRequest.GET("/get/pojoList"), Argument.of(List.class, HttpGetSpec.Book.class)
    ));
    HttpResponse<List> response = flowable.blockingFirst();

    assertEquals(response.getStatus(), HttpStatus.OK);
    Optional<List> body = response.getBody();
    assertTrue(body.isPresent());

    List<HttpGetSpec.Book> list = body.get();
    assertEquals(list.size(), 1);
    assertTrue(list.get(0) instanceof HttpGetSpec.Book);

    client.stop();
    applicationContext.stop();
  }
}

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

@Test
public void testSimpleGet() {
  ApplicationContext applicationContext = ApplicationContext.run();
  EmbeddedServer server = applicationContext.getBean(EmbeddedServer.class).start();
  HttpClient client = new DefaultHttpClient(server.getURL());
  Flowable<HttpResponse<String>> flowable = Flowable.fromPublisher(client.exchange(
      HttpRequest.GET("/get/simple"), String.class
  ));
  HttpResponse<String> response = flowable.blockingFirst();
  Assert.assertEquals(response.getStatus(), HttpStatus.OK);
  Optional<String> body = response.getBody(String.class);
  assertTrue(body.isPresent());
  assertEquals(body.get(), "success");
  client.stop();
  applicationContext.stop();
}

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

private void stopServer() {
    try {
      Thread.sleep(WAIT_BEFORE_STOP);
    } catch (InterruptedException ex) {
      Thread.currentThread().interrupt();
    }
    this.context.stop();
  }
}

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

private void stopServer() {
    try {
      Thread.sleep(WAIT_BEFORE_STOP);
    } catch (InterruptedException ex) {
      Thread.currentThread().interrupt();
    }
    this.context.stop();
  }
}

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

@Override
public void stop() {
  if (isRunning()) {
    micronautContext.stop();
  }
}

代码示例来源: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;
  }
}

相关文章