This is an automated email from the ASF dual-hosted git repository.

elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit 04d86651fb6d846f2ea10a48b9fe4303b28b725c
Author: Rawlin Peters <rawlin_pet...@comcast.com>
AuthorDate: Tue Jan 23 17:46:43 2018 -0700

    Move loadDeepCaches() into CacheLocation and add synchronization
---
 .../traffic_router/core/cache/CacheLocation.java   | 23 +++++++++++++++++++++-
 .../traffic_router/core/router/TrafficRouter.java  | 16 ++-------------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/cache/CacheLocation.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/cache/CacheLocation.java
index 7caf2a3..67159c1 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/cache/CacheLocation.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/cache/CacheLocation.java
@@ -23,6 +23,7 @@ import java.util.Set;
 
 import org.apache.commons.lang3.builder.EqualsBuilder;
 import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.log4j.Logger;
 
 import com.comcast.cdn.traffic_control.traffic_router.geolocation.Geolocation;
 
@@ -31,6 +32,8 @@ import 
com.comcast.cdn.traffic_control.traffic_router.geolocation.Geolocation;
  */
 public class CacheLocation {
 
+       public static final Logger LOGGER = 
Logger.getLogger(CacheLocation.class);
+
        private final String id;
        private final Geolocation geolocation;
 
@@ -57,11 +60,29 @@ public class CacheLocation {
         *            the cache to add
         */
        public void addCache(final Cache cache) {
+           synchronized (caches) {
                        caches.put(cache.getId(), cache);
+               }
        }
 
        public void clearCaches() {
-               caches.clear();
+               synchronized (caches) {
+                       caches.clear();
+               }
+       }
+
+       public void loadDeepCaches(final Set<String> deepCacheNames, final 
CacheRegister cacheRegister) {
+           synchronized (caches) {
+                       if (caches.isEmpty() && deepCacheNames != null) {
+                               for (final String deepCacheName : 
deepCacheNames) {
+                                       final Cache deepCache = 
cacheRegister.getCacheMap().get(deepCacheName);
+                                       if (deepCache != null) {
+                                               LOGGER.debug("DDC: Adding " + 
deepCacheName + " to " + getId());
+                                               caches.put(deepCache.getId(), 
deepCache);
+                                       }
+                               }
+                       }
+               }
        }
 
        @Override
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
index bb1dbb5..b63e075 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
@@ -648,9 +648,9 @@ public class TrafficRouter {
                final DeliveryService deliveryService = 
cacheRegister.getDeliveryService(deliveryServiceId);
                CacheLocation cacheLocation = networkNode.getCacheLocation();
 
-               if (useDeep && cacheLocation != null && 
cacheLocation.getCaches().isEmpty()) {
+               if (useDeep && cacheLocation != null) {
                        // lazily load deep Caches into the deep CacheLocation
-                       loadDeepCaches(networkNode, cacheLocation);
+                       
cacheLocation.loadDeepCaches(networkNode.getDeepCacheNames(), cacheRegister);
                }
 
                if (cacheLocation != null && 
!getSupportingCaches(cacheLocation.getCaches(), deliveryService).isEmpty()) {
@@ -679,18 +679,6 @@ public class TrafficRouter {
                return 
getClosestCacheLocation(cacheRegister.filterAvailableLocations(deliveryServiceId),
 networkNode.getGeolocation(), 
cacheRegister.getDeliveryService(deliveryServiceId));
        }
 
-       private void loadDeepCaches(final NetworkNode networkNode, final 
CacheLocation cacheLocation) {
-               if (networkNode.getDeepCacheNames() != null) {
-                       for (final String deepCacheName : 
networkNode.getDeepCacheNames()) {
-                               final Cache deepCache = 
cacheRegister.getCacheMap().get(deepCacheName);
-                               if (deepCache != null) {
-                                       LOGGER.debug("DDC: Adding " + 
deepCacheName + " to " + cacheLocation.getId());
-                                       cacheLocation.addCache(deepCache);
-                               }
-                       }
-               }
-       }
-
        public CacheLocation getDeepCoverageZoneCacheLocation(final String ip, 
final DeliveryService deliveryService) {
                return getCoverageZoneCacheLocation(ip, deliveryService, true);
        }

-- 
To stop receiving notification emails like this one, please contact
els...@apache.org.

Reply via email to