Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(apollo-biz): Use constructor injection instead of field injection #4826

Merged
merged 93 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
fe75b4d
add tech-support-qq-4.png
klboke May 16, 2019
99bf97a
Update README.md
klboke May 16, 2019
1579f41
Merge remote-tracking branch 'upstream/master'
klboke Nov 11, 2020
9f65eed
Merge remote-tracking branch 'upstream/master'
klboke Dec 9, 2020
d7d3fd9
Enhance the user experience in the scenario of submitting duplicate keys
klboke Dec 11, 2020
7329fab
Merge branch 'master' into master
nobodyiam Dec 12, 2020
5def448
Modify the key-value conflict exception prompt, adjust the code style
klboke Dec 12, 2020
6942564
Merge branch 'master' into master
nobodyiam Dec 12, 2020
0fc1f91
Merge remote-tracking branch 'upstream/master'
klboke Dec 19, 2020
61ad016
Merge remote-tracking branch 'origin/master'
klboke Dec 19, 2020
587ce33
rge remote-tracking branch 'upstream/master'
klboke Mar 1, 2021
9de6563
Merge remote-tracking branch 'upstream/master'
klboke Mar 8, 2021
9aab632
Merge remote-tracking branch 'upstream/master'
klboke Mar 25, 2021
050dd0a
Merge branch 'ctripcorp:master' into master
klboke May 10, 2021
5a64035
Merge branch 'master' of github.com:klboke/apollo
klboke May 10, 2021
0648fbd
Merge branch 'ctripcorp:master' into master
klboke May 19, 2021
35bd3a6
Merge branch 'master' of github.com:klboke/apollo
klboke May 19, 2021
bc8149b
Merge branch 'ctripcorp:master' into master
klboke Jun 8, 2021
e771bdd
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 8, 2021
9a1ad83
Merge branch 'ctripcorp:master' into master
klboke Jun 25, 2021
3efef37
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 25, 2021
1274281
Merge branch 'apolloconfig:master' into master
klboke Sep 1, 2021
a968932
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 1, 2021
df8942c
Merge branch 'apolloconfig:master' into master
klboke Jan 7, 2022
f98175a
Merge branch 'master' of github.com:klboke/apollo
klboke Jan 7, 2022
710cdd6
Merge branch 'apolloconfig:master' into master
klboke Feb 18, 2022
3c162b6
Merge branch 'master' of github.com:klboke/apollo
klboke Feb 18, 2022
0101a3f
Merge branch 'apolloconfig:master' into master
klboke Jun 17, 2022
cc6f568
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 17, 2022
21dd30c
Merge branch 'apolloconfig:master' into master
klboke Jun 21, 2022
c1eeb41
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 21, 2022
e85d645
Merge branch 'apolloconfig:master' into master
klboke Jun 27, 2022
8b0056d
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 27, 2022
347e07b
Merge branch 'apolloconfig:master' into master
klboke Jul 1, 2022
d8eb437
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 1, 2022
19bae52
Merge branch 'apolloconfig:master' into master
klboke Jul 4, 2022
7e40fa1
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 4, 2022
fbbb02d
Merge branch 'apolloconfig:master' into master
klboke Jul 6, 2022
19cee24
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 6, 2022
91ba3b7
Merge branch 'apolloconfig:master' into master
klboke Jul 8, 2022
94ad542
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 8, 2022
64e1b0b
Merge branch 'apolloconfig:master' into master
klboke Jul 19, 2022
36ce5e2
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 19, 2022
c1364c2
Merge branch 'apolloconfig:master' into master
klboke Jul 22, 2022
76ed2ea
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 22, 2022
db8cf3d
Merge branch 'apolloconfig:master' into master
klboke Jul 26, 2022
3e4616d
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 26, 2022
47297cc
Merge branch 'apolloconfig:master' into master
klboke Jul 30, 2022
1c320e7
Merge branch 'apolloconfig:master' into master
klboke Aug 2, 2022
e723db5
Merge branch 'master' of github.com:klboke/apollo
klboke Aug 2, 2022
6be6a8b
Merge branch 'apolloconfig:master' into master
klboke Aug 8, 2022
014657d
Merge branch 'apolloconfig:master' into master
klboke Aug 12, 2022
370eec9
Merge branch 'master' of github.com:klboke/apollo
klboke Aug 12, 2022
dfa6c54
Merge branch 'apolloconfig:master' into master
klboke Sep 8, 2022
1a66d08
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 8, 2022
cb2c22e
Merge branch 'apolloconfig:master' into master
klboke Sep 14, 2022
74af869
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 14, 2022
a349f2e
Merge branch 'apolloconfig:master' into master
klboke Sep 22, 2022
7238296
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 22, 2022
c38d00d
Merge branch 'apolloconfig:master' into master
klboke Oct 8, 2022
10cbbed
Merge branch 'master' of github.com:klboke/apollo
klboke Oct 8, 2022
601e17b
Merge branch 'apolloconfig:master' into master
klboke Oct 11, 2022
8fe2ce5
Merge branch 'master' of github.com:klboke/apollo
klboke Oct 11, 2022
04ea7ff
Merge branch 'apolloconfig:master' into master
klboke Dec 12, 2022
cfe577c
Merge branch 'master' of github.com:klboke/apollo
klboke Dec 12, 2022
4e9ba79
Merge branch 'apolloconfig:master' into master
klboke Dec 15, 2022
53d033a
Merge branch 'master' of github.com:klboke/apollo
klboke Dec 15, 2022
3789a6d
Merge branch 'apolloconfig:master' into master
klboke Jan 4, 2023
2a1f3bc
Merge branch 'master' of github.com:klboke/apollo
klboke Jan 10, 2023
0c7c63f
Merge branch 'apolloconfig:master' into master
klboke Mar 9, 2023
eaf3b3d
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 9, 2023
312abaa
Merge branch 'apolloconfig:master' into master
klboke Mar 13, 2023
f7c95f2
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 13, 2023
39cc719
Merge branch 'apolloconfig:master' into master
klboke Mar 15, 2023
e410062
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 15, 2023
bb2bf94
Merge branch 'apolloconfig:master' into master
klboke Mar 17, 2023
95cf566
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 17, 2023
0c10b9d
Merge branch 'apolloconfig:master' into master
klboke Mar 20, 2023
aa95cdd
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 20, 2023
3441587
Merge branch 'apolloconfig:master' into master
klboke Mar 21, 2023
a09b174
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 21, 2023
8419fca
Merge branch 'apolloconfig:master' into master
klboke Mar 23, 2023
d8d0664
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 23, 2023
0af7aa2
Merge branch 'apolloconfig:master' into master
klboke Mar 27, 2023
b353db3
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 27, 2023
304f7ec
refactor(apollo-biz): Use constructor injection instead of field inje…
klboke Mar 30, 2023
c1c19a9
Merge branch 'master' into kl-autowired
klboke Mar 30, 2023
696a040
[Clean code] Remove unused imports
Mar 30, 2023
d060482
Correct the test semantics of the test case in ItemSetControllerTest …
klboke Apr 1, 2023
111ece0
Refactor the code related to ReleaseMessage (#4822)
klboke Apr 1, 2023
fad37f0
refactor(apollo-biz): Use constructor injection instead of field inje…
klboke Mar 30, 2023
3ce77cf
chore(apollo-portal): Adjusting the code style
klboke Apr 3, 2023
4cbc8dc
Merge branch 'master' into kl-autowired
klboke Apr 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

import java.util.List;
Expand All @@ -60,10 +59,8 @@ public class GrayReleaseRulesHolder implements ReleaseMessageListener, Initializ
private static final Logger logger = LoggerFactory.getLogger(GrayReleaseRulesHolder.class);
private static final Joiner STRING_JOINER = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR);

@Autowired
private GrayReleaseRuleRepository grayReleaseRuleRepository;
@Autowired
private BizConfig bizConfig;
private final GrayReleaseRuleRepository grayReleaseRuleRepository;
private final BizConfig bizConfig;

private int databaseScanInterval;
private ScheduledExecutorService executorService;
Expand All @@ -74,7 +71,10 @@ public class GrayReleaseRulesHolder implements ReleaseMessageListener, Initializ
//an auto increment version to indicate the age of rules
private AtomicLong loadVersion;

public GrayReleaseRulesHolder() {
public GrayReleaseRulesHolder(final GrayReleaseRuleRepository grayReleaseRuleRepository,
final BizConfig bizConfig) {
this.grayReleaseRuleRepository = grayReleaseRuleRepository;
this.bizConfig = bizConfig;
loadVersion = new AtomicLong();
grayReleaseRuleCache = Multimaps.synchronizedSetMultimap(
TreeMultimap.create(String.CASE_INSENSITIVE_ORDER, Ordering.natural()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

import com.ctrip.framework.apollo.biz.config.BizConfig;
Expand All @@ -46,17 +45,18 @@
public class ReleaseMessageScanner implements InitializingBean {
private static final Logger logger = LoggerFactory.getLogger(ReleaseMessageScanner.class);
private static final int missingReleaseMessageMaxAge = 10; // hardcoded to 10, could be configured via BizConfig if necessary
@Autowired
private BizConfig bizConfig;
@Autowired
private ReleaseMessageRepository releaseMessageRepository;
private final BizConfig bizConfig;
private final ReleaseMessageRepository releaseMessageRepository;
private int databaseScanInterval;
private final List<ReleaseMessageListener> listeners;
private final ScheduledExecutorService executorService;
private final Map<Long, Integer> missingReleaseMessages; // missing release message id => age counter
private long maxIdScanned;

public ReleaseMessageScanner() {
public ReleaseMessageScanner(final BizConfig bizConfig,
final ReleaseMessageRepository releaseMessageRepository) {
this.bizConfig = bizConfig;
this.releaseMessageRepository = releaseMessageRepository;
listeners = Lists.newCopyOnWriteArrayList();
executorService = Executors.newScheduledThreadPool(1, ApolloThreadFactory
.create("ReleaseMessageScanner", true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ public class BizDBPropertySource extends RefreshablePropertySource {

private static final Logger logger = LoggerFactory.getLogger(BizDBPropertySource.class);

@Autowired
private ServerConfigRepository serverConfigRepository;
private final ServerConfigRepository serverConfigRepository;

public BizDBPropertySource(String name, Map<String, Object> source) {
public BizDBPropertySource(final String name,
final Map<String, Object> source,
final ServerConfigRepository serverConfigRepository) {
super(name, source);
this.serverConfigRepository = serverConfigRepository;
}

public BizDBPropertySource() {
@Autowired
public BizDBPropertySource(final ServerConfigRepository serverConfigRepository) {
super("DBConfig", Maps.newConcurrentMap());
this.serverConfigRepository = serverConfigRepository;
}

String getCurrentDataCenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.ctrip.framework.apollo.biz.config;

import com.ctrip.framework.apollo.biz.repository.ServerConfigRepository;
import com.ctrip.framework.apollo.biz.service.BizDBPropertySource;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -36,12 +37,14 @@ public class BizConfigTest {

@Mock
private ConfigurableEnvironment environment;
@Mock
private ServerConfigRepository serverConfigRepository;

private BizConfig bizConfig;

@Before
public void setUp() throws Exception {
bizConfig = new BizConfig(new BizDBPropertySource());
bizConfig = new BizConfig(new BizDBPropertySource(serverConfigRepository));
ReflectionTestUtils.setField(bizConfig, "environment", environment);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -64,11 +63,7 @@ public class GrayReleaseRulesHolderTest {

@Before
public void setUp() throws Exception {
grayReleaseRulesHolder = spy(new GrayReleaseRulesHolder());
ReflectionTestUtils.setField(grayReleaseRulesHolder, "bizConfig",
bizConfig);
ReflectionTestUtils.setField(grayReleaseRulesHolder, "grayReleaseRuleRepository",
grayReleaseRuleRepository);
grayReleaseRulesHolder = spy(new GrayReleaseRulesHolder(grayReleaseRuleRepository, bizConfig));
idCounter = new AtomicLong();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.concurrent.TimeUnit;

Expand All @@ -52,10 +51,7 @@ public class ReleaseMessageScannerTest extends AbstractUnitTest {

@Before
public void setUp() throws Exception {
releaseMessageScanner = new ReleaseMessageScanner();
ReflectionTestUtils
.setField(releaseMessageScanner, "releaseMessageRepository", releaseMessageRepository);
ReflectionTestUtils.setField(releaseMessageScanner, "bizConfig", bizConfig);
releaseMessageScanner = new ReleaseMessageScanner(bizConfig, releaseMessageRepository);
databaseScanInterval = 100; //100 ms
when(bizConfig.releaseMessageScanIntervalInMilli()).thenReturn(databaseScanInterval);
releaseMessageScanner.afterPropertiesSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.List;

Expand All @@ -55,8 +54,7 @@ public class BizDBPropertySourceTest extends AbstractUnitTest {

@Before
public void initTestData() {
propertySource = spy(new BizDBPropertySource());
ReflectionTestUtils.setField(propertySource, "serverConfigRepository", serverConfigRepository);
propertySource = spy(new BizDBPropertySource(serverConfigRepository));

List<ServerConfig> configs = Lists.newLinkedList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.ctrip.framework.apollo.biz.grayReleaseRule.GrayReleaseRulesHolder;
import com.ctrip.framework.apollo.biz.message.ReleaseMessageScanner;
import com.ctrip.framework.apollo.biz.repository.GrayReleaseRuleRepository;
import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository;
import com.ctrip.framework.apollo.biz.service.ReleaseMessageService;
import com.ctrip.framework.apollo.biz.service.ReleaseService;
import com.ctrip.framework.apollo.configservice.controller.ConfigFileController;
import com.ctrip.framework.apollo.configservice.controller.NotificationController;
import com.ctrip.framework.apollo.configservice.controller.NotificationControllerV2;
Expand All @@ -40,22 +44,32 @@
public class ConfigServiceAutoConfiguration {

private final BizConfig bizConfig;
private final ReleaseService releaseService;
private final ReleaseMessageService releaseMessageService;
private final GrayReleaseRuleRepository grayReleaseRuleRepository;

public ConfigServiceAutoConfiguration(final BizConfig bizConfig) {
public ConfigServiceAutoConfiguration(final BizConfig bizConfig,
final ReleaseService releaseService,
final ReleaseMessageService releaseMessageService,
final GrayReleaseRuleRepository grayReleaseRuleRepository) {
this.bizConfig = bizConfig;
this.releaseService = releaseService;
this.releaseMessageService = releaseMessageService;
this.grayReleaseRuleRepository = grayReleaseRuleRepository;
}

@Bean
public GrayReleaseRulesHolder grayReleaseRulesHolder() {
return new GrayReleaseRulesHolder();
return new GrayReleaseRulesHolder(grayReleaseRuleRepository, bizConfig);
}

@Bean
public ConfigService configService() {
if (bizConfig.isConfigServiceCacheEnabled()) {
return new ConfigServiceWithCache();
return new ConfigServiceWithCache(releaseService, releaseMessageService,
grayReleaseRulesHolder());
}
return new DefaultConfigService();
return new DefaultConfigService(releaseService, grayReleaseRulesHolder());
}

@Bean
Expand All @@ -64,8 +78,8 @@ public static NoOpPasswordEncoder passwordEncoder() {
}

@Bean
public FilterRegistrationBean clientAuthenticationFilter(AccessKeyUtil accessKeyUtil) {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
public FilterRegistrationBean<ClientAuthenticationFilter> clientAuthenticationFilter(AccessKeyUtil accessKeyUtil) {
FilterRegistrationBean<ClientAuthenticationFilter> filterRegistrationBean = new FilterRegistrationBean<>();

filterRegistrationBean.setFilter(new ClientAuthenticationFilter(bizConfig, accessKeyUtil));
filterRegistrationBean.addUrlPatterns("/configs/*");
Expand All @@ -83,25 +97,32 @@ static class MessageScannerConfiguration {
private final GrayReleaseRulesHolder grayReleaseRulesHolder;
private final ReleaseMessageServiceWithCache releaseMessageServiceWithCache;
private final ConfigService configService;
private final BizConfig bizConfig;
private final ReleaseMessageRepository releaseMessageRepository;

public MessageScannerConfiguration(
final NotificationController notificationController,
final ConfigFileController configFileController,
final NotificationControllerV2 notificationControllerV2,
final GrayReleaseRulesHolder grayReleaseRulesHolder,
final ReleaseMessageServiceWithCache releaseMessageServiceWithCache,
final ConfigService configService) {
final ConfigService configService,
final BizConfig bizConfig,
final ReleaseMessageRepository releaseMessageRepository) {
this.notificationController = notificationController;
this.configFileController = configFileController;
this.notificationControllerV2 = notificationControllerV2;
this.grayReleaseRulesHolder = grayReleaseRulesHolder;
this.releaseMessageServiceWithCache = releaseMessageServiceWithCache;
this.configService = configService;
this.bizConfig = bizConfig;
this.releaseMessageRepository = releaseMessageRepository;
}

@Bean
public ReleaseMessageScanner releaseMessageScanner() {
ReleaseMessageScanner releaseMessageScanner = new ReleaseMessageScanner();
ReleaseMessageScanner releaseMessageScanner = new ReleaseMessageScanner(bizConfig,
releaseMessageRepository);
//0. handle release message cache
releaseMessageScanner.addMessageListener(releaseMessageServiceWithCache);
//1. handle gray release rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public class NotificationControllerV2 implements ReleaseMessageListener {
private final Gson gson;
private final BizConfig bizConfig;

@Autowired
public NotificationControllerV2(
final WatchKeysUtil watchKeysUtil,
final ReleaseMessageServiceWithCache releaseMessageService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public class AccessKeyServiceWithCache implements InitializingBean {
private ListMultimap<String, AccessKey> accessKeyCache;
private ConcurrentMap<Long, AccessKey> accessKeyIdCache;

@Autowired
public AccessKeyServiceWithCache(AccessKeyRepository accessKeyRepository, BizConfig bizConfig) {
public AccessKeyServiceWithCache(final AccessKeyRepository accessKeyRepository,
final BizConfig bizConfig) {
this.accessKeyRepository = accessKeyRepository;
this.bizConfig = bizConfig;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
import com.google.common.base.Strings;

import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;

/**
* @author Jason Song([email protected])
*/
public abstract class AbstractConfigService implements ConfigService {
@Autowired
private GrayReleaseRulesHolder grayReleaseRulesHolder;

private final GrayReleaseRulesHolder grayReleaseRulesHolder;

protected AbstractConfigService(final GrayReleaseRulesHolder grayReleaseRulesHolder) {
this.grayReleaseRulesHolder = grayReleaseRulesHolder;
}

@Override
public Release loadConfig(String clientAppId, String clientIp, String clientLabel, String configAppId, String configClusterName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.ctrip.framework.apollo.configservice.service.config;

import com.ctrip.framework.apollo.biz.grayReleaseRule.GrayReleaseRulesHolder;
import com.google.common.base.Strings;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
Expand All @@ -37,7 +38,6 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.concurrent.TimeUnit;
Expand All @@ -59,19 +59,21 @@ public class ConfigServiceWithCache extends AbstractConfigService {
private static final String TRACER_EVENT_CACHE_GET = "ConfigCache.Get";
private static final String TRACER_EVENT_CACHE_GET_ID = "ConfigCache.GetById";

@Autowired
private ReleaseService releaseService;

@Autowired
private ReleaseMessageService releaseMessageService;
private final ReleaseService releaseService;
private final ReleaseMessageService releaseMessageService;

private LoadingCache<String, ConfigCacheEntry> configCache;

private LoadingCache<Long, Optional<Release>> configIdCache;

private ConfigCacheEntry nullConfigCacheEntry;

public ConfigServiceWithCache() {
public ConfigServiceWithCache(final ReleaseService releaseService,
final ReleaseMessageService releaseMessageService,
final GrayReleaseRulesHolder grayReleaseRulesHolder) {
super(grayReleaseRulesHolder);
this.releaseService = releaseService;
this.releaseMessageService = releaseMessageService;
nullConfigCacheEntry = new ConfigCacheEntry(ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@

import com.ctrip.framework.apollo.biz.entity.Release;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.grayReleaseRule.GrayReleaseRulesHolder;
import com.ctrip.framework.apollo.biz.service.ReleaseService;
import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages;

import org.springframework.beans.factory.annotation.Autowired;

/**
* config service with no cache
*
* @author Jason Song([email protected])
*/
public class DefaultConfigService extends AbstractConfigService {

@Autowired
private ReleaseService releaseService;
private final ReleaseService releaseService;
private final GrayReleaseRulesHolder grayReleaseRulesHolder;

public DefaultConfigService(final ReleaseService releaseService,
final GrayReleaseRulesHolder grayReleaseRulesHolder) {
super(grayReleaseRulesHolder);
this.releaseService = releaseService;
this.grayReleaseRulesHolder = grayReleaseRulesHolder;
}

@Override
protected Release findActiveOne(long id, ApolloNotificationMessages clientMessages) {
Expand Down
Loading