Search in sources :

Example 1 with ServiceReadyEvent

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

the class NettyHttpServer method fireStartupEvents.

private void fireStartupEvents() {
    Optional<String> applicationName = serverConfiguration.getApplicationConfiguration().getName();
    applicationContext.getEventPublisher(ServerStartupEvent.class).publishEvent(new ServerStartupEvent(this));
    applicationName.ifPresent(id -> {
        this.serviceInstance = applicationContext.createBean(NettyEmbeddedServerInstance.class, id, this);
        applicationContext.getEventPublisher(ServiceReadyEvent.class).publishEvent(new ServiceReadyEvent(serviceInstance));
    });
}
Also used : ServiceReadyEvent(io.micronaut.discovery.event.ServiceReadyEvent) AsciiString(io.netty.util.AsciiString) ServerStartupEvent(io.micronaut.runtime.server.event.ServerStartupEvent)

Example 2 with ServiceReadyEvent

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

Example 3 with ServiceReadyEvent

use of io.micronaut.discovery.event.ServiceReadyEvent in project micronaut-grpc by micronaut-projects.

the class GrpcEmbeddedServer method start.

@Override
public EmbeddedServer start() {
    if (running.compareAndSet(false, true)) {
        try {
            server.start();
            eventPublisher.publishEvent(new ServerStartupEvent(this));
            getApplicationConfiguration().getName().ifPresent(id -> {
                Map<String, String> metadata = new LinkedHashMap<>();
                if (computeInstanceMetadataResolver != null) {
                    final Optional<ComputeInstanceMetadata> cim = computeInstanceMetadataResolver.resolve(applicationContext.getEnvironment());
                    cim.ifPresent(computeInstanceMetadata -> metadata.putAll(computeInstanceMetadata.getMetadata()));
                }
                this.serviceInstance = new GrpcServerInstance(this, id, getURI(), metadata, metadataContributors, grpcConfiguration);
                applicationContext.publishEvent(new ServiceReadyEvent(serviceInstance));
            });
        } catch (IOException e) {
            throw new ApplicationStartupException("Unable to start GRPC server: " + e.getMessage(), e);
        }
    }
    return this;
}
Also used : ServiceReadyEvent(io.micronaut.discovery.event.ServiceReadyEvent) IOException(java.io.IOException) ServerStartupEvent(io.micronaut.runtime.server.event.ServerStartupEvent) ApplicationStartupException(io.micronaut.runtime.exceptions.ApplicationStartupException) ComputeInstanceMetadata(io.micronaut.discovery.cloud.ComputeInstanceMetadata) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ServiceReadyEvent (io.micronaut.discovery.event.ServiceReadyEvent)3 ServerStartupEvent (io.micronaut.runtime.server.event.ServerStartupEvent)2 ComputeInstanceMetadata (io.micronaut.discovery.cloud.ComputeInstanceMetadata)1 ServiceStoppedEvent (io.micronaut.discovery.event.ServiceStoppedEvent)1 HeartbeatEvent (io.micronaut.health.HeartbeatEvent)1 ApplicationStartupException (io.micronaut.runtime.exceptions.ApplicationStartupException)1 AsciiString (io.netty.util.AsciiString)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1