You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@heron.apache.org by nw...@apache.org on 2018/12/17 17:24:39 UTC

[incubator-heron] branch master updated: Add util function for registerTopologyTimerEvents in Config (#3126)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new a201965  Add util function for registerTopologyTimerEvents in Config (#3126)
a201965 is described below

commit a201965b269291942fffda038810bd7514c2e1e0
Author: Ning Wang <nw...@twitter.com>
AuthorDate: Mon Dec 17 09:24:34 2018 -0800

    Add util function for registerTopologyTimerEvents in Config (#3126)
---
 .../api/src/java/org/apache/heron/api/Config.java  | 54 ++++++++++++----------
 1 file changed, 29 insertions(+), 25 deletions(-)

diff --git a/heron/api/src/java/org/apache/heron/api/Config.java b/heron/api/src/java/org/apache/heron/api/Config.java
index 1607e39..3ee4b47 100644
--- a/heron/api/src/java/org/apache/heron/api/Config.java
+++ b/heron/api/src/java/org/apache/heron/api/Config.java
@@ -630,6 +630,33 @@ public class Config extends HashMap<String, Object> {
     conf.put(Config.TOPOLOGY_ENVIRONMENT, env);
   }
 
+  /**
+   * Registers a timer event that executes periodically
+   * @param conf the map with the existing topology configs
+   * @param name the name of the timer
+   * @param interval the frequency in which to run the task
+   * @param task the task to run
+   */
+  @SuppressWarnings("unchecked")
+  public static void registerTopologyTimerEvents(Map<String, Object> conf,
+                                                 String name, Duration interval,
+                                                 Runnable task) {
+    if (interval.isZero() || interval.isNegative()) {
+      throw new IllegalArgumentException("Timer duration needs to be positive");
+    }
+    if (!conf.containsKey(Config.TOPOLOGY_TIMER_EVENTS)) {
+      conf.put(Config.TOPOLOGY_TIMER_EVENTS, new HashMap<String, Pair<Duration, Runnable>>());
+    }
+
+    Map<String, Pair<Duration, Runnable>> timers
+        = (Map<String, Pair<Duration, Runnable>>) conf.get(Config.TOPOLOGY_TIMER_EVENTS);
+
+    if (timers.containsKey(name)) {
+      throw new IllegalArgumentException("Timer with name " + name + " already exists");
+    }
+    timers.put(name, Pair.of(interval, task));
+  }
+
   public void setDebug(boolean isOn) {
     setDebug(this, isOn);
   }
@@ -811,31 +838,8 @@ public class Config extends HashMap<String, Object> {
     setMetricsmgrRam(this, ramInBytes);
   }
 
-  /**
-   * Registers a timer event that executes periodically
-   * @param conf the map with the existing topology configs
-   * @param name the name of the timer
-   * @param interval the frequency in which to run the task
-   * @param task the task to run
-   */
-  @SuppressWarnings("unchecked")
-  public static void registerTopologyTimerEvents(Map<String, Object> conf,
-                                                 String name, Duration interval,
-                                                 Runnable task) {
-    if (interval.isZero() || interval.isNegative()) {
-      throw new IllegalArgumentException("Timer duration needs to be positive");
-    }
-    if (!conf.containsKey(Config.TOPOLOGY_TIMER_EVENTS)) {
-      conf.put(Config.TOPOLOGY_TIMER_EVENTS, new HashMap<String, Pair<Duration, Runnable>>());
-    }
-
-    Map<String, Pair<Duration, Runnable>> timers
-        = (Map<String, Pair<Duration, Runnable>>) conf.get(Config.TOPOLOGY_TIMER_EVENTS);
-
-    if (timers.containsKey(name)) {
-      throw new IllegalArgumentException("Timer with name " + name + " already exists");
-    }
-    timers.put(name, Pair.of(interval, task));
+  public void registerTopologyTimerEvents(String name, Duration interval, Runnable task) {
+    registerTopologyTimerEvents(this, name, interval, task);
   }
 
   public void setTopologyRemoteDebugging(boolean isOn) {