Forráskód Böngészése

configure the server side's long polling timeout (#2532)

* configure server side's long polling timeout

* logical update

* Revert "logical update"

This reverts commit 99943df3

* logic uapte
Crecel 5 éve
szülő
commit
8eac52e5b8

+ 7 - 0
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java

@@ -27,6 +27,7 @@ public class BizConfig extends RefreshableConfig {
   private static final int DEFAULT_RELEASE_MESSAGE_SCAN_INTERVAL_IN_MS = 1000; //1000ms
   private static final int DEFAULT_RELEASE_MESSAGE_NOTIFICATION_BATCH = 100;
   private static final int DEFAULT_RELEASE_MESSAGE_NOTIFICATION_BATCH_INTERVAL_IN_MILLI = 100;//100ms
+  private static final int DEFAULT_LONG_POLLING_TIMEOUT = 60; //60s
 
   private Gson gson = new Gson();
   private static final Type namespaceValueLengthOverrideTypeReference =
@@ -58,6 +59,11 @@ public class BizConfig extends RefreshableConfig {
     return checkInt(interval, 1, Integer.MAX_VALUE, DEFAULT_GRAY_RELEASE_RULE_SCAN_INTERVAL);
   }
 
+  public long longPollingTimeout() {
+    int timeout = getIntProperty("long.polling.timeout", DEFAULT_LONG_POLLING_TIMEOUT);
+    return 1000 * checkInt(timeout, 1, Integer.MAX_VALUE, DEFAULT_LONG_POLLING_TIMEOUT);
+  }
+
   public int itemKeyLengthLimit() {
     int limit = getIntProperty("item.key.length.limit", DEFAULT_ITEM_KEY_LENGTH);
     return checkInt(limit, 5, Integer.MAX_VALUE, DEFAULT_ITEM_KEY_LENGTH);
@@ -146,4 +152,5 @@ public class BizConfig extends RefreshableConfig {
     }
     return defaultValue;
   }
+
 }

+ 1 - 1
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/controller/NotificationControllerV2.java

@@ -108,7 +108,7 @@ public class NotificationControllerV2 implements ReleaseMessageListener {
       throw new BadRequestException("Invalid format of notifications: " + notificationsAsString);
     }
 
-    DeferredResultWrapper deferredResultWrapper = new DeferredResultWrapper();
+    DeferredResultWrapper deferredResultWrapper = new DeferredResultWrapper(bizConfig.longPollingTimeout());
     Set<String> namespaces = Sets.newHashSet();
     Map<String, Long> clientSideNotifications = Maps.newHashMap();
     Map<String, ApolloConfigNotification> filteredNotifications = filterNotifications(appId, notifications);

+ 2 - 3
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/wrapper/DeferredResultWrapper.java

@@ -16,7 +16,6 @@ import java.util.Map;
  * @author Jason Song(song_s@ctrip.com)
  */
 public class DeferredResultWrapper {
-  private static final long TIMEOUT = 60 * 1000;//60 seconds
   private static final ResponseEntity<List<ApolloConfigNotification>>
       NOT_MODIFIED_RESPONSE_LIST = new ResponseEntity<>(HttpStatus.NOT_MODIFIED);
 
@@ -24,8 +23,8 @@ public class DeferredResultWrapper {
   private DeferredResult<ResponseEntity<List<ApolloConfigNotification>>> result;
 
 
-  public DeferredResultWrapper() {
-    result = new DeferredResult<>(TIMEOUT, NOT_MODIFIED_RESPONSE_LIST);
+  public DeferredResultWrapper(long timeout) {
+    result = new DeferredResult<>(timeout, NOT_MODIFIED_RESPONSE_LIST);
   }
 
   public void recordNamespaceNameNormalizedResult(String originalNamespaceName, String normalizedNamespaceName) {