Committed by
Gerrit Code Review
Making IntentSynchronizer more generic to be used with other classes. Deleting SDN-IP nomenclature.
Change-Id: I779a8dab82fea00fb0d261d63b598d863693e332
Showing
1 changed file
with
21 additions
and
21 deletions
| ... | @@ -49,9 +49,9 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -49,9 +49,9 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 49 | private final Map<Key, Intent> intents; | 49 | private final Map<Key, Intent> intents; |
| 50 | 50 | ||
| 51 | // | 51 | // |
| 52 | - // State to deal with SDN-IP Leader election and pushing Intents | 52 | + // State to deal with the Leader election and pushing Intents |
| 53 | // | 53 | // |
| 54 | - private final ExecutorService bgpIntentsSynchronizerExecutor; | 54 | + private final ExecutorService intentsSynchronizerExecutor; |
| 55 | private volatile boolean isElectedLeader = false; | 55 | private volatile boolean isElectedLeader = false; |
| 56 | private volatile boolean isActivatedLeader = false; | 56 | private volatile boolean isActivatedLeader = false; |
| 57 | 57 | ||
| ... | @@ -61,9 +61,9 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -61,9 +61,9 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 61 | * @param appId the Application ID | 61 | * @param appId the Application ID |
| 62 | * @param intentService the intent service | 62 | * @param intentService the intent service |
| 63 | */ | 63 | */ |
| 64 | - IntentSynchronizer(ApplicationId appId, IntentService intentService) { | 64 | + public IntentSynchronizer(ApplicationId appId, IntentService intentService) { |
| 65 | this(appId, intentService, | 65 | this(appId, intentService, |
| 66 | - newSingleThreadExecutor(groupedThreads("onos/sdnip", "sync"))); | 66 | + newSingleThreadExecutor(groupedThreads("onos/" + appId, "sync"))); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | /** | 69 | /** |
| ... | @@ -80,7 +80,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -80,7 +80,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 80 | 80 | ||
| 81 | intents = new ConcurrentHashMap<>(); | 81 | intents = new ConcurrentHashMap<>(); |
| 82 | 82 | ||
| 83 | - bgpIntentsSynchronizerExecutor = executorService; | 83 | + intentsSynchronizerExecutor = executorService; |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | /** | 86 | /** |
| ... | @@ -96,10 +96,10 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -96,10 +96,10 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 96 | public void stop() { | 96 | public void stop() { |
| 97 | synchronized (this) { | 97 | synchronized (this) { |
| 98 | // Stop the thread(s) | 98 | // Stop the thread(s) |
| 99 | - bgpIntentsSynchronizerExecutor.shutdownNow(); | 99 | + intentsSynchronizerExecutor.shutdownNow(); |
| 100 | 100 | ||
| 101 | // | 101 | // |
| 102 | - // Withdraw all SDN-IP intents | 102 | + // Withdraw all app related intents |
| 103 | // | 103 | // |
| 104 | if (!isElectedLeader) { | 104 | if (!isElectedLeader) { |
| 105 | return; // Nothing to do: not the leader anymore | 105 | return; // Nothing to do: not the leader anymore |
| ... | @@ -115,7 +115,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -115,7 +115,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 115 | // Build a batch operation to withdraw all intents from this | 115 | // Build a batch operation to withdraw all intents from this |
| 116 | // application. | 116 | // application. |
| 117 | // | 117 | // |
| 118 | - log.debug("SDN-IP Intent Synchronizer shutdown: " + | 118 | + log.debug("Intent Synchronizer shutdown: " + |
| 119 | "withdrawing all intents..."); | 119 | "withdrawing all intents..."); |
| 120 | IntentOperations.Builder builder = IntentOperations.builder(appId); | 120 | IntentOperations.Builder builder = IntentOperations.builder(appId); |
| 121 | for (Intent intent : intentService.getIntents()) { | 121 | for (Intent intent : intentService.getIntents()) { |
| ... | @@ -133,7 +133,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -133,7 +133,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 133 | continue; | 133 | continue; |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | - log.trace("SDN-IP Intent Synchronizer withdrawing intent: {}", | 136 | + log.trace("Intent Synchronizer withdrawing intent: {}", |
| 137 | intent); | 137 | intent); |
| 138 | builder.addWithdrawOperation(intent.id()); | 138 | builder.addWithdrawOperation(intent.id()); |
| 139 | } | 139 | } |
| ... | @@ -143,7 +143,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -143,7 +143,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 143 | 143 | ||
| 144 | peerIntents.clear(); | 144 | peerIntents.clear(); |
| 145 | routeIntents.clear(); | 145 | routeIntents.clear(); |
| 146 | - log.debug("SDN-IP Intent Synchronizer shutdown completed"); | 146 | + log.debug("Intent Synchronizer shutdown completed"); |
| 147 | */ | 147 | */ |
| 148 | } | 148 | } |
| 149 | } | 149 | } |
| ... | @@ -153,7 +153,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -153,7 +153,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 153 | synchronized (this) { | 153 | synchronized (this) { |
| 154 | intents.put(intent.key(), intent); | 154 | intents.put(intent.key(), intent); |
| 155 | if (isElectedLeader && isActivatedLeader) { | 155 | if (isElectedLeader && isActivatedLeader) { |
| 156 | - log.trace("SDN-IP Submitting intent: {}", intent); | 156 | + log.trace("Submitting intent: {}", intent); |
| 157 | intentService.submit(intent); | 157 | intentService.submit(intent); |
| 158 | } | 158 | } |
| 159 | } | 159 | } |
| ... | @@ -164,19 +164,19 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -164,19 +164,19 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 164 | synchronized (this) { | 164 | synchronized (this) { |
| 165 | intents.remove(intent.key(), intent); | 165 | intents.remove(intent.key(), intent); |
| 166 | if (isElectedLeader && isActivatedLeader) { | 166 | if (isElectedLeader && isActivatedLeader) { |
| 167 | - log.trace("SDN-IP Withdrawing intent: {}", intent); | 167 | + log.trace("Withdrawing intent: {}", intent); |
| 168 | intentService.withdraw(intent); | 168 | intentService.withdraw(intent); |
| 169 | } | 169 | } |
| 170 | } | 170 | } |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | /** | 173 | /** |
| 174 | - * Signals the synchronizer that the SDN-IP leadership has changed. | 174 | + * Signals the synchronizer that the leadership has changed. |
| 175 | * | 175 | * |
| 176 | * @param isLeader true if this instance is now the leader, otherwise false | 176 | * @param isLeader true if this instance is now the leader, otherwise false |
| 177 | */ | 177 | */ |
| 178 | public void leaderChanged(boolean isLeader) { | 178 | public void leaderChanged(boolean isLeader) { |
| 179 | - log.debug("SDN-IP Leader changed: {}", isLeader); | 179 | + log.debug("Leader changed: {}", isLeader); |
| 180 | 180 | ||
| 181 | if (!isLeader) { | 181 | if (!isLeader) { |
| 182 | this.isElectedLeader = false; | 182 | this.isElectedLeader = false; |
| ... | @@ -187,7 +187,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -187,7 +187,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 187 | this.isElectedLeader = true; | 187 | this.isElectedLeader = true; |
| 188 | 188 | ||
| 189 | // Run the synchronization method off-thread | 189 | // Run the synchronization method off-thread |
| 190 | - bgpIntentsSynchronizerExecutor.execute(this::synchronizeIntents); | 190 | + intentsSynchronizerExecutor.execute(this::synchronizeIntents); |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | private void synchronizeIntents() { | 193 | private void synchronizeIntents() { |
| ... | @@ -225,17 +225,17 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -225,17 +225,17 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 225 | } | 225 | } |
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | - log.debug("SDN-IP Intent Synchronizer: submitting {}, withdrawing {}", | 228 | + log.debug("Intent Synchronizer: submitting {}, withdrawing {}", |
| 229 | intentsToAdd.size(), intentsToRemove.size()); | 229 | intentsToAdd.size(), intentsToRemove.size()); |
| 230 | 230 | ||
| 231 | // Withdraw Intents | 231 | // Withdraw Intents |
| 232 | for (Intent intent : intentsToRemove) { | 232 | for (Intent intent : intentsToRemove) { |
| 233 | intentService.withdraw(intent); | 233 | intentService.withdraw(intent); |
| 234 | - log.trace("SDN-IP Intent Synchronizer: withdrawing intent: {}", | 234 | + log.trace("Intent Synchronizer: withdrawing intent: {}", |
| 235 | intent); | 235 | intent); |
| 236 | } | 236 | } |
| 237 | if (!isElectedLeader) { | 237 | if (!isElectedLeader) { |
| 238 | - log.debug("SDN-IP Intent Synchronizer: cannot withdraw intents: " + | 238 | + log.debug("Intent Synchronizer: cannot withdraw intents: " + |
| 239 | "not elected leader anymore"); | 239 | "not elected leader anymore"); |
| 240 | isActivatedLeader = false; | 240 | isActivatedLeader = false; |
| 241 | return; | 241 | return; |
| ... | @@ -244,11 +244,11 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -244,11 +244,11 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 244 | // Add Intents | 244 | // Add Intents |
| 245 | for (Intent intent : intentsToAdd) { | 245 | for (Intent intent : intentsToAdd) { |
| 246 | intentService.submit(intent); | 246 | intentService.submit(intent); |
| 247 | - log.trace("SDN-IP Intent Synchronizer: submitting intent: {}", | 247 | + log.trace("Intent Synchronizer: submitting intent: {}", |
| 248 | intent); | 248 | intent); |
| 249 | } | 249 | } |
| 250 | if (!isElectedLeader) { | 250 | if (!isElectedLeader) { |
| 251 | - log.debug("SDN-IP Intent Synchronizer: cannot submit intents: " + | 251 | + log.debug("Intent Synchronizer: cannot submit intents: " + |
| 252 | "not elected leader anymore"); | 252 | "not elected leader anymore"); |
| 253 | isActivatedLeader = false; | 253 | isActivatedLeader = false; |
| 254 | return; | 254 | return; |
| ... | @@ -259,7 +259,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -259,7 +259,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
| 259 | } else { | 259 | } else { |
| 260 | isActivatedLeader = false; | 260 | isActivatedLeader = false; |
| 261 | } | 261 | } |
| 262 | - log.debug("SDN-IP intent synchronization completed"); | 262 | + log.debug("Intent synchronization completed"); |
| 263 | } | 263 | } |
| 264 | 264 | ||
| 265 | } | 265 | } | ... | ... |
-
Please register or login to post a comment