VTN: offload more of the event handling off of the Atomix event thread.
Change-Id: Icd42fad7f4ae436b95b83acf9528720a06d03e71
diff --git a/src/main/java/org/opencord/cordvtn/impl/CordVtnNodeManager.java b/src/main/java/org/opencord/cordvtn/impl/CordVtnNodeManager.java
index 8a8bc37..2e51c6a 100644
--- a/src/main/java/org/opencord/cordvtn/impl/CordVtnNodeManager.java
+++ b/src/main/java/org/opencord/cordvtn/impl/CordVtnNodeManager.java
@@ -220,7 +220,7 @@
.withApplicationId(appId)
.build();
- nodeStore.addListener(nodeStoreListener);
+ nodeStore.addListener(nodeStoreListener, eventExecutor);
deviceService.addListener(deviceListener);
configService.addListener(configListener);
@@ -906,30 +906,30 @@
CordVtnNode newNode;
switch (event.type()) {
- case UPDATE:
- oldNode = event.oldValue().value();
- newNode = event.newValue().value();
+ case UPDATE:
+ oldNode = event.oldValue().value();
+ newNode = event.newValue().value();
- log.info("Reloaded {}", newNode.hostname());
- if (!newNode.equals(oldNode)) {
- log.debug("New node: {}", newNode);
- }
- // performs init procedure even if the node is not changed
- // for robustness since it's no harm to run init procedure
- // multiple times
- eventExecutor.execute(() -> initNode(newNode));
- break;
- case INSERT:
- newNode = event.newValue().value();
- log.info("Added {}", newNode.hostname());
- eventExecutor.execute(() -> initNode(newNode));
- break;
- case REMOVE:
- oldNode = event.oldValue().value();
- log.info("Removed {}", oldNode.hostname());
- break;
- default:
- break;
+ log.info("Reloaded {}", newNode.hostname());
+ if (!newNode.equals(oldNode)) {
+ log.debug("New node: {}", newNode);
+ }
+ // performs init procedure even if the node is not changed
+ // for robustness since it's no harm to run init procedure
+ // multiple times
+ initNode(newNode);
+ break;
+ case INSERT:
+ newNode = event.newValue().value();
+ log.info("Added {}", newNode.hostname());
+ initNode(newNode);
+ break;
+ case REMOVE:
+ oldNode = event.oldValue().value();
+ log.info("Removed {}", oldNode.hostname());
+ break;
+ default:
+ break;
}
}
}
diff --git a/src/main/java/org/opencord/cordvtn/impl/handler/AbstractInstanceHandler.java b/src/main/java/org/opencord/cordvtn/impl/handler/AbstractInstanceHandler.java
index dc6a0d6..64cda2e 100644
--- a/src/main/java/org/opencord/cordvtn/impl/handler/AbstractInstanceHandler.java
+++ b/src/main/java/org/opencord/cordvtn/impl/handler/AbstractInstanceHandler.java
@@ -122,6 +122,10 @@
@Override
public void event(HostEvent event) {
+ eventExecutor.execute(() -> handle(event));
+ }
+
+ private void handle(HostEvent event) {
Host host = event.subject();
if (!mastershipService.isLocalMaster(host.location().deviceId())) {
// do not allow to proceed without mastership
@@ -135,17 +139,17 @@
}
switch (event.type()) {
- case HOST_UPDATED:
- eventExecutor.execute(() -> instanceUpdated(instance));
- break;
- case HOST_ADDED:
- eventExecutor.execute(() -> instanceDetected(instance));
- break;
- case HOST_REMOVED:
- eventExecutor.execute(() -> instanceRemoved(instance));
- break;
- default:
- break;
+ case HOST_UPDATED:
+ instanceUpdated(instance);
+ break;
+ case HOST_ADDED:
+ instanceDetected(instance);
+ break;
+ case HOST_REMOVED:
+ instanceRemoved(instance);
+ break;
+ default:
+ break;
}
}
}