Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,53 @@

package org.springframework.cloud.netflix.eureka.server;

import com.netflix.eureka.EurekaServerConfig;
import jakarta.servlet.ServletContext;
import java.util.concurrent.CompletableFuture;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaServerStartedEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.context.ServletContextAware;

import com.netflix.eureka.EurekaServerConfig;

import jakarta.servlet.ServletContext;

/**
* @author Dave Syer
*/
@Configuration(proxyBeanMethods = false)
public class EurekaServerInitializerConfiguration implements ServletContextAware, SmartLifecycle, Ordered {
public class EurekaServerInitializerConfiguration implements SmartLifecycle, Ordered {

private static final Log log = LogFactory.getLog(EurekaServerInitializerConfiguration.class);

@Autowired
private EurekaServerConfig eurekaServerConfig;
private static final int ORDER = 1;

private ServletContext servletContext;
private final EurekaServerConfig eurekaServerConfig;

@Autowired
private ApplicationContext applicationContext;
private final ServletContext servletContext;

@Autowired
private EurekaServerBootstrap eurekaServerBootstrap;
private final ApplicationEventPublisher applicationEventPublisher;

private boolean running;
private final EurekaServerBootstrap eurekaServerBootstrap;

private final int order = 1;
private volatile boolean running;

@Override
public void setServletContext(ServletContext servletContext) {
public EurekaServerInitializerConfiguration(EurekaServerConfig eurekaServerConfig, ServletContext servletContext,
ApplicationEventPublisher applicationEventPublisher, EurekaServerBootstrap eurekaServerBootstrap) {
this.eurekaServerConfig = eurekaServerConfig;
this.servletContext = servletContext;
this.applicationEventPublisher = applicationEventPublisher;
this.eurekaServerBootstrap = eurekaServerBootstrap;
}

@Override
public void start() {
new Thread(() -> {
CompletableFuture.runAsync(() -> {
try {
// TODO: is this class even needed now?
eurekaServerBootstrap.contextInitialized(EurekaServerInitializerConfiguration.this.servletContext);
Expand All @@ -75,15 +76,15 @@ public void start() {
// Help!
log.error("Could not initialize Eureka servlet context", ex);
}
}).start();
});
}

private EurekaServerConfig getEurekaServerConfig() {
return this.eurekaServerConfig;
}

private void publish(ApplicationEvent event) {
this.applicationContext.publishEvent(event);
this.applicationEventPublisher.publishEvent(event);
}

@Override
Expand All @@ -102,14 +103,9 @@ public int getPhase() {
return 0;
}

@Override
public boolean isAutoStartup() {
return true;
}

@Override
public int getOrder() {
return this.order;
return ORDER;
}

}