Skip to content

Commit

Permalink
#71 - Stop all controllers in case of shell replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Hossfeld committed Aug 10, 2019
1 parent a5e4188 commit 2b58da8
Showing 1 changed file with 48 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ void handleRouting(String hash) {
// check whether or not the routing is possible ...
if (this.confirmRouting(routeConfigurations)) {
// call stop for all elements
this.stopController(routeConfigurations);
this.stopController(routeConfigurations,
!routeResult.getShell()
.equals(this.lastAddedShell));
// handle shellCreator
//
// in case shellCreator changed or is not set, use the actual shellCreator!
Expand Down Expand Up @@ -698,47 +700,52 @@ private boolean confirmRouting(List<RouteConfig> routeConfigurations) {
.allMatch(message -> this.plugin.confirm(message));
}

private void stopController(List<RouteConfig> routeConfiguraions) {
routeConfiguraions.stream()
.map(config -> this.activeComponents.get(config.getSelector()))
.filter(Objects::nonNull)
.forEach(controller -> {
// stop controller
RouterLogger.logControllerHandlingStop(controller.getClass()
.getCanonicalName());
RouterLogger.logControllerHandlingStopComposites(controller.getClass()
.getCanonicalName());
// stop compositeComntrollers
controller.getComposites()
.values()
.forEach(s -> {
if (controller.isCached()) {
deactivateCompositeController(controller,
s);
} else {
if (s.isCached()) {
deactivateCompositeController(controller,
s);
} else {
stopCompositeController(controller,
s);
}
}
});

RouterLogger.logControllerCompositesStopped(controller.getClass()
.getCanonicalName());
if (controller.isCached()) {
deactivateController(controller);
} else {
stopController(controller);
}
});
private void stopController(List<RouteConfig> routeConfiguraions,
boolean replaceShell) {
List<AbstractComponentController<?, ?, ?>> controllerList = new ArrayList<>();
if (replaceShell) {
controllerList.addAll(this.activeComponents.values());
} else {
controllerList.addAll(routeConfiguraions.stream()
.map(config -> this.activeComponents.get(config.getSelector()))
.filter(Objects::nonNull)
.collect(Collectors.toList()));

}
controllerList.forEach(controller -> {
// stop controller
RouterLogger.logControllerHandlingStop(controller.getClass()
.getCanonicalName());
RouterLogger.logControllerHandlingStopComposites(controller.getClass()
.getCanonicalName());
// stop compositeComntrollers
controller.getComposites()
.values()
.forEach(s -> {
if (controller.isCached()) {
deactivateCompositeController(controller,
s);
} else {
if (s.isCached()) {
deactivateCompositeController(controller,
s);
} else {
stopCompositeController(controller,
s);
}
}
});

RouterLogger.logControllerCompositesStopped(controller.getClass()
.getCanonicalName());
if (controller.isCached()) {
deactivateController(controller);
} else {
stopController(controller);
}
});
routeConfiguraions.forEach(routeConfiguraion -> this.plugin.remove(routeConfiguraion.getSelector()));
routeConfiguraions.stream()
.map(config -> this.activeComponents.get(config.getSelector()))
.filter(Objects::nonNull)
.forEach(c -> this.activeComponents.remove(c));
controllerList.forEach(c -> this.activeComponents.remove(c));
}

private void deactivateController(AbstractComponentController<?, ?, ?> controller) {
Expand Down

0 comments on commit 2b58da8

Please sign in to comment.