Search in sources :

Example 1 with ServiceStoppedEvent

use of io.micronaut.discovery.event.ServiceStoppedEvent 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)

Example 2 with ServiceStoppedEvent

use of io.micronaut.discovery.event.ServiceStoppedEvent in project micronaut-core by micronaut-projects.

the class AutoRegistration method onApplicationEvent.

@Override
public void onApplicationEvent(AbstractServiceInstanceEvent event) {
    if (registrationConfiguration.isEnabled()) {
        if (event instanceof ServiceReadyEvent) {
            register(event.getSource());
        } else if (event instanceof ServiceStoppedEvent) {
            if (registrationConfiguration.isDeregister()) {
                deregister(event.getSource());
            }
        } else if (event instanceof HeartbeatEvent) {
            HeartbeatEvent heartbeatEvent = (HeartbeatEvent) event;
            pulsate(event.getSource(), heartbeatEvent.getStatus());
        }
    }
}
Also used : HeartbeatEvent(io.micronaut.health.HeartbeatEvent) ServiceReadyEvent(io.micronaut.discovery.event.ServiceReadyEvent) ServiceStoppedEvent(io.micronaut.discovery.event.ServiceStoppedEvent)

Aggregations

ServiceStoppedEvent (io.micronaut.discovery.event.ServiceStoppedEvent)2 ServiceReadyEvent (io.micronaut.discovery.event.ServiceReadyEvent)1 HeartbeatEvent (io.micronaut.health.HeartbeatEvent)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