trafficcontrol-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [incubator-trafficcontrol] 13/36: Remove the need for deepcoveragezone.polling.initialDelay parameter
Date Wed, 24 Jan 2018 17:23:22 GMT
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 dfda01a0e3f4db4452d0c9ea81db78ef04da2d5b
Author: Rawlin Peters <rawlin_peters@comcast.com>
AuthorDate: Mon Oct 30 16:47:13 2017 -0600

    Remove the need for deepcoveragezone.polling.initialDelay parameter
---
 .../traffic_router/core/loc/AbstractServiceUpdater.java  | 12 +-----------
 .../traffic_router/core/loc/NetworkNode.java             | 16 ++++++++++++++--
 .../core/src/main/webapp/WEB-INF/applicationContext.xml  |  2 +-
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/AbstractServiceUpdater.java
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/AbstractServiceUpdater.java
index 650bdea..3304119 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/AbstractServiceUpdater.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/AbstractServiceUpdater.java
@@ -48,7 +48,6 @@ public abstract class AbstractServiceUpdater {
 	protected String databaseName;
 	protected ScheduledExecutorService executorService;
 	private long pollingInterval;
-	private long initialDelay = -1;
 	protected boolean loaded = false;
 	protected ScheduledFuture<?> scheduledService;
 	private TrafficRouterManager trafficRouterManager;
@@ -93,13 +92,9 @@ public abstract class AbstractServiceUpdater {
 
 	public void init() {
 		final long pollingInterval = getPollingInterval();
-        if (initialDelay == -1) {
-             initialDelay = pollingInterval;
-        }
-
 		final Date nextFetchDate = new Date(System.currentTimeMillis() + pollingInterval);
 		LOGGER.info("[" + getClass().getSimpleName() + "] Fetching external resource " + dataBaseURL
+ " at interval: " + pollingInterval + " : " + TimeUnit.MILLISECONDS + " next update occurrs
at " + nextFetchDate);
-		scheduledService = executorService.scheduleWithFixedDelay(updater, initialDelay, pollingInterval,
TimeUnit.MILLISECONDS);
+		scheduledService = executorService.scheduleWithFixedDelay(updater, pollingInterval, pollingInterval,
TimeUnit.MILLISECONDS);
 	}
 
 	@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
@@ -199,11 +194,6 @@ public abstract class AbstractServiceUpdater {
 		dataBaseURL = null;
 	}
 
-    public void setDataBaseURL(final String url, final long refresh, final long iDelay) {
-        this.initialDelay = iDelay;
-        this.setDataBaseURL(url, refresh);
-    }
-
 	public void setDataBaseURL(final String url, final long refresh) {
 		if (refresh !=0 && refresh != pollingInterval) {
 
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNode.java
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNode.java
index bab5a2e..0b89d2e 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNode.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNode.java
@@ -24,7 +24,7 @@ import java.util.Map;
 import java.util.TreeMap;
 import java.util.List;
 import java.util.ArrayList;
-
+import java.util.concurrent.CountDownLatch;
 
 import com.comcast.cdn.traffic_control.traffic_router.core.util.CidrAddress;
 import com.comcast.cdn.traffic_control.traffic_router.core.util.JsonUtils;
@@ -47,6 +47,7 @@ public class NetworkNode implements Comparable<NetworkNode> {
     private static NetworkNode deepInstance;
 
     private static CacheRegister cacheRegister;
+    private static final CountDownLatch cacheRegisterLatch = new CountDownLatch(1);
 
     private CidrAddress cidrAddress;
     private String loc;
@@ -84,6 +85,17 @@ public class NetworkNode implements Comparable<NetworkNode> {
 
     public static void setCacheRegister(final CacheRegister cr) {
         cacheRegister = cr;
+        cacheRegisterLatch.countDown();
+    }
+
+    public static CacheRegister getCacheRegisterBlocking() {
+        try {
+            cacheRegisterLatch.await();
+        } catch (InterruptedException e) {
+            LOGGER.warn(e);
+        } finally {
+            return cacheRegister;
+        }
     }
 
     public static NetworkNode generateTree(final File f, final boolean verifyOnly, final
boolean useDeep) throws IOException  {
@@ -129,7 +141,7 @@ public class NetworkNode implements Comparable<NetworkNode> {
                             }
                             // Get the cache from the cacheregister here - don't create a
new cache due to the deep file, only reuse the
                             // ones we already know about.
-                            final Cache cache = cacheRegister.getCacheMap().get(cacheHostname);
+                            final Cache cache = getCacheRegisterBlocking().getCacheMap().get(cacheHostname);
                             if (cache == null) {
                                 LOGGER.warn("DDC: deep cache entry " + cacheHostname + "
not found in crconfig server list (it might not belong to this CDN)");
                             } else {
diff --git a/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml b/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
index d416a3f..fb5cca3 100644
--- a/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
+++ b/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
@@ -191,7 +191,7 @@
 	</bean>
 
 	<bean id="languidState" class="com.comcast.cdn.traffic_control.traffic_router.core.util.LanguidState"
init-method="init"
-		depends-on="geolocationDatabaseUpdater, networkUpdater, regionalGeoUpdater, MonitorWatcher,
trafficRouterManager, ConfigHandler">
+		depends-on="geolocationDatabaseUpdater, networkUpdater, deepNetworkUpdater, regionalGeoUpdater,
MonitorWatcher, trafficRouterManager, ConfigHandler">
 		<!-- todo: add bean refs that can be validated inside the method called -->
 		<property name="trafficRouterManager" ref="trafficRouterManager" />
 	</bean>

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

Mime
View raw message