maoling commented on a change in pull request #1306: ZOOKEEPER-3415: Convert
internal logic to use streams
URL: https://github.com/apache/zookeeper/pull/1306#discussion_r403873499
##########
File path:
zookeeper-server/src/main/java/org/apache/zookeeper/server/ContainerManager.java
##########
@@ -125,24 +125,29 @@ public void stop() {
*/
public void checkContainers() throws InterruptedException {
long minIntervalMs = getMinIntervalMs();
- for (String containerPath : getCandidates()) {
- long startMs = Time.currentElapsedTime();
-
- ByteBuffer path = ByteBuffer.wrap(containerPath.getBytes());
- Request request = new Request(null, 0, 0,
ZooDefs.OpCode.deleteContainer, path, null);
- try {
- LOG.info("Attempting to delete candidate container: {}",
containerPath);
- postDeleteRequest(request);
- } catch (Exception e) {
- LOG.error("Could not delete container: {}", containerPath, e);
- }
+ getCandidates().stream()
+ .forEach(containerPath -> {
+ long startMs = Time.currentElapsedTime();
- long elapsedMs = Time.currentElapsedTime() - startMs;
- long waitMs = minIntervalMs - elapsedMs;
- if (waitMs > 0) {
- Thread.sleep(waitMs);
- }
- }
+ ByteBuffer path =
ByteBuffer.wrap(containerPath.getBytes());
+ Request request = new Request(null, 0, 0,
ZooDefs.OpCode.deleteContainer, path, null);
+ try {
+ LOG.info("Attempting to delete candidate container:
{}", containerPath);
+ postDeleteRequest(request);
+ } catch (Exception e) {
+ LOG.error("Could not delete container: {}",
containerPath, e);
+ }
+
+ long elapsedMs = Time.currentElapsedTime() - startMs;
+ long waitMs = minIntervalMs - elapsedMs;
+ if (waitMs > 0) {
+ try {
+ Thread.sleep(waitMs);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
}
Review comment:
this change makes the body of `forEach` so fat? just a personal aesthetics.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services