Skip to content

Commit

Permalink
Use cache for notification controller
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyiam committed Jan 16, 2017
1 parent efcfe94 commit 1eaf379
Show file tree
Hide file tree
Showing 18 changed files with 960 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Component
public class BizConfig extends RefreshableConfig {
Expand Down Expand Up @@ -80,5 +81,28 @@ public String cloggingPort() {
return getValue("clogging.server.port");
}

public int appNamespaceCacheScanInterval() {
return getIntProperty("apollo.app-namespace-cache-scan.interval", 1);
}

public TimeUnit appNamespaceCacheScanIntervalTimeUnit() {
return TimeUnit.SECONDS;
}

public int appNamespaceCacheRebuildInterval() {
return getIntProperty("apollo.app-namespace-cache-rebuild.interval", 60);
}

public TimeUnit appNamespaceCacheRebuildIntervalTimeUnit() {
return TimeUnit.SECONDS;
}

public int releaseMessageCacheScanInterval() {
return getIntProperty("apollo.release-message-cache-scan.interval", 1);
}

public TimeUnit releaseMessageCacheScanIntervalTimeUnit() {
return TimeUnit.SECONDS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -250,12 +249,7 @@ private GrayReleaseRuleCache transformRuleToRuleCache(GrayReleaseRule grayReleas
}

private void populateDataBaseInterval() {
try {
databaseScanInterval = bizConfig.grayReleaseRuleScanInterval();
} catch (Throwable ex) {
Tracer.logError(ex);
logger.error("Load apollo gray release rule scan interval from server config failed", ex);
}
databaseScanInterval = bizConfig.grayReleaseRuleScanInterval();
}

private int getDatabaseScanIntervalSecond() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public interface AppNamespaceRepository extends PagingAndSortingRepository<AppNa

List<AppNamespace> findByAppIdAndIsPublic(String appId, boolean isPublic);

List<AppNamespace> findFirst500ByIdGreaterThanOrderByIdAsc(long id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public int getIntProperty(String key, int defaultValue) {
try {
String value = getValue(key);
return value == null ? defaultValue : Integer.parseInt(value);
} catch (Exception e) {
} catch (Throwable e) {
Tracer.logError("Get int property failed.", e);
return defaultValue;
}
Expand All @@ -85,7 +85,7 @@ public boolean getBooleanProperty(String key, boolean defaultValue) {
try {
String value = getValue(key);
return value == null ? defaultValue : "true".equals(value);
} catch (Exception e) {
} catch (Throwable e) {
Tracer.logError("Get boolean property failed.", e);
return defaultValue;
}
Expand All @@ -95,7 +95,7 @@ public String[] getArrayProperty(String key, String[] defaultValue) {
try {
String value = getValue(key);
return Strings.isNullOrEmpty(value) ? defaultValue : value.split(LIST_SEPARATOR);
} catch (Exception e) {
} catch (Throwable e) {
Tracer.logError("Get array property failed.", e);
return defaultValue;
}
Expand All @@ -104,7 +104,7 @@ public String[] getArrayProperty(String key, String[] defaultValue) {
public String getValue(String key, String defaultValue) {
try {
return environment.getProperty(key, defaultValue);
} catch (Exception e) {
} catch (Throwable e) {
Tracer.logError("Get value failed.", e);
return defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.ctrip.framework.apollo.configservice.controller.ConfigFileController;
import com.ctrip.framework.apollo.configservice.controller.NotificationController;
import com.ctrip.framework.apollo.configservice.controller.NotificationControllerV2;
import com.ctrip.framework.apollo.configservice.service.ReleaseMessageServiceWithCache;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
Expand All @@ -30,10 +31,14 @@ static class MessageScannerConfiguration {
private NotificationControllerV2 notificationControllerV2;
@Autowired
private GrayReleaseRulesHolder grayReleaseRulesHolder;
@Autowired
private ReleaseMessageServiceWithCache releaseMessageServiceWithCache;

@Bean
public ReleaseMessageScanner releaseMessageScanner() {
ReleaseMessageScanner releaseMessageScanner = new ReleaseMessageScanner();
//0. handle release message cache
releaseMessageScanner.addMessageListener(releaseMessageServiceWithCache);
//1. handle gray release rule
releaseMessageScanner.addMessageListener(grayReleaseRulesHolder);
//2. handle server cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.message.ReleaseMessageListener;
import com.ctrip.framework.apollo.biz.message.Topics;
import com.ctrip.framework.apollo.biz.service.ReleaseMessageService;
import com.ctrip.framework.apollo.biz.utils.EntityManagerUtil;
import com.ctrip.framework.apollo.configservice.service.ReleaseMessageServiceWithCache;
import com.ctrip.framework.apollo.configservice.util.NamespaceUtil;
import com.ctrip.framework.apollo.configservice.util.WatchKeysUtil;
import com.ctrip.framework.apollo.core.ConfigConsts;
Expand Down Expand Up @@ -51,7 +51,7 @@ public class NotificationController implements ReleaseMessageListener {
private WatchKeysUtil watchKeysUtil;

@Autowired
private ReleaseMessageService releaseMessageService;
private ReleaseMessageServiceWithCache releaseMessageService;

@Autowired
private EntityManagerUtil entityManagerUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.message.ReleaseMessageListener;
import com.ctrip.framework.apollo.biz.message.Topics;
import com.ctrip.framework.apollo.biz.service.ReleaseMessageService;
import com.ctrip.framework.apollo.biz.utils.EntityManagerUtil;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.configservice.service.ReleaseMessageServiceWithCache;
import com.ctrip.framework.apollo.configservice.util.NamespaceUtil;
import com.ctrip.framework.apollo.configservice.util.WatchKeysUtil;
import com.ctrip.framework.apollo.core.ConfigConsts;
Expand Down Expand Up @@ -65,7 +65,7 @@ public class NotificationControllerV2 implements ReleaseMessageListener {
private WatchKeysUtil watchKeysUtil;

@Autowired
private ReleaseMessageService releaseMessageService;
private ReleaseMessageServiceWithCache releaseMessageService;

@Autowired
private EntityManagerUtil entityManagerUtil;
Expand Down
Loading

0 comments on commit 1eaf379

Please sign in to comment.