org.zodiac.autoconfigure.cluster.AppClusterAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.cluster;
import java.util.List;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.core.application.AppContext;
import org.zodiac.core.cluster.AppClusterCustomizer;
import org.zodiac.core.cluster.AppClusterService;
import org.zodiac.core.cluster.AppClusterServiceProvider;
import org.zodiac.core.cluster.DefaultAppClusterService;
import org.zodiac.core.context.config.annotation.AppRefreshScope;
import org.zodiac.core.event.context.AppRefreshEvent;
import org.zodiac.core.event.metadata.AppClusterMetadataListener;
import org.zodiac.core.event.metadata.MetadataListener;
@SpringBootConfiguration
//@EnableConfigurationProperties(value = {AppClusterInfoProperties.class})
public class AppClusterAutoConfiguration {
public AppClusterAutoConfiguration() {
super();
}
@Bean
@AppRefreshScope
@ConditionalOnMissingBean
@ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SPRING_CLUSTER_PREFIX)
protected AppClusterInfoProperties appClusterInfoProperties() {
return new AppClusterInfoProperties();
}
@Bean
@ConditionalOnMissingBean
protected AppClusterServiceProvider clusterServiceProvider(ObjectProvider> clusterCustomizers) {
return new AppClusterServiceProvider(clusterCustomizers.getIfAvailable());
}
@Bean
@ConditionalOnMissingBean
protected MetadataListener appClusterMetadataListener() {
return new AppClusterMetadataListener();
}
@Bean
@ConditionalOnMissingBean
protected AppClusterService clusterService(AppClusterInfoProperties appClusterInfoProperties, AppContext appContext) {
return new DefaultAppClusterService(appClusterInfoProperties, appContext);
}
}