zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject [zookeeper] branch master updated: ZOOKEEPER-3415: convert internal logic to use java8 streams
Date Fri, 24 Jul 2020 09:27:55 GMT
This is an automated email from the ASF dual-hosted git repository.

andor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 281a7c3  ZOOKEEPER-3415: convert internal logic to use java8 streams
281a7c3 is described below

commit 281a7c30c4485c34ea11e7051e55ebf6a859b993
Author: Shyam Sundar J <shyamsundarcoolz@gmail.com>
AuthorDate: Fri Jul 24 11:27:47 2020 +0200

    ZOOKEEPER-3415: convert internal logic to use java8 streams
    
    I have refactored few for loops that perform just some filtering and collections
    
    Author: Shyam Sundar J <shyamsundarcoolz@gmail.com>
    
    Reviewers: eolivelli@apache.org, andor@apache.org
    
    Closes #1311 from severussundar/ZOOKEEPER-3415 and squashes the following commits:
    
    f07461cd7 [Shyam Sundar J] Merge branch 'master' into ZOOKEEPER-3415
    78ed4c8ec [Shyam Sundar J] removing extra whitespaces and newlines
    6fd7751de [Shyam Sundar J] removing unused imports and tabs
    cb133fd33 [Shyam Sundar J] Merge branch 'master' of https://github.com/apache/zookeeper
into ZOOKEEPER-3415
    3f9a39a62 [Shyam Sundar J] ZOOKEEPER-3415 :convert internal logic to use java8 streams
---
 .../apache/zookeeper/server/ZooKeeperServer.java    | 21 ++++-----------------
 .../zookeeper/server/admin/JettyAdminServer.java    | 12 ++----------
 2 files changed, 6 insertions(+), 27 deletions(-)

diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperServer.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperServer.java
index 9d09024..6543842 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperServer.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperServer.java
@@ -498,17 +498,9 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider
{
         }
 
         // Clean up dead sessions
-        List<Long> deadSessions = new ArrayList<>();
-        for (Long session : zkDb.getSessions()) {
-            if (zkDb.getSessionWithTimeOuts().get(session) == null) {
-                deadSessions.add(session);
-            }
-        }
-
-        for (long session : deadSessions) {
-            // TODO: Is lastProcessedZxid really the best thing to use?
-            killSession(session, zkDb.getDataTreeLastProcessedZxid());
-        }
+        zkDb.getSessions().stream()
+                        .filter(session -> zkDb.getSessionWithTimeOuts().get(session)
== null)
+                        .forEach(session -> killSession(session, zkDb.getDataTreeLastProcessedZxid()));
 
         // Make a clean snapshot
         takeSnapshot();
@@ -1648,12 +1640,7 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider
{
     }
 
     private boolean hasCnxSASLAuthenticated(ServerCnxn cnxn) {
-        for (Id id : cnxn.getAuthInfo()) {
-            if (id.getScheme().equals(SASL_AUTH_SCHEME)) {
-                return true;
-            }
-        }
-        return false;
+        return cnxn.getAuthInfo().stream().anyMatch(id -> id.getScheme().equals(SASL_AUTH_SCHEME));
     }
 
     private void processSasl(ByteBuffer incomingBuffer, ServerCnxn cnxn, RequestHeader requestHeader)
throws IOException {
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/JettyAdminServer.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/JettyAdminServer.java
index 6845f23..aa18cfb 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/JettyAdminServer.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/JettyAdminServer.java
@@ -21,11 +21,10 @@ package org.apache.zookeeper.server.admin;
 import java.io.IOException;
 import java.security.GeneralSecurityException;
 import java.security.KeyStore;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -260,14 +259,7 @@ public class JettyAdminServer implements AdminServer {
      * Returns a list of URLs to each registered Command.
      */
     private List<String> commandLinks() {
-        List<String> links = new ArrayList<String>();
-        List<String> commands = new ArrayList<String>(Commands.getPrimaryNames());
-        Collections.sort(commands);
-        for (String command : commands) {
-            String url = commandUrl + "/" + command;
-            links.add(String.format("<a href=\"%s\">%s</a>", url, command));
-        }
-        return links;
+        return Commands.getPrimaryNames().stream().sorted().map(command -> String.format("<a
href=\"%s\">%s</a>", commandUrl + "/" + command , command)).collect(Collectors.toList());
     }
 
     /**


Mime
View raw message