From issues-return-34-archive-asf-public=cust-asf.ponee.io@zookeeper.apache.org Wed Jun 5 17:41:02 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 4E083180763 for ; Wed, 5 Jun 2019 19:41:02 +0200 (CEST) Received: (qmail 84790 invoked by uid 500); 5 Jun 2019 17:41:01 -0000 Mailing-List: contact issues-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zookeeper.apache.org Delivered-To: mailing list issues@zookeeper.apache.org Received: (qmail 84733 invoked by uid 99); 5 Jun 2019 17:41:01 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Jun 2019 17:41:01 +0000 Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id D916FE2BA4 for ; Wed, 5 Jun 2019 17:41:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 988CE2459D for ; Wed, 5 Jun 2019 17:41:00 +0000 (UTC) Date: Wed, 5 Jun 2019 17:41:00 +0000 (UTC) From: "Brian Nixon (JIRA)" To: issues@zookeeper.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (ZOOKEEPER-3415) convert internal logic to use java 8 streams MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/ZOOKEEPER-3415?page=3Dcom.atlas= sian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D= 16856900#comment-16856900 ]=20 Brian Nixon commented on ZOOKEEPER-3415: ---------------------------------------- As an example: =C2=A0 {code:java} +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperS= erver.java @@ -37,6 +37,7 @@ =C2=A0import java.util.concurrent.atomic.AtomicInteger; =C2=A0import java.util.concurrent.atomic.AtomicLong; =C2=A0import java.util.function.BiConsumer; +import java.util.stream.Collectors; =C2=A0import javax.security.sasl.SaslException; @@ -383,17 +384,9 @@ public void loadData() throws IOException, Interrupted= Exception { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // Clean up dead sessions -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 List deadSessions =3D new= ArrayList<>(); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for (Long session : zkDb.getSes= sions()) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (zkD= b.getSessionWithTimeOuts().get(session) =3D=3D null) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 deadSessions.add(session); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } - -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for (long session : deadSession= s) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // XXX:= Is lastProcessedZxid really the best thing to use? -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 killSes= sion(session, zkDb.getDataTreeLastProcessedZxid()); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 zkDb.getSessions().stream() +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 .filter(session -> zkDb.getSessionWithTimeOuts().get(ses= sion) =3D=3D null) +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 .forEach(session -> killSession(session, zkDb.getDataTre= eLastProcessedZxid())); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // Make a clean snapshot =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 takeSnapshot(); {code} > convert internal logic to use java 8 streams > -------------------------------------------- > > Key: ZOOKEEPER-3415 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-3415 > Project: ZooKeeper > Issue Type: Wish > Affects Versions: 3.6.0 > Reporter: Brian Nixon > Priority: Trivial > > There are a number of places in the code where for loops are used to perf= orm basic filtering and collection. The java 8 stream api's make these oper= ations much more polished. Since the master branch has been at this languag= e level for a while, I'd wish for a (series of) refactor(s) to convert more= of these loops to streams. -- This message was sent by Atlassian JIRA (v7.6.3#76005)