org.zodiac.eureka.client.EurekaAppRegistration Maven / Gradle / Ivy
package org.zodiac.eureka.client;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zodiac.commons.util.spring.Springs;
import org.zodiac.core.application.AppInstance;
import org.zodiac.core.application.ApplicationInfoMetadata;
import org.zodiac.core.bootstrap.registry.AppRegistration;
import org.zodiac.eureka.base.instance.AppEurekaInstanceConfig;
import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaClientConfig;
public class EurekaAppRegistration implements AppRegistration {
private static final Logger log = LoggerFactory.getLogger(EurekaAppRegistration.class);
private final EurekaClient eurekaClient;
private final AtomicReference appEurekaClientRef = new AtomicReference<>();
private final EurekaClientConfig eurekaClientConfig;
private final AppEurekaInstanceConfig eurekaInstanceConfig;
private final ApplicationInfoManager applicationInfoManager;
private HealthCheckHandler healthCheckHandler;
private final AppInstance appInstance;
public EurekaAppRegistration(AppEurekaInstanceConfig eurekaInstanceConfig, EurekaClientConfig eurekaClientConfig,
EurekaClient eurekaClient, ApplicationInfoManager applicationInfoManager, HealthCheckHandler healthCheckHandler,
AppInstance appInstance) {
this.eurekaClientConfig = eurekaClientConfig;
this.eurekaClient = eurekaClient;
this.eurekaInstanceConfig = eurekaInstanceConfig;
this.applicationInfoManager = applicationInfoManager;
this.healthCheckHandler = healthCheckHandler;
this.appInstance = appInstance;
}
@Override
public String getAppServiceId() {
return this.eurekaInstanceConfig.getAppname();
}
@Override
public String getAppHost() {
return this.eurekaInstanceConfig.getHostName();
}
@Override
public Integer getAppPort() {
return this.eurekaInstanceConfig.isNonSecurePortEnabled() ? this.eurekaInstanceConfig.getNonSecurePort()
: this.eurekaInstanceConfig.getSecurePort();
}
@Override
public URI getAppUri() {
try {
return new URI(this.eurekaInstanceConfig.getHomePageUrl());
} catch (URISyntaxException e) {
log.error("{}", e);
return null;
}
}
@Override
public String getAppGroup() {
return this.eurekaInstanceConfig.getAppGroupName();
}
@Override
public String getModule() {
return this.eurekaInstanceConfig.getModule();
}
@Override
public String getRegion() {
return this.eurekaClientConfig.getRegion();
}
@Override
public String getZone() {
return this.eurekaInstanceConfig.getZone();
}
@Override
public String getCluster() {
return this.eurekaInstanceConfig.getCluster();
}
@Override
public String getEnvType() {
return this.eurekaInstanceConfig.getEnvType();
}
@Override
public String getIpAddress() {
return this.eurekaInstanceConfig.getIpAddress();
}
@Override
public String getDescription() {
return this.appInstance.getDescription();
}
@Override
public ApplicationInfoMetadata getAppMetadata() {
return this.appInstance.getAppMetadata();
}
@Override
public EurekaAppRegistration setServerPort(Integer port) {
this.appInstance.setServerPort(port);
return this;
}
@Override
public int getWeight() {
return this.appInstance.getWeight();
}
public AppEurekaClient getEurekaClient() {
if (this.appEurekaClientRef.get() == null) {
try {
this.appEurekaClientRef.compareAndSet(null,
Springs.getTargetObject(eurekaClient, AppEurekaClient.class));
} catch (Exception e) {
log.error("error getting AppEurekaClient", e);
}
}
return this.appEurekaClientRef.get();
}
public AppEurekaInstanceConfig getInstanceConfig() {
return eurekaInstanceConfig;
}
public ApplicationInfoManager getApplicationInfoManager() {
return applicationInfoManager;
}
public HealthCheckHandler getHealthCheckHandler() {
return healthCheckHandler;
}
public void setHealthCheckHandler(HealthCheckHandler healthCheckHandler) {
this.healthCheckHandler = healthCheckHandler;
}
public int getNonSecurePort() {
return this.eurekaInstanceConfig.getNonSecurePort();
}
public int getSecurePort() {
return this.eurekaInstanceConfig.getSecurePort();
}
@Override
public String getRole() {
return appInstance.getRole();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy