修改代码风格为eclipse风格

pull/898/head
xiejiashuai 7 years ago
parent d39c7e9b8f
commit 234aa773e2

@ -16,12 +16,12 @@
package org.springframework.cloud.alibaba.sentinel;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.core.Ordered;
import java.util.List;
/**
* @author xiaojing
* @author hengyunabc
@ -30,245 +30,245 @@ import java.util.List;
@ConfigurationProperties(prefix = SentinelConstants.PROPERTY_PREFIX)
public class SentinelProperties {
/**
*
*/
private boolean eager = false;
/**
* Enable sentinel auto configure, the default value is true
*/
private boolean enabled = true;
/**
*
*/
private String charset = "UTF-8";
/**
*
*/
@NestedConfigurationProperty
private Transport transport = new Transport();
/**
*
*/
@NestedConfigurationProperty
private Metric metric = new Metric();
/**
* web
*/
@NestedConfigurationProperty
private Servlet servlet = new Servlet();
/**
*
*/
@NestedConfigurationProperty
private Filter filter = new Filter();
@NestedConfigurationProperty
private Flow flow = new Flow();
/**
*
*/
private boolean eager = false;
/**
* Enable sentinel auto configure, the default value is true
*/
private boolean enabled = true;
/**
*
*/
private String charset = "UTF-8";
/**
*
*/
@NestedConfigurationProperty
private Transport transport = new Transport();
/**
*
*/
@NestedConfigurationProperty
private Metric metric = new Metric();
/**
* web
*/
@NestedConfigurationProperty
private Servlet servlet = new Servlet();
/**
*
*/
@NestedConfigurationProperty
private Filter filter = new Filter();
@NestedConfigurationProperty
private Flow flow = new Flow();
public boolean isEager() {
return eager;
}
public void setEager(boolean eager) {
this.eager = eager;
}
public Flow getFlow() {
return flow;
}
public void setFlow(Flow flow) {
this.flow = flow;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
public Transport getTransport() {
return transport;
}
public void setTransport(Transport transport) {
this.transport = transport;
}
public Metric getMetric() {
return metric;
}
public void setMetric(Metric metric) {
this.metric = metric;
}
public Servlet getServlet() {
return servlet;
}
public void setServlet(Servlet servlet) {
this.servlet = servlet;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Filter getFilter() {
return filter;
}
public void setFilter(Filter filter) {
this.filter = filter;
}
public static class Flow {
/**
*
*/
private String coldFactor = "3";
public String getColdFactor() {
return coldFactor;
}
public void setColdFactor(String coldFactor) {
this.coldFactor = coldFactor;
}
public boolean isEager() {
return eager;
}
}
public void setEager(boolean eager) {
this.eager = eager;
}
public Flow getFlow() {
return flow;
}
public void setFlow(Flow flow) {
this.flow = flow;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
public Transport getTransport() {
return transport;
}
public static class Servlet {
public void setTransport(Transport transport) {
this.transport = transport;
}
public Metric getMetric() {
return metric;
}
public void setMetric(Metric metric) {
this.metric = metric;
}
public Servlet getServlet() {
return servlet;
}
public void setServlet(Servlet servlet) {
this.servlet = servlet;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Filter getFilter() {
return filter;
}
public void setFilter(Filter filter) {
this.filter = filter;
}
public static class Flow {
/**
*
*/
private String coldFactor = "3";
public String getColdFactor() {
return coldFactor;
}
public void setColdFactor(String coldFactor) {
this.coldFactor = coldFactor;
}
/**
* url
*/
private String blockPage;
}
public static class Servlet {
public String getBlockPage() {
return blockPage;
}
/**
* url
*/
private String blockPage;
public void setBlockPage(String blockPage) {
this.blockPage = blockPage;
}
}
public String getBlockPage() {
return blockPage;
}
public static class Metric {
public void setBlockPage(String blockPage) {
this.blockPage = blockPage;
}
}
/**
*
*/
private String fileSingleSize;
public static class Metric {
/**
*
*/
private String fileTotalCount;
/**
*
*/
private String fileSingleSize;
public String getFileSingleSize() {
return fileSingleSize;
}
/**
*
*/
private String fileTotalCount;
public void setFileSingleSize(String fileSingleSize) {
this.fileSingleSize = fileSingleSize;
}
public String getFileSingleSize() {
return fileSingleSize;
}
public String getFileTotalCount() {
return fileTotalCount;
}
public void setFileSingleSize(String fileSingleSize) {
this.fileSingleSize = fileSingleSize;
}
public void setFileTotalCount(String fileTotalCount) {
this.fileTotalCount = fileTotalCount;
}
}
public String getFileTotalCount() {
return fileTotalCount;
}
public static class Transport {
public void setFileTotalCount(String fileTotalCount) {
this.fileTotalCount = fileTotalCount;
}
}
/**
* sentinel api port,default value is 8721
*/
private String port = "8721";
public static class Transport {
/**
* Sentinel dashboard address, won't try to connect dashboard when address is empty
*/
private String dashboard = "";
/**
* sentinel api port,default value is 8721
*/
private String port = "8721";
/**
* DashBord
*/
private String heartbeatIntervalMs;
/**
* Sentinel dashboard address, won't try to connect dashboard when address is
* empty
*/
private String dashboard = "";
public String getHeartbeatIntervalMs() {
return heartbeatIntervalMs;
}
/**
* DashBord
*/
private String heartbeatIntervalMs;
public void setHeartbeatIntervalMs(String heartbeatIntervalMs) {
this.heartbeatIntervalMs = heartbeatIntervalMs;
}
public String getHeartbeatIntervalMs() {
return heartbeatIntervalMs;
}
public String getPort() {
return port;
}
public void setHeartbeatIntervalMs(String heartbeatIntervalMs) {
this.heartbeatIntervalMs = heartbeatIntervalMs;
}
public void setPort(String port) {
this.port = port;
}
public String getPort() {
return port;
}
public String getDashboard() {
return dashboard;
}
public void setPort(String port) {
this.port = port;
}
public void setDashboard(String dashboard) {
this.dashboard = dashboard;
}
public String getDashboard() {
return dashboard;
}
}
public void setDashboard(String dashboard) {
this.dashboard = dashboard;
}
public static class Filter {
}
/**
* Sentinel filter chain order.
*/
private int order = Ordered.HIGHEST_PRECEDENCE;
public static class Filter {
/**
* URL pattern for sentinel filter,default is /*
*/
private List<String> urlPatterns;
/**
* Sentinel filter chain order.
*/
private int order = Ordered.HIGHEST_PRECEDENCE;
public int getOrder() {
return this.order;
}
public void setOrder(int order) {
this.order = order;
}
public List<String> getUrlPatterns() {
return urlPatterns;
}
public void setUrlPatterns(List<String> urlPatterns) {
this.urlPatterns = urlPatterns;
}
}
/**
* URL pattern for sentinel filter,default is /*
*/
private List<String> urlPatterns;
public int getOrder() {
return this.order;
}
public void setOrder(int order) {
this.order = order;
}
public List<String> getUrlPatterns() {
return urlPatterns;
}
public void setUrlPatterns(List<String> urlPatterns) {
this.urlPatterns = urlPatterns;
}
}
}

@ -16,7 +16,11 @@
package org.springframework.cloud.alibaba.sentinel;
import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.Filter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -27,9 +31,7 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.Filter;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
/**
* @author xiaojing
@ -40,38 +42,38 @@ import java.util.List;
@EnableConfigurationProperties(SentinelProperties.class)
public class SentinelWebAutoConfiguration {
private static final Logger logger = LoggerFactory
.getLogger(SentinelWebAutoConfiguration.class);
private static final Logger logger = LoggerFactory
.getLogger(SentinelWebAutoConfiguration.class);
@Autowired
private SentinelProperties properties;
@Autowired
private SentinelProperties properties;
@Bean
public FilterRegistrationBean servletRequestListener() {
FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
@Bean
public FilterRegistrationBean servletRequestListener() {
FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
SentinelProperties.Filter filterConfig = properties.getFilter();
SentinelProperties.Filter filterConfig = properties.getFilter();
if (null == filterConfig) {
filterConfig = new SentinelProperties.Filter();
properties.setFilter(filterConfig);
}
if (null == filterConfig) {
filterConfig = new SentinelProperties.Filter();
properties.setFilter(filterConfig);
}
if (filterConfig.getUrlPatterns() == null
|| filterConfig.getUrlPatterns().isEmpty()) {
List<String> defaultPatterns = new ArrayList<>();
defaultPatterns.add("/*");
filterConfig.setUrlPatterns(defaultPatterns);
}
if (filterConfig.getUrlPatterns() == null
|| filterConfig.getUrlPatterns().isEmpty()) {
List<String> defaultPatterns = new ArrayList<>();
defaultPatterns.add("/*");
filterConfig.setUrlPatterns(defaultPatterns);
}
registration.addUrlPatterns(filterConfig.getUrlPatterns().toArray(new String[0]));
Filter filter = new CommonFilter();
registration.setFilter(filter);
registration.setOrder(filterConfig.getOrder());
logger.info("[Sentinel Starter] register Sentinel with urlPatterns: {}.",
filterConfig.getUrlPatterns());
return registration;
registration.addUrlPatterns(filterConfig.getUrlPatterns().toArray(new String[0]));
Filter filter = new CommonFilter();
registration.setFilter(filter);
registration.setOrder(filterConfig.getOrder());
logger.info("[Sentinel Starter] register Sentinel with urlPatterns: {}.",
filterConfig.getUrlPatterns());
return registration;
}
}
}

@ -16,17 +16,10 @@
package org.springframework.cloud.alibaba.sentinel.custom;
import com.alibaba.csp.sentinel.Env;
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler;
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner;
import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig;
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.init.InitExecutor;
import com.alibaba.csp.sentinel.node.NodeBuilder;
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
import com.alibaba.csp.sentinel.util.AppNameUtil;
import java.util.Optional;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@ -39,8 +32,17 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.util.Optional;
import com.alibaba.csp.sentinel.Env;
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler;
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner;
import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig;
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.init.InitExecutor;
import com.alibaba.csp.sentinel.node.NodeBuilder;
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
import com.alibaba.csp.sentinel.util.AppNameUtil;
/**
* @author xiaojing
@ -51,79 +53,94 @@ import java.util.Optional;
@EnableConfigurationProperties(SentinelProperties.class)
public class SentinelAutoConfiguration {
@Value("${project.name:${spring.application.name:}}")
private String projectName;
@Autowired
private SentinelProperties properties;
@Autowired
private Optional<UrlCleaner> urlCleanerOptional;
@Autowired
private Optional<UrlBlockHandler> urlBlockHandlerOptional;
@PostConstruct
private void init() {
if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME))) {
System.setProperty(AppNameUtil.APP_NAME, projectName);
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT)) && StringUtils.hasText(properties.getTransport().getPort())) {
System.setProperty(TransportConfig.SERVER_PORT, properties.getTransport().getPort());
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.CONSOLE_SERVER)) && StringUtils.hasText(properties.getTransport().getDashboard())) {
System.setProperty(TransportConfig.CONSOLE_SERVER, properties.getTransport().getDashboard());
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS)) && StringUtils.hasText(properties.getTransport().getHeartbeatIntervalMs())) {
System.setProperty(TransportConfig.HEARTBEAT_INTERVAL_MS, properties.getTransport().getHeartbeatIntervalMs());
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.CHARSET)) && StringUtils.hasText(properties.getCharset())) {
System.setProperty(SentinelConfig.CHARSET, properties.getCharset());
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE)) && StringUtils.hasText(properties.getMetric().getFileSingleSize())) {
System.setProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE, properties.getMetric().getFileSingleSize());
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT)) && StringUtils.hasText(properties.getMetric().getFileTotalCount())) {
System.setProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT, properties.getMetric().getFileTotalCount());
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.COLD_FACTOR)) && StringUtils.hasText(properties.getFlow().getColdFactor())) {
System.setProperty(SentinelConfig.COLD_FACTOR, properties.getFlow().getColdFactor());
}
if (StringUtils.hasText(properties.getServlet().getBlockPage())) {
WebServletConfig.setBlockPage(properties.getServlet().getBlockPage());
}
urlBlockHandlerOptional.ifPresent(WebCallbackManager::setUrlBlockHandler);
urlCleanerOptional.ifPresent(WebCallbackManager::setUrlCleaner);
InitExecutor.doInit();
// earlier initialize
if (properties.isEager()) {
NodeBuilder nodeBuilder = Env.nodeBuilder;
}
}
@Bean
@ConditionalOnMissingBean
public SentinelResourceAspect sentinelResourceAspect() {
return new SentinelResourceAspect();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
public SentinelBeanPostProcessor sentinelBeanPostProcessor() {
return new SentinelBeanPostProcessor();
}
@Bean
@ConditionalOnMissingBean
public SentinelDataSourcePostProcessor sentinelDataSourcePostProcessor() {
return new SentinelDataSourcePostProcessor();
}
@Value("${project.name:${spring.application.name:}}")
private String projectName;
@Autowired
private SentinelProperties properties;
@Autowired
private Optional<UrlCleaner> urlCleanerOptional;
@Autowired
private Optional<UrlBlockHandler> urlBlockHandlerOptional;
@PostConstruct
private void init() {
if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME))) {
System.setProperty(AppNameUtil.APP_NAME, projectName);
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))
&& StringUtils.hasText(properties.getTransport().getPort())) {
System.setProperty(TransportConfig.SERVER_PORT,
properties.getTransport().getPort());
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.CONSOLE_SERVER))
&& StringUtils.hasText(properties.getTransport().getDashboard())) {
System.setProperty(TransportConfig.CONSOLE_SERVER,
properties.getTransport().getDashboard());
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS))
&& StringUtils
.hasText(properties.getTransport().getHeartbeatIntervalMs())) {
System.setProperty(TransportConfig.HEARTBEAT_INTERVAL_MS,
properties.getTransport().getHeartbeatIntervalMs());
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.CHARSET))
&& StringUtils.hasText(properties.getCharset())) {
System.setProperty(SentinelConfig.CHARSET, properties.getCharset());
}
if (StringUtils
.isEmpty(System.getProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE))
&& StringUtils.hasText(properties.getMetric().getFileSingleSize())) {
System.setProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE,
properties.getMetric().getFileSingleSize());
}
if (StringUtils
.isEmpty(System.getProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT))
&& StringUtils.hasText(properties.getMetric().getFileTotalCount())) {
System.setProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT,
properties.getMetric().getFileTotalCount());
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.COLD_FACTOR))
&& StringUtils.hasText(properties.getFlow().getColdFactor())) {
System.setProperty(SentinelConfig.COLD_FACTOR,
properties.getFlow().getColdFactor());
}
if (StringUtils.hasText(properties.getServlet().getBlockPage())) {
WebServletConfig.setBlockPage(properties.getServlet().getBlockPage());
}
urlBlockHandlerOptional.ifPresent(WebCallbackManager::setUrlBlockHandler);
urlCleanerOptional.ifPresent(WebCallbackManager::setUrlCleaner);
InitExecutor.doInit();
// earlier initialize
if (properties.isEager()) {
NodeBuilder nodeBuilder = Env.nodeBuilder;
}
}
@Bean
@ConditionalOnMissingBean
public SentinelResourceAspect sentinelResourceAspect() {
return new SentinelResourceAspect();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
public SentinelBeanPostProcessor sentinelBeanPostProcessor() {
return new SentinelBeanPostProcessor();
}
@Bean
@ConditionalOnMissingBean
public SentinelDataSourcePostProcessor sentinelDataSourcePostProcessor() {
return new SentinelDataSourcePostProcessor();
}
}

Loading…
Cancel
Save