Commit 5b62b80b by 房斌

1等待时间,10ms 优化

2配置 ,url 不需要。引用公共的
parent 2e5d8dce
......@@ -36,31 +36,18 @@ public class ConfigCenter {
public static final Logger logger = LoggerFactory.getLogger(ConfigCenter.class);
@Value("${admin.registry.address:}")
@Value("${dubbo.registry.address:}")
public String registryAddress;
@Value("${admin.registry.group:dubbo}")
@Value("${dubbo.protocol.name}")
public String registryGroup;
@Value("${admin.config-center.group:dubbo}")
public String configCenterGroup;
@Value("${admin.config-center.username:}")
@Value("${dubbo.registry.username:}")
public String username;
@Value("${admin.config-center.password:}")
@Value("${dubbo.registry.password:}")
public String password;
@Value("${admin.patch:}")
@Value("${dubbo.monitorpatch:}")
public String patch;
public URL configCenterUrl;
public URL registryUrl;
public String getRegistryGroup() {
return registryGroup;
}
public void setRegistryGroup(String registryGroup) {
this.registryGroup = registryGroup;
}
public URL getRegistryUrl() {
return registryUrl;
}
......
......@@ -43,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
public class RegistryServerSync implements InitializingBean, DisposableBean, NotifyListener, CommandLineRunner {
public class RegistryServerSync extends Observable implements InitializingBean, DisposableBean, NotifyListener, CommandLineRunner {
public RegistryServerSync(Registry registry) {
this.registry=registry;
}
......@@ -83,6 +83,16 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
return registryCache;
}
volatile boolean signal=false;
public boolean isSignal() {
return signal;
}
public void setSignal(boolean signal) {
this.signal = signal;
}
@Override
public void afterPropertiesSet() throws Exception {
logger.info("Init Dubbo Admin Sync Cache...");
......@@ -119,15 +129,17 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
String group = url.getParameter(Constants.GROUP_KEY);
String version = url.getParameter(Constants.VERSION_KEY);
// NOTE: group and version in empty protocol is *
if (!Constants.ANY_VALUE.equals(group) && !Constants.ANY_VALUE.equals(version)) {
services.remove(url.getServiceKey());
if (!Constants.ANY_VALUE.equals(group) && !Constants.ANY_VALUE.equals(version)) {//移除带版本的key
// services.remove(url.getServiceKey());
removeAndNotice(services,url.getServiceKey());
} else {
for (Map.Entry<String, Map<String, URL>> serviceEntry : services.entrySet()) {
String service = serviceEntry.getKey();
if (Tool.getInterface(service).equals(url.getServiceInterface())
&& (Constants.ANY_VALUE.equals(group) || StringUtils.isEquals(group, Tool.getGroup(service)))
&& (Constants.ANY_VALUE.equals(version) || StringUtils.isEquals(version, Tool.getVersion(service)))) {
services.remove(service);//版本 和分组匹配就干掉?
services.remove(service);//如果版本和分组匹配就干掉
removeAndNotice(services,service);
}
}
}
......@@ -141,7 +153,7 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
services = new HashMap<>();
categories.put(category, services);
}
String service = url.getServiceKey();
String service = url.getServiceKey();//带版本
Map<String, URL> ids = services.get(service);
if (ids == null) {
ids = new HashMap<>();
......@@ -171,7 +183,8 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
Set<String> keys = new HashSet<String>(services.keySet());
for (String key : keys) { //接口
if (Tool.getInterface(key).equals(interfaceName) && !categoryEntry.getValue().entrySet().contains(key)) {
services.remove(key);
// services.remove(key);
removeAndNotice(services,key);
}
}
}
......@@ -219,5 +232,13 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
}
}
public void removeAndNotice(ConcurrentMap<String, Map<String, URL>> services,String serviceKey){
services.remove(serviceKey);
if(signal) {
this.setChanged();
this.notifyObservers(serviceKey);
}
}
}
......@@ -7,6 +7,7 @@ import com.secoo.mall.common.util.date.DateUtil;
import com.secoo.mall.common.util.log.LoggerUtil;
import com.secoo.mall.common.core.bean.gracefulshowtdownBean.ExecutorDetail;
import com.secoo.mall.common.core.bean.gracefulshowtdownBean.ExecutorDetails;
import com.secoo.mall.dubbo.monitor.dubbo.service.RegistryServerSync;
import com.secoo.mall.dubbo.service.impl.TomcatConnectShoutDownHock;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.config.DubboShutdownHook;
......@@ -34,6 +35,8 @@ public class GracefullyShoutDown implements CommandLineRunner, ApplicationListen
private ApplicationContext context;
// private ProviderService providerService ;
RegistryServerSync registryServerSync;
UpDatas dubboUpdata;
// public GracefullyShoutDown(TomcatConnectShoutDownHock tomcatConnectShoutDownHock,ProviderService providerService,UpDatas dubboUpdata){
......@@ -62,28 +65,29 @@ public class GracefullyShoutDown implements CommandLineRunner, ApplicationListen
}
//test-------------------------------------> begin
// ExecutorDetails result = new ExecutorDetails();
// result.setCode(0);
// List<ExecutorDetail> details = new ArrayList<ExecutorDetail>();
// result.setT(details);
// String ip = NetUtils.getIpByHost(NetUtils.getLocalAddress().getHostName());
// String name = ApplicationModel.getApplication();
// result.setIp(ip);
// result.setName(name);
//
// Map<String, StopService> map = this.context.getBeansOfType(StopService.class);
// if (map != null && map.size() > 0) {
// Set<StopService> ts = new TreeSet<StopService>();
// for (StopService service : map.values()) {
// if (!(service instanceof TomcatConnectShoutDownHock)) {
// ts.add(service);
// }
// }
// //按定义顺序执行
// Iterator<StopService> it = ts.iterator();
// while (it.hasNext()) {
// StopService service = (StopService) it.next();
ExecutorDetails result = new ExecutorDetails();
result.setCode(0);
List<ExecutorDetail> details = new ArrayList<ExecutorDetail>();
result.setT(details);
String ip = NetUtils.getIpByHost(NetUtils.getLocalAddress().getHostName());
String name = ApplicationModel.getApplication();
result.setIp(ip);
result.setName(name);
Map<String, StopService> map = this.context.getBeansOfType(StopService.class);
if (map != null && map.size() > 0) {
Set<StopService> ts = new TreeSet<StopService>();
for (StopService service : map.values()) {
if (!(service instanceof TomcatConnectShoutDownHock)) {
ts.add(service);
}
}
//按定义顺序执行
Iterator<StopService> it = ts.iterator();
while (it.hasNext()) {
StopService service = (StopService) it.next();
// ExecutorDetail one = (ExecutorDetail) service.stop();
// if (one != null) {
// details.add(one);
......@@ -91,21 +95,17 @@ public class GracefullyShoutDown implements CommandLineRunner, ApplicationListen
// result.setCode(-1);
// }
// }
//
// }
// } catch (Exception e) {
// LoggerUtil.error("matrix.GracefullyShoutDown.error", e);
// }
// try {
// dubboUpdata.upData(result);
// } catch (Exception e) {
// LoggerUtil.error("matrix.GracefullyShoutDown update .error data:" + JSON.toJSONString(result), e);
// }
// }
}
try {
dubboUpdata.upData(result);
} catch (Exception e) {
LoggerUtil.error("matrix.GracefullyShoutDown update .error data:" + JSON.toJSONString(result), e);
}
//test------------------------------------->
//test------------------------------------->
}
}
......
package com.secoo.mall.dubbo.spring.boot.autoconfigure;
import com.secoo.mall.common.core.service.UpDatas;
import com.secoo.mall.common.util.string.StringUtil;
import com.secoo.mall.dubbo.monitor.config.ConfigCenter;
import com.secoo.mall.dubbo.monitor.dubbo.service.ProviderService;
import com.secoo.mall.dubbo.monitor.dubbo.service.RegistryServerSync;
......@@ -39,21 +40,29 @@ public class MatrixGracefulShutDownAutoConfiguration {
DubboUpdata transport= new DubboUpdata();
URL url =configCenter.formUrl(configCenter.registryAddress, configCenter.registryGroup, configCenter.username, configCenter.password);
transport.setUrl(url);
if(StringUtil.isEmpty(configCenter.patch)){
configCenter.patch="/monitorZ";
}
transport.setPath(configCenter.patch);
return transport;
}
@Bean
@ConditionalOnClass({ProviderService.class,RegistryServerSync.class})
@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${dubbo.registry.address:}')")
DubboCustomerDownHock createDubboConsumerDownHock(ProviderService providerService) {
return new DubboCustomerDownHock(providerService);
DubboCustomerDownHock createDubboConsumerDownHock(ProviderService providerService, RegistryServerSync registryServerSync) {
DubboCustomerDownHock hock= new DubboCustomerDownHock(providerService);
registryServerSync.addObserver(hock);
hock.setRegistryServerSync(registryServerSync);
return hock;
}
@Bean
@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${dubbo.registry.address:}')")
public RegistryServerSync createSynObject(Registry registry) {
return new RegistryServerSync(registry);
RegistryServerSync r= new RegistryServerSync(registry);
return r;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment