Skip to content
Permalink
Browse files

Improved: Use the ‘Deque’ interface in ‘ContainerLoader’

(OFBIZ-11099)

With a deque it is possible to iterate from the end of a list with
‘Deque#descendingIterator’ which is useful when unloading containers.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1860954 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jun 10, 2019
1 parent 8a681cd commit 266e0d0a872820c9d2e25a912316ed1c1742eb75
@@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@@ -49,7 +50,7 @@

public static final String module = ContainerLoader.class.getName();

private final List<Container> loadedContainers = new LinkedList<>();
private final Deque<Container> loadedContainers = new LinkedList<>();

/**
* Starts the containers.
@@ -166,18 +167,14 @@ private void startLoadedContainers() throws StartupException {
*/
public synchronized void unload() {
Debug.logInfo("Shutting down containers", module);

List<Container> reversedContainerList = new ArrayList<>(loadedContainers);
Collections.reverse(reversedContainerList);

for(Container loadedContainer : reversedContainerList) {
loadedContainers.descendingIterator().forEachRemaining(loadedContainer -> {
Debug.logInfo("Stopping container " + loadedContainer.getName(), module);
try {
loadedContainer.stop();
} catch (ContainerException e) {
Debug.logError(e, module);
}
Debug.logInfo("Stopped container " + loadedContainer.getName(), module);
}
});
}
}

0 comments on commit 266e0d0

Please sign in to comment.
You can’t perform that action at this time.