Search in sources :

Example 1 with ServerShutdownEvent

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);
        }
    }
}
Also used : ServerShutdownEvent(io.micronaut.runtime.server.event.ServerShutdownEvent) DefaultEventLoopGroupConfiguration(io.micronaut.http.netty.channel.DefaultEventLoopGroupConfiguration) EventLoopGroupConfiguration(io.micronaut.http.netty.channel.EventLoopGroupConfiguration) ServiceStoppedEvent(io.micronaut.discovery.event.ServiceStoppedEvent)

Aggregations

ServiceStoppedEvent (io.micronaut.discovery.event.ServiceStoppedEvent)1 DefaultEventLoopGroupConfiguration (io.micronaut.http.netty.channel.DefaultEventLoopGroupConfiguration)1 EventLoopGroupConfiguration (io.micronaut.http.netty.channel.EventLoopGroupConfiguration)1 ServerShutdownEvent (io.micronaut.runtime.server.event.ServerShutdownEvent)1