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);
}
}
}
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());
}
}
}
Aggregations