You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/06/04 00:46:36 UTC

[GitHub] wujimin commented on a change in pull request #744: [SCB-627] Client Request Timeout support for operation/schema/service level

wujimin commented on a change in pull request #744: [SCB-627] Client Request Timeout support for operation/schema/service level
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/744#discussion_r192608767
 
 

 ##########
 File path: core/src/main/java/org/apache/servicecomb/core/transport/AbstractTransport.java
 ##########
 @@ -160,4 +161,83 @@ public Object parseAddress(String address) {
     }
     return new URIEndpointObject(address);
   }
+
+  /**
+   * Handles the request timeout configurations.
+   * 
+   * @param invocation
+   *            invocation of request
+   * @return configuration value
+   */
+  public static long getReqTimeout(Invocation invocation) {
+    long value = 0;
+    String config;
+
+    // get the config base on priority. operationName-->schema-->service-->global
+    String operationName = invocation.getOperationName();
+    String schema = invocation.getSchemaId();
+    String serviceName = invocation.getMicroserviceName();
+
+    config = CONSUMER_REQUEST_TIMEOUT + "." + serviceName + "." + schema + "." + operationName;
+    value = getConfigValue(config);
+    if ((value != REQUEST_TIMEOUT_CFG_FAIL)) {
+      return value;
+    }
+
+    config = CONSUMER_REQUEST_TIMEOUT + "." + serviceName + "." + schema;
+    value = getConfigValue(config);
+    if ((value != REQUEST_TIMEOUT_CFG_FAIL)) {
+      return value;
+    }
+
+    config = CONSUMER_REQUEST_TIMEOUT + "." + serviceName;
+    value = getConfigValue(config);
+    if ((value != REQUEST_TIMEOUT_CFG_FAIL)) {
+      return value;
+    }
+
+    value = getConfigValue(CONSUMER_REQUEST_TIMEOUT);
+    if ((value != REQUEST_TIMEOUT_CFG_FAIL)) {
+      return value;
+    }
+    return DEFAULT_TIMEOUT_MILLIS;
+  }
+
+  /**
+   * Get the configuration value
+   * @param config config parameter
+   * @return long value
+   */
+  private static long getConfigParam(String config, long defaultValue) {
+    DynamicLongProperty dynamicLongProperty = DynamicPropertyFactory.getInstance().getLongProperty(config,
+        defaultValue);
+
+    cfgCallback.computeIfAbsent(config, key -> {
+      dynamicLongProperty.addCallback(() -> {
+        long newValue = dynamicLongProperty.get();
+        String cfgName = dynamicLongProperty.getName();
+
+        //store the value in config center map and check for next requests.
+        configCenterValue.put(cfgName, new AtomicLong(newValue));
 
 Review comment:
   why need Atomic logic?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services