use of io.micronaut.runtime.server.event.ServerShutdownEvent in project micronaut-core by micronaut-projects.
the class NettyHttpServer method stopInternal.
private void stopInternal() {
try {
if (shutdownParent) {
EventLoopGroupConfiguration parent = serverConfiguration.getParent();
if (parent != null) {
long quietPeriod = parent.getShutdownQuietPeriod().toMillis();
long timeout = parent.getShutdownTimeout().toMillis();
parentGroup.shutdownGracefully(quietPeriod, timeout, TimeUnit.MILLISECONDS).addListener(this::logShutdownErrorIfNecessary);
} else {
parentGroup.shutdownGracefully().addListener(this::logShutdownErrorIfNecessary);
}
}
if (shutdownWorker) {
workerGroup.shutdownGracefully().addListener(this::logShutdownErrorIfNecessary);
}
webSocketSessions.close();
applicationContext.getEventPublisher(ServerShutdownEvent.class).publishEvent(new ServerShutdownEvent(this));
if (serviceInstance != null) {
applicationContext.getEventPublisher(ServiceStoppedEvent.class).publishEvent(new ServiceStoppedEvent(serviceInstance));
}
if (isDefault) {
if (applicationContext.isRunning()) {
applicationContext.stop();
}
serverConfiguration.getMultipart().getLocation().ifPresent(dir -> DiskFileUpload.baseDirectory = null);
}
serverConfiguration.getMultipart().getLocation().ifPresent(dir -> DiskFileUpload.baseDirectory = null);
childHandler = null;
this.boundPorts.clear();
} catch (Throwable e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error stopping Micronaut server: " + e.getMessage(), e);
}
}
}
Aggregations