ONOS-1992 Improving IntentCleanup configurability and adding enabled property
Change-Id: Id6daa33448a3ffee91e98a61e4bea24d1f8c06ca
Showing
1 changed file
with
26 additions
and
12 deletions
... | @@ -61,6 +61,10 @@ public class IntentCleanup implements Runnable, IntentListener { | ... | @@ -61,6 +61,10 @@ public class IntentCleanup implements Runnable, IntentListener { |
61 | private static final int DEFAULT_PERIOD = 5; //seconds | 61 | private static final int DEFAULT_PERIOD = 5; //seconds |
62 | private static final int DEFAULT_THRESHOLD = 5; //tries | 62 | private static final int DEFAULT_THRESHOLD = 5; //tries |
63 | 63 | ||
64 | + @Property(name = "enabled", boolValue = true, | ||
65 | + label = "Enables/disables the intent cleanup component") | ||
66 | + private boolean enabled = true; | ||
67 | + | ||
64 | @Property(name = "period", intValue = DEFAULT_PERIOD, | 68 | @Property(name = "period", intValue = DEFAULT_PERIOD, |
65 | label = "Frequency in ms between cleanup runs") | 69 | label = "Frequency in ms between cleanup runs") |
66 | protected int period = DEFAULT_PERIOD; | 70 | protected int period = DEFAULT_PERIOD; |
... | @@ -108,40 +112,50 @@ public class IntentCleanup implements Runnable, IntentListener { | ... | @@ -108,40 +112,50 @@ public class IntentCleanup implements Runnable, IntentListener { |
108 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); | 112 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
109 | 113 | ||
110 | int newPeriod; | 114 | int newPeriod; |
115 | + boolean newEnabled; | ||
111 | try { | 116 | try { |
112 | String s = get(properties, "period"); | 117 | String s = get(properties, "period"); |
113 | newPeriod = isNullOrEmpty(s) ? period : Integer.parseInt(s.trim()); | 118 | newPeriod = isNullOrEmpty(s) ? period : Integer.parseInt(s.trim()); |
114 | 119 | ||
115 | s = get(properties, "retryThreshold"); | 120 | s = get(properties, "retryThreshold"); |
116 | - retryThreshold = isNullOrEmpty(s) ? period : Integer.parseInt(s.trim()); | 121 | + retryThreshold = isNullOrEmpty(s) ? retryThreshold : Integer.parseInt(s.trim()); |
122 | + | ||
123 | + s = get(properties, "enabled"); | ||
124 | + newEnabled = isNullOrEmpty(s) ? enabled : Boolean.parseBoolean(s.trim()); | ||
117 | } catch (NumberFormatException e) { | 125 | } catch (NumberFormatException e) { |
118 | log.warn(e.getMessage()); | 126 | log.warn(e.getMessage()); |
119 | newPeriod = period; | 127 | newPeriod = period; |
128 | + newEnabled = enabled; | ||
120 | } | 129 | } |
121 | 130 | ||
122 | // Any change in the following parameters implies hard restart | 131 | // Any change in the following parameters implies hard restart |
123 | - if (newPeriod != period) { | 132 | + if (newPeriod != period || enabled != newEnabled) { |
124 | period = newPeriod; | 133 | period = newPeriod; |
134 | + enabled = newEnabled; | ||
125 | adjustRate(); | 135 | adjustRate(); |
126 | } | 136 | } |
127 | 137 | ||
128 | - log.info("Settings: period={}", period); | 138 | + log.info("Settings: enabled={}, period={}, retryThreshold={}", |
139 | + enabled, period, retryThreshold); | ||
129 | } | 140 | } |
130 | 141 | ||
131 | protected void adjustRate() { | 142 | protected void adjustRate() { |
132 | if (timerTask != null) { | 143 | if (timerTask != null) { |
133 | timerTask.cancel(); | 144 | timerTask.cancel(); |
145 | + timerTask = null; | ||
134 | } | 146 | } |
135 | 147 | ||
136 | - timerTask = new TimerTask() { | 148 | + if (enabled) { |
137 | - @Override | 149 | + timerTask = new TimerTask() { |
138 | - public void run() { | 150 | + @Override |
139 | - executor.submit(IntentCleanup.this); | 151 | + public void run() { |
140 | - } | 152 | + executor.submit(IntentCleanup.this); |
141 | - }; | 153 | + } |
154 | + }; | ||
142 | 155 | ||
143 | - periodMs = period * 1_000; //convert to ms | 156 | + periodMs = period * 1_000; //convert to ms |
144 | - timer.scheduleAtFixedRate(timerTask, periodMs, periodMs); | 157 | + timer.scheduleAtFixedRate(timerTask, periodMs, periodMs); |
158 | + } | ||
145 | } | 159 | } |
146 | 160 | ||
147 | 161 | ||
... | @@ -224,7 +238,7 @@ public class IntentCleanup implements Runnable, IntentListener { | ... | @@ -224,7 +238,7 @@ public class IntentCleanup implements Runnable, IntentListener { |
224 | public void event(IntentEvent event) { | 238 | public void event(IntentEvent event) { |
225 | // this is the fast path for CORRUPT intents, retry on event notification. | 239 | // this is the fast path for CORRUPT intents, retry on event notification. |
226 | //TODO we might consider using the timer to back off for subsequent retries | 240 | //TODO we might consider using the timer to back off for subsequent retries |
227 | - if (event.type() == IntentEvent.Type.CORRUPT) { | 241 | + if (enabled && event.type() == IntentEvent.Type.CORRUPT) { |
228 | Key key = event.subject().key(); | 242 | Key key = event.subject().key(); |
229 | if (store.isMaster(key)) { | 243 | if (store.isMaster(key)) { |
230 | IntentData data = store.getIntentData(event.subject().key()); | 244 | IntentData data = store.getIntentData(event.subject().key()); | ... | ... |
-
Please register or login to post a comment