Commit 107c2332 by 房斌

解决depender依赖 顺序问题

parent 47bed17b
......@@ -38,6 +38,9 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
public class RegistryServerSync implements InitializingBean, DisposableBean, NotifyListener, CommandLineRunner {
public RegistryServerSync(Registry registry) {
this.registry=registry;
}
private static final Logger logger = LoggerFactory.getLogger(RegistryServerSync.class);
......@@ -65,9 +68,11 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
* registryCache
*/
private final ConcurrentMap<String, ConcurrentMap<String, Map<String, URL>>> registryCache = new ConcurrentHashMap<>();
@Autowired
// @Autowired
private Registry registry;
public ConcurrentMap<String, ConcurrentMap<String, Map<String, URL>>> getRegistryCache() {
return registryCache;
}
......
......@@ -31,12 +31,33 @@ public class AbstractService {
protected static final Logger logger = LoggerFactory.getLogger(AbstractService.class);
@Autowired
//@Autowired
protected Registry registry;
@Autowired
// @Autowired
private RegistryServerSync sync;
public AbstractService(Registry registry, RegistryServerSync sync) {
this.registry=registry;
this.sync=sync;
}
public Registry getRegistry() {
return registry;
}
public void setRegistry(Registry registry) {
this.registry = registry;
}
public RegistryServerSync getSync() {
return sync;
}
public void setSync(RegistryServerSync sync) {
this.sync = sync;
}
public ConcurrentMap<String, ConcurrentMap<String, Map<String, URL>>> getRegistryCache() {
return sync.getRegistryCache();
}
......
......@@ -20,8 +20,10 @@ package com.secoo.mall.dubbo.monitor.dubbo.service.impl;
import com.secoo.mall.dubbo.monitor.dubbo.Constants.Constants;
import com.secoo.mall.dubbo.monitor.dubbo.model.domain.Consumer;
import com.secoo.mall.dubbo.monitor.dubbo.service.ConsumerService;
import com.secoo.mall.dubbo.monitor.dubbo.service.RegistryServerSync;
import com.secoo.mall.dubbo.monitor.utils.SyncUtils;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.registry.Registry;
import org.springframework.stereotype.Component;
import java.util.HashMap;
......@@ -31,6 +33,10 @@ import java.util.Map;
@Component
public class ConsumerServiceImpl extends AbstractService implements ConsumerService {
public ConsumerServiceImpl(Registry registry, RegistryServerSync sync) {
super(registry, sync);
}
@Override
public List<Consumer> findByService(String service) {
return SyncUtils.url2ConsumerList(findConsumerUrlByService(service));
......
......@@ -25,11 +25,13 @@ import com.secoo.mall.dubbo.monitor.dubbo.exception.ParamValidationException;
import com.secoo.mall.dubbo.monitor.dubbo.model.domain.Provider;
import com.secoo.mall.dubbo.monitor.dubbo.model.dto.ServiceDTO;
import com.secoo.mall.dubbo.monitor.dubbo.service.ProviderService;
import com.secoo.mall.dubbo.monitor.dubbo.service.RegistryServerSync;
import com.secoo.mall.dubbo.monitor.utils.Pair;
import com.secoo.mall.dubbo.monitor.utils.ParseUtils;
import com.secoo.mall.dubbo.monitor.utils.SyncUtils;
import com.secoo.mall.dubbo.monitor.utils.Tool;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.registry.Registry;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
......@@ -42,7 +44,9 @@ import java.util.stream.Collectors;
@Service
public class ProviderServiceImpl extends AbstractService implements ProviderService {
public ProviderServiceImpl(Registry registry, RegistryServerSync sync) {
super(registry,sync);
}
//注册 服务
@Override
......
......@@ -23,11 +23,11 @@ import java.util.List;
public class DubboCustomerDownHock extends AbstractStop {
@Autowired
private final ProviderService providerService;
//@Autowired
private ProviderService providerService;
public DubboCustomerDownHock() {
providerService = null;
public DubboCustomerDownHock(ProviderService providerService ) {
this.providerService = providerService;
}
@Override
......@@ -79,11 +79,11 @@ public class DubboCustomerDownHock extends AbstractStop {
}
}
DubboShutdownHook.getDubboShutdownHook().doDestroy();
} catch (Exception e) {
DubboShutdownHook.getDubboShutdownHook().doDestroy();
detail.setCode(-1);
str.add(" error :matirx-monitor offDubbo " + e.toString() + StringUtil.line());
}finally {
DubboShutdownHook.getDubboShutdownHook().doDestroy();
}
detail.setEndTime(DateUtil.getDateTime());
return detail;
......
......@@ -35,15 +35,22 @@ import static org.springframework.context.support.AbstractApplicationContext.APP
public class GracefullyShoutDown implements CommandLineRunner, ApplicationListener<ContextClosedEvent>, TomcatConnectorCustomizer, ApplicationContextAware {
private static final int TIMEOUT = 10;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
// @Autowired
ServletConnectShoutDownHock servletConnectShoutDownHock;
private ApplicationContext context;
@Autowired
private final ProviderService providerService = null;
// @Autowired
private ProviderService providerService ;
@Autowired
// @Autowired
UpDatas dubboUpdata;
public GracefullyShoutDown(ServletConnectShoutDownHock servletConnectShoutDownHock,ProviderService providerService,UpDatas dubboUpdata){
this.servletConnectShoutDownHock=servletConnectShoutDownHock;
this.providerService=providerService;
this.dubboUpdata=dubboUpdata;
}
//容器初始化后执行
@Override
......
......@@ -11,6 +11,8 @@ import com.secoo.mall.dubbo.service.impl.ServletConnectShoutDownHock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.registry.Registry;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -18,22 +20,11 @@ import org.springframework.context.annotation.DependsOn;
@Configuration
@EnableDubbo
public class MatrixGracefulShutDownAutoConfiguration {
public class MatrixGracefulShutDownAutoConfiguration {
@Bean
public GracefullyShoutDown createGraceObject() {
return new GracefullyShoutDown();
}
@Bean
public RegistryServerSync createSynObject() {
return new RegistryServerSync();
}
@Bean
ProviderService createProviderService() {
return new ProviderServiceImpl();
ProviderService createProviderService(Registry registry, RegistryServerSync sync) {
return new ProviderServiceImpl(registry,sync);
}
@Bean
......@@ -41,14 +32,6 @@ import org.springframework.context.annotation.DependsOn;
return new ServletConnectShoutDownHock();
}
@Bean
DubboCustomerDownHock createDubboConsumerDownHock() {
return new DubboCustomerDownHock();
}
@Bean
ConfigCenter configCenter(){
return new ConfigCenter();
}
@Bean
@ConditionalOnBean(ConfigCenter.class)
......@@ -62,5 +45,28 @@ import org.springframework.context.annotation.DependsOn;
}
@Bean
public GracefullyShoutDown createGraceObject(ServletConnectShoutDownHock servletConnectShoutDownHock,ProviderService providerService,UpDatas dubboUpdata) {
return new GracefullyShoutDown( servletConnectShoutDownHock, providerService, dubboUpdata);
}
@Bean
public RegistryServerSync createSynObject(Registry registry) {
return new RegistryServerSync(registry);
}
@Bean
DubboCustomerDownHock createDubboConsumerDownHock(ProviderService providerService) {
return new DubboCustomerDownHock(providerService);
}
@Bean
ConfigCenter configCenter(){
return new ConfigCenter();
}
}
\ No newline at end of file
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