wu-sheng commented on a change in pull request #1069: Replaced ObjectUtils for 
java.utils.Objects methods
URL: 
https://github.com/apache/incubator-skywalking/pull/1069#discussion_r180793789
 
 

 ##########
 File path: 
apm-collector/apm-collector-cache/collector-cache-caffeine-provider/src/main/java/org/apache/skywalking/apm/collector/cache/caffeine/service/InstanceCacheCaffeineService.java
 ##########
 @@ -51,67 +57,49 @@ public InstanceCacheCaffeineService(ModuleManager 
moduleManager) {
     }
 
     private IInstanceCacheDAO getInstanceCacheDAO() {
-        if (ObjectUtils.isEmpty(instanceCacheDAO)) {
+        if (Objects.isNull(instanceCacheDAO)) {
             this.instanceCacheDAO = 
moduleManager.find(StorageModule.NAME).getService(IInstanceCacheDAO.class);
         }
         return this.instanceCacheDAO;
     }
 
     @Override public int getApplicationId(int instanceId) {
-        int applicationId = 0;
-        try {
-            Integer value = applicationIdCache.get(instanceId, key -> 
getInstanceCacheDAO().getApplicationId(key));
-            applicationId = value == null ? 0 : value;
-        } catch (Throwable e) {
-            logger.error(e.getMessage(), e);
-        }
-
-        if (applicationId == 0) {
-            applicationId = getInstanceCacheDAO().getApplicationId(instanceId);
-            if (applicationId != 0) {
-                applicationIdCache.put(instanceId, applicationId);
-            }
-        }
-        return applicationId;
+        return   ofNullable(retrieveFromCache(applicationIdCache,  instanceId,
+            () -> 
getInstanceCacheDAO().getApplicationId(instanceId))).orElse(0);
 
 Review comment:
   TODO: recheck this refactor later.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to