diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java index bb473496ad51f500d78b0848afb1e0f7416592c8..ef3c55a22226c97f5a852dc854efd52acdfbe6dc 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java @@ -131,7 +131,7 @@ public class ConfigServiceLocator implements Initializable { } try { - TimeUnit.SECONDS.sleep(1); + m_configUtil.getOnErrorRetryIntervalTimeUnit().sleep(m_configUtil.getOnErrorRetryInterval()); } catch (InterruptedException ex) { //ignore } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 869cf4438af5974918ca8114dbb4002132cea288..efb69866c3260bf5f07e4181eb56648380af8bf3 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -228,7 +228,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository { } try { - TimeUnit.SECONDS.sleep(1); + m_configUtil.getOnErrorRetryIntervalTimeUnit().sleep(m_configUtil.getOnErrorRetryInterval()); } catch (InterruptedException ex) { //ignore } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java index 454f91dfa2dea92c91c360c1b9521f6f3045c4b6..0cc9ec9b187bd0c5cac43d8dc2a73f2911a99cab 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java @@ -29,6 +29,9 @@ public class ConfigUtil { private String cluster; private int loadConfigQPS = 2; //2 times per second private int longPollQPS = 2; //2 times per second + //for on error retry + private long onErrorRetryInterval = 1;//1 second + private TimeUnit onErrorRetryIntervalTimeUnit = TimeUnit.SECONDS;//1 second //for typed config cache of parser result, e.g. integer, double, long, etc. private long maxConfigCacheSize = 500;//500 cache key private long configCacheExpireTime = 1;//1 minute @@ -212,6 +215,14 @@ public class ConfigUtil { return longPollQPS; } + public long getOnErrorRetryInterval() { + return onErrorRetryInterval; + } + + public TimeUnit getOnErrorRetryIntervalTimeUnit() { + return onErrorRetryIntervalTimeUnit; + } + public String getDefaultLocalCacheDir() { String cacheRoot = isOSWindows() ? "C:\\opt\\data\\%s" : "/opt/data/%s"; return String.format(cacheRoot, getAppId()); diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/BaseIntegrationTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/BaseIntegrationTest.java index 5108e0b2ccf4e9eb22476a43b15afa0f26d90dcc..e4bc8cf0a1628417bafd36b4b51f83c69323b01a 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/BaseIntegrationTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/BaseIntegrationTest.java @@ -182,6 +182,16 @@ public abstract class BaseIntegrationTest extends ComponentTestCase { public String getDefaultLocalCacheDir() { return ClassLoaderUtil.getClassPath(); } + + @Override + public long getOnErrorRetryInterval() { + return 10; + } + + @Override + public TimeUnit getOnErrorRetryIntervalTimeUnit() { + return TimeUnit.MILLISECONDS; + } } /** diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java index 30e74674c1b024bf0905879b099f3c7b96ca3f18..797d213bec0d17a0aa586e64eec982d64d81f1e6 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java @@ -233,6 +233,16 @@ public class RemoteConfigRepositoryTest extends ComponentTestCase { public int getLongPollQPS() { return 200; } + + @Override + public long getOnErrorRetryInterval() { + return 10; + } + + @Override + public TimeUnit getOnErrorRetryIntervalTimeUnit() { + return TimeUnit.MILLISECONDS; + } } public static class MockConfigServiceLocator extends ConfigServiceLocator {