Commit 107c2332 by 房斌

解决depender依赖 顺序问题

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