From 3748ed5f8e1023c3e24f598c447de0d9cddd30b2 Mon Sep 17 00:00:00 2001 From: Tamas Penzes Date: Mon, 11 Sep 2017 09:55:05 -0700 Subject: [PATCH 1/2] =?UTF-8?q?ZOOKEEPER-2630:=20Use=20interface=20type=20?= =?UTF-8?q?instead=20of=20implementation=20type=20whe=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use interface type instead of implementation type when appropriate. There are a couple of places in code base where we declare a field / variable as implementation type (i.e. HashMap, HashSet) instead of interface type (i.e. Map, Set), while in other places we do the opposite by declaring as interface type. A quick check indicates that most if not all of these places could be updated so we have a consistent style over the code base (prefer using interface type), which is also a good coding style to stick per best practice. Checked and fixed Set, Map and List interface usages. Author: Tamas Penzes Reviewers: Abe Fine , Michael Han Closes #354 from tamaashu/ZOOKEEPER-2630 (cherry picked from commit 1165794be9587acccc02782dbff95bc482222528) --- .../org/apache/zookeeper/util/FatJarMain.java | 6 +++-- .../org/apache/zookeeper/graph/FilterOp.java | 5 ++-- .../apache/zookeeper/graph/JsonGenerator.java | 3 ++- .../org/apache/zookeeper/graph/LogEntry.java | 3 ++- .../zookeeper/graph/MeasureThroughput.java | 3 ++- .../zookeeper/graph/servlets/Throughput.java | 3 ++- ...ooInspectorConnectionPropertiesDialog.java | 2 +- .../inspector/gui/ZooInspectorPanel.java | 2 +- .../org/apache/jute/compiler/CGenerator.java | 8 +++--- .../apache/jute/compiler/CSharpGenerator.java | 6 ++--- .../apache/jute/compiler/CppGenerator.java | 8 +++--- .../main/org/apache/jute/compiler/JFile.java | 5 ++-- .../org/apache/jute/compiler/JRecord.java | 8 +++--- .../apache/jute/compiler/JavaGenerator.java | 8 +++--- .../org/apache/zookeeper/Environment.java | 4 +-- .../org/apache/zookeeper/common/PathTrie.java | 3 ++- .../org/apache/zookeeper/server/DataTree.java | 4 +-- .../server/NettyServerCnxnFactory.java | 3 ++- .../server/PrepRequestProcessor.java | 3 ++- .../apache/zookeeper/server/WatchManager.java | 27 ++++++++++--------- .../zookeeper/server/ZooKeeperServer.java | 5 ++-- .../server/auth/ProviderRegistry.java | 3 ++- .../server/quorum/AuthFastLeaderElection.java | 3 ++- .../server/quorum/CommitProcessor.java | 3 ++- .../server/quorum/FastLeaderElection.java | 4 +-- .../zookeeper/server/quorum/Leader.java | 3 ++- .../zookeeper/test/system/BaseSysTest.java | 3 ++- .../test/system/InstanceContainer.java | 4 +-- .../test/system/InstanceManager.java | 7 ++--- .../test/system/QuorumPeerInstance.java | 3 ++- .../server/quorum/CnxManagerTest.java | 3 ++- .../quorum/FLEBackwardElectionRoundTest.java | 3 ++- .../org/apache/zookeeper/test/ACLTest.java | 2 +- .../org/apache/zookeeper/test/AsyncTest.java | 3 ++- .../org/apache/zookeeper/test/ClientBase.java | 2 +- .../org/apache/zookeeper/test/FLETest.java | 5 ++-- .../zookeeper/test/FLEZeroWeightTest.java | 3 ++- .../apache/zookeeper/test/IntegrityCheck.java | 3 ++- .../org/apache/zookeeper/test/OOMTest.java | 3 ++- .../org/apache/zookeeper/test/QuorumBase.java | 5 ++-- .../apache/zookeeper/test/SessionTest.java | 2 +- .../apache/zookeeper/test/TruncateTest.java | 3 ++- .../recipes/queue/DistributedQueue.java | 11 ++++---- 43 files changed, 116 insertions(+), 84 deletions(-) diff --git a/src/contrib/fatjar/src/java/org/apache/zookeeper/util/FatJarMain.java b/src/contrib/fatjar/src/java/org/apache/zookeeper/util/FatJarMain.java index bdf0eaec546..283675d66fe 100644 --- a/src/contrib/fatjar/src/java/org/apache/zookeeper/util/FatJarMain.java +++ b/src/contrib/fatjar/src/java/org/apache/zookeeper/util/FatJarMain.java @@ -26,6 +26,8 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * This is a generic Main class that is completely driven by the @@ -48,8 +50,8 @@ static class Cmd { String clazz; String desc; } - static HashMap cmds = new HashMap(); - static ArrayList order = new ArrayList(); + static Map cmds = new HashMap(); + static List order = new ArrayList(); /** * @param args the first parameter of args will be used as an diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterOp.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterOp.java index ee7328323eb..b29c8462bf4 100644 --- a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterOp.java +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterOp.java @@ -18,11 +18,12 @@ package org.apache.zookeeper.graph; import java.util.ArrayList; +import java.util.List; import org.apache.zookeeper.graph.filterops.*; public abstract class FilterOp { - protected ArrayList subOps; - protected ArrayList args; + protected List subOps; + protected List args; public enum ArgType { STRING, NUMBER, SYMBOL diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/JsonGenerator.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/JsonGenerator.java index afaf3a1c9de..8215833f298 100644 --- a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/JsonGenerator.java +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/JsonGenerator.java @@ -31,10 +31,11 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.ListIterator; +import java.util.Set; public class JsonGenerator { private JSONObject root; - private HashSet servers; + private Set servers; private class Message { private int from; diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogEntry.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogEntry.java index a8252ebb949..27973ba91a3 100644 --- a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogEntry.java +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogEntry.java @@ -19,9 +19,10 @@ import java.io.Serializable; import java.util.HashMap; +import java.util.Map; public abstract class LogEntry implements Serializable { - private HashMap attributes; + private Map attributes; public enum Type { UNKNOWN, LOG4J, TXN }; diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/MeasureThroughput.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/MeasureThroughput.java index 1c83da7af94..a42354cb3fb 100644 --- a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/MeasureThroughput.java +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/MeasureThroughput.java @@ -24,6 +24,7 @@ import java.io.PrintStream; import java.util.HashSet; +import java.util.Set; public class MeasureThroughput { private static final int MS_PER_SEC = 1000; @@ -45,7 +46,7 @@ public static void main(String[] args) throws IOException { long currentsec = 0; long currentmin = 0; long currenthour = 0; - HashSet zxids_ms = new HashSet(); + Set zxids_ms = new HashSet(); long zxid_sec = 0; long zxid_min = 0; long zxid_hour = 0; diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Throughput.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Throughput.java index 341bf9e6a80..80ed1dc2fd1 100644 --- a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Throughput.java +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Throughput.java @@ -25,6 +25,7 @@ import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.Set; import org.apache.zookeeper.graph.*; import org.slf4j.Logger; @@ -80,7 +81,7 @@ public String handleRequest(JsonRequest request) throws Exception { long current = 0; long currentms = 0; - HashSet zxids_ms = new HashSet(); + Set zxids_ms = new HashSet(); long zxidcount = 0; JSONArray events = new JSONArray(); diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorConnectionPropertiesDialog.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorConnectionPropertiesDialog.java index c7db5243b2c..1647021f513 100644 --- a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorConnectionPropertiesDialog.java +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorConnectionPropertiesDialog.java @@ -51,7 +51,7 @@ */ public class ZooInspectorConnectionPropertiesDialog extends JDialog { - private final HashMap components; + private final Map components; /** * @param lastConnectionProps diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java index 7a4efafa465..f0ae9f5d114 100644 --- a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java @@ -64,7 +64,7 @@ public class ZooInspectorPanel extends JPanel implements */ public ZooInspectorPanel(final ZooInspectorManager zooInspectorManager) { this.zooInspectorManager = zooInspectorManager; - final ArrayList nodeViewers = new ArrayList(); + final List nodeViewers = new ArrayList(); try { List defaultNodeViewersClassNames = this.zooInspectorManager .getDefaultNodeViewerConfiguration(); diff --git a/src/java/main/org/apache/jute/compiler/CGenerator.java b/src/java/main/org/apache/jute/compiler/CGenerator.java index 689ee2120a4..3b63de97929 100644 --- a/src/java/main/org/apache/jute/compiler/CGenerator.java +++ b/src/java/main/org/apache/jute/compiler/CGenerator.java @@ -18,19 +18,19 @@ package org.apache.jute.compiler; -import java.util.ArrayList; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Iterator; +import java.util.List; /** * C++ Code generator front-end for Hadoop record I/O. */ class CGenerator { private String mName; - private ArrayList mInclFiles; - private ArrayList mRecList; + private List mInclFiles; + private List mRecList; private final File outputDirectory; /** Creates a new instance of CppGenerator @@ -40,7 +40,7 @@ class CGenerator { * @param rlist List of records defined within this file * @param outputDirectory */ - CGenerator(String name, ArrayList ilist, ArrayList rlist, + CGenerator(String name, List ilist, List rlist, File outputDirectory) { this.outputDirectory = outputDirectory; diff --git a/src/java/main/org/apache/jute/compiler/CSharpGenerator.java b/src/java/main/org/apache/jute/compiler/CSharpGenerator.java index c28751d0012..f59cdb2a3a6 100644 --- a/src/java/main/org/apache/jute/compiler/CSharpGenerator.java +++ b/src/java/main/org/apache/jute/compiler/CSharpGenerator.java @@ -20,10 +20,10 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; +import java.util.List; public class CSharpGenerator { - private ArrayList mRecList; + private List mRecList; private final File outputDirectory; /** Creates a new instance of CSharpGenerator @@ -33,7 +33,7 @@ public class CSharpGenerator { * @param rlist List of records defined within this file * @param outputDirectory */ - CSharpGenerator(String name, ArrayList ilist, ArrayList rlist, + CSharpGenerator(String name, List ilist, List rlist, File outputDirectory) { this.outputDirectory = outputDirectory; diff --git a/src/java/main/org/apache/jute/compiler/CppGenerator.java b/src/java/main/org/apache/jute/compiler/CppGenerator.java index 98892a303c6..f3a71f7b9e4 100644 --- a/src/java/main/org/apache/jute/compiler/CppGenerator.java +++ b/src/java/main/org/apache/jute/compiler/CppGenerator.java @@ -18,19 +18,19 @@ package org.apache.jute.compiler; -import java.util.ArrayList; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Iterator; +import java.util.List; /** * C++ Code generator front-end for Hadoop record I/O. */ class CppGenerator { private String mName; - private ArrayList mInclFiles; - private ArrayList mRecList; + private List mInclFiles; + private List mRecList; private final File outputDirectory; /** Creates a new instance of CppGenerator @@ -40,7 +40,7 @@ class CppGenerator { * @param rlist List of records defined within this file * @param outputDirectory */ - CppGenerator(String name, ArrayList ilist, ArrayList rlist, + CppGenerator(String name, List ilist, List rlist, File outputDirectory) { this.outputDirectory = outputDirectory; diff --git a/src/java/main/org/apache/jute/compiler/JFile.java b/src/java/main/org/apache/jute/compiler/JFile.java index e5b0ba36161..ae59490158e 100644 --- a/src/java/main/org/apache/jute/compiler/JFile.java +++ b/src/java/main/org/apache/jute/compiler/JFile.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.List; /** * Container for the Hadoop Record DDL. @@ -31,8 +32,8 @@ public class JFile { private String mName; - private ArrayList mInclFiles; - private ArrayList mRecords; + private List mInclFiles; + private List mRecords; /** Creates a new instance of JFile * diff --git a/src/java/main/org/apache/jute/compiler/JRecord.java b/src/java/main/org/apache/jute/compiler/JRecord.java index 7322f216b96..97da179c355 100644 --- a/src/java/main/org/apache/jute/compiler/JRecord.java +++ b/src/java/main/org/apache/jute/compiler/JRecord.java @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * @@ -33,7 +35,7 @@ public class JRecord extends JCompType { private String mFQName; private String mName; private String mModule; - private ArrayList mFields; + private List mFields; /** * Creates a new instance of JRecord @@ -83,7 +85,7 @@ public String getCsharpNameSpace() { return namespace.toString(); } - public ArrayList getFields() { + public List getFields() { return mFields; } @@ -139,7 +141,7 @@ public String genCsharpWriteWrapper(String fname, String tag) { return " a_.WriteRecord("+fname+",\""+tag+"\");\n"; } - static HashMap vectorStructs = new HashMap(); + static Map vectorStructs = new HashMap(); public void genCCode(FileWriter h, FileWriter c) throws IOException { for (JField f : mFields) { if (f.getType() instanceof JVector) { diff --git a/src/java/main/org/apache/jute/compiler/JavaGenerator.java b/src/java/main/org/apache/jute/compiler/JavaGenerator.java index 4078520f71e..250ff56b903 100644 --- a/src/java/main/org/apache/jute/compiler/JavaGenerator.java +++ b/src/java/main/org/apache/jute/compiler/JavaGenerator.java @@ -20,14 +20,14 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.Iterator; +import java.util.List; /** * Java Code generator front-end for Hadoop record I/O. */ class JavaGenerator { - private ArrayList mRecList; + private List mRecList; private final File outputDirectory; /** Creates a new instance of JavaGenerator @@ -37,8 +37,8 @@ class JavaGenerator { * @param records List of records defined within this file * @param outputDirectory */ - JavaGenerator(String name, ArrayList incl, - ArrayList records, File outputDirectory) + JavaGenerator(String name, List incl, + List records, File outputDirectory) { mRecList = records; this.outputDirectory = outputDirectory; diff --git a/src/java/main/org/apache/zookeeper/Environment.java b/src/java/main/org/apache/zookeeper/Environment.java index 51797a18d77..e3bfd1db003 100644 --- a/src/java/main/org/apache/zookeeper/Environment.java +++ b/src/java/main/org/apache/zookeeper/Environment.java @@ -49,12 +49,12 @@ public String toString() { } } - private static void put(ArrayList l, String k, String v) { + private static void put(List l, String k, String v) { l.add(new Entry(k,v)); } public static List list() { - ArrayList l = new ArrayList(); + List l = new ArrayList(); put(l, "zookeeper.version", Version.getFullVersion()); try { diff --git a/src/java/main/org/apache/zookeeper/common/PathTrie.java b/src/java/main/org/apache/zookeeper/common/PathTrie.java index 73053e02cd1..5555b28c7c7 100644 --- a/src/java/main/org/apache/zookeeper/common/PathTrie.java +++ b/src/java/main/org/apache/zookeeper/common/PathTrie.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,7 +54,7 @@ public class PathTrie { static class TrieNode { boolean property = false; - final HashMap children; + final Map children; TrieNode parent = null; /** * create a trienode with parent diff --git a/src/java/main/org/apache/zookeeper/server/DataTree.java b/src/java/main/org/apache/zookeeper/server/DataTree.java index f2537f35edd..85c873d4ce9 100644 --- a/src/java/main/org/apache/zookeeper/server/DataTree.java +++ b/src/java/main/org/apache/zookeeper/server/DataTree.java @@ -883,7 +883,7 @@ void killSession(long session, long zxid) { // so there is no need for synchronization. The list is not // changed here. Only create and delete change the list which // are again called from FinalRequestProcessor in sequence. - HashSet list = ephemerals.remove(session); + Set list = ephemerals.remove(session); if (list != null) { for (String path : list) { try { @@ -1139,7 +1139,7 @@ public void dumpEphemerals(PrintWriter pwriter) { for (Map.Entry> entry : entrySet) { pwriter.print("0x" + Long.toHexString(entry.getKey())); pwriter.println(":"); - HashSet tmp = entry.getValue(); + Set tmp = entry.getValue(); if (tmp != null) { synchronized (tmp) { for (String path : tmp) { diff --git a/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java b/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java index a34a398b2d4..360b635f060 100644 --- a/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java +++ b/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java @@ -25,6 +25,7 @@ import java.net.InetSocketAddress; import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.concurrent.Executors; @@ -51,7 +52,7 @@ public class NettyServerCnxnFactory extends ServerCnxnFactory { ServerBootstrap bootstrap; Channel parentChannel; ChannelGroup allChannels = new DefaultChannelGroup("zkServerCnxns"); - HashMap> ipMap = + Map> ipMap = new HashMap>( ); InetSocketAddress localAddress; int maxClientCnxns = 60; diff --git a/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java index 825c22adafc..86d6ab88cb6 100644 --- a/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java +++ b/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.ListIterator; import java.util.Locale; +import java.util.Map; import java.util.Set; import java.util.concurrent.LinkedBlockingQueue; @@ -683,7 +684,7 @@ protected void pRequest(Request request) throws RequestProcessorException { private List removeDuplicates(List acl) { - ArrayList retval = new ArrayList(); + List retval = new ArrayList(); Iterator it = acl.iterator(); while (it.hasNext()) { ACL a = it.next(); diff --git a/src/java/main/org/apache/zookeeper/server/WatchManager.java b/src/java/main/org/apache/zookeeper/server/WatchManager.java index 76e37f2a3cd..5b1fb882fbf 100644 --- a/src/java/main/org/apache/zookeeper/server/WatchManager.java +++ b/src/java/main/org/apache/zookeeper/server/WatchManager.java @@ -21,6 +21,7 @@ import java.io.PrintWriter; import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.Map.Entry; @@ -38,11 +39,11 @@ public class WatchManager { private static final Logger LOG = LoggerFactory.getLogger(WatchManager.class); - private final HashMap> watchTable = - new HashMap>(); + private final Map> watchTable = + new HashMap>(); - private final HashMap> watch2Paths = - new HashMap>(); + private final Map> watch2Paths = + new HashMap>(); public synchronized int size(){ int result = 0; @@ -53,7 +54,7 @@ public synchronized int size(){ } public synchronized void addWatch(String path, Watcher watcher) { - HashSet list = watchTable.get(path); + Set list = watchTable.get(path); if (list == null) { // don't waste memory if there are few watches on a node // rehash when the 4th entry is added, doubling size thereafter @@ -63,7 +64,7 @@ public synchronized void addWatch(String path, Watcher watcher) { } list.add(watcher); - HashSet paths = watch2Paths.get(watcher); + Set paths = watch2Paths.get(watcher); if (paths == null) { // cnxns typically have many watches, so use default cap here paths = new HashSet(); @@ -73,12 +74,12 @@ public synchronized void addWatch(String path, Watcher watcher) { } public synchronized void removeWatcher(Watcher watcher) { - HashSet paths = watch2Paths.remove(watcher); + Set paths = watch2Paths.remove(watcher); if (paths == null) { return; } for (String p : paths) { - HashSet list = watchTable.get(p); + Set list = watchTable.get(p); if (list != null) { list.remove(watcher); if (list.size() == 0) { @@ -95,7 +96,7 @@ public Set triggerWatch(String path, EventType type) { public Set triggerWatch(String path, EventType type, Set supress) { WatchedEvent e = new WatchedEvent(type, KeeperState.SyncConnected, path); - HashSet watchers; + Set watchers; synchronized (this) { watchers = watchTable.remove(path); if (watchers == null || watchers.isEmpty()) { @@ -107,7 +108,7 @@ public Set triggerWatch(String path, EventType type, Set supre return null; } for (Watcher w : watchers) { - HashSet paths = watch2Paths.get(w); + Set paths = watch2Paths.get(w); if (paths != null) { paths.remove(path); } @@ -133,7 +134,7 @@ public synchronized String toString() { .append(watchTable.size()).append(" paths\n"); int total = 0; - for (HashSet paths : watch2Paths.values()) { + for (Set paths : watch2Paths.values()) { total += paths.size(); } sb.append("Total watches:").append(total); @@ -149,7 +150,7 @@ public synchronized String toString() { */ public synchronized void dumpWatches(PrintWriter pwriter, boolean byPath) { if (byPath) { - for (Entry> e : watchTable.entrySet()) { + for (Entry> e : watchTable.entrySet()) { pwriter.println(e.getKey()); for (Watcher w : e.getValue()) { pwriter.print("\t0x"); @@ -158,7 +159,7 @@ public synchronized void dumpWatches(PrintWriter pwriter, boolean byPath) { } } } else { - for (Entry> e : watch2Paths.entrySet()) { + for (Entry> e : watch2Paths.entrySet()) { pwriter.print("0x"); pwriter.println(Long.toHexString(((ServerCnxn)e.getKey()).getSessionId())); for (String path : e.getValue()) { diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java index 0a4b5557f1a..820363c900e 100644 --- a/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java +++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java @@ -29,6 +29,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -127,7 +128,7 @@ protected enum State { private final AtomicInteger requestsInProcess = new AtomicInteger(0); final List outstandingChanges = new ArrayList(); // this data structure must be accessed under the outstandingChanges lock - final HashMap outstandingChangesForPath = + final Map outstandingChangesForPath = new HashMap(); private ServerCnxnFactory serverCnxnFactory; @@ -284,7 +285,7 @@ public void loadData() throws IOException, InterruptedException { } // Clean up dead sessions - LinkedList deadSessions = new LinkedList(); + List deadSessions = new LinkedList(); for (Long session : zkDb.getSessions()) { if (zkDb.getSessionWithTimeOuts().get(session) == null) { deadSessions.add(session); diff --git a/src/java/main/org/apache/zookeeper/server/auth/ProviderRegistry.java b/src/java/main/org/apache/zookeeper/server/auth/ProviderRegistry.java index 855971bebc7..0b9f066aba1 100644 --- a/src/java/main/org/apache/zookeeper/server/auth/ProviderRegistry.java +++ b/src/java/main/org/apache/zookeeper/server/auth/ProviderRegistry.java @@ -20,6 +20,7 @@ import java.util.Enumeration; import java.util.HashMap; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,7 +31,7 @@ public class ProviderRegistry { private static final Logger LOG = LoggerFactory.getLogger(ProviderRegistry.class); private static boolean initialized = false; - private static HashMap authenticationProviders = + private static Map authenticationProviders = new HashMap(); public static void initialize() { diff --git a/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java b/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java index d32a725abf4..12c68797213 100644 --- a/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java +++ b/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java @@ -28,6 +28,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.LinkedBlockingQueue; @@ -798,7 +799,7 @@ private boolean totalOrderPredicate(long id, long zxid) { } - private boolean termPredicate(HashMap votes, + private boolean termPredicate(Map votes, long l, long zxid) { diff --git a/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java b/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java index 220d6588cd1..916d97d9094 100644 --- a/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java +++ b/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.LinkedList; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +50,7 @@ public class CommitProcessor extends ZooKeeperCriticalThread implements RequestP LinkedList committedRequests = new LinkedList(); RequestProcessor nextProcessor; - ArrayList toProcess = new ArrayList(); + List toProcess = new ArrayList(); /** * This flag indicates whether we need to wait for a response to come back from the diff --git a/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java b/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java index 67e926730dd..3efdc4fadeb 100644 --- a/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java +++ b/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java @@ -639,7 +639,7 @@ protected boolean totalOrderPredicate(long newId, long newZxid, long newEpoch, l * @param zxid zxid of the the vote received last */ protected boolean termPredicate( - HashMap votes, + Map votes, Vote vote) { HashSet set = new HashSet(); @@ -669,7 +669,7 @@ protected boolean termPredicate( * @param electionEpoch epoch id */ protected boolean checkLeader( - HashMap votes, + Map votes, long leader, long electionEpoch){ diff --git a/src/java/main/org/apache/zookeeper/server/quorum/Leader.java b/src/java/main/org/apache/zookeeper/server/quorum/Leader.java index a9fd8d099a4..76915ee488a 100644 --- a/src/java/main/org/apache/zookeeper/server/quorum/Leader.java +++ b/src/java/main/org/apache/zookeeper/server/quorum/Leader.java @@ -32,6 +32,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; @@ -136,7 +137,7 @@ private void addObserverLearnerHandler(LearnerHandler lh) { } // Pending sync requests. Must access under 'this' lock. - private final HashMap> pendingSyncs = + private final Map> pendingSyncs = new HashMap>(); synchronized public int getNumPendingSyncs() { diff --git a/src/java/systest/org/apache/zookeeper/test/system/BaseSysTest.java b/src/java/systest/org/apache/zookeeper/test/system/BaseSysTest.java index 421f699a77f..8ff7dcb445e 100644 --- a/src/java/systest/org/apache/zookeeper/test/system/BaseSysTest.java +++ b/src/java/systest/org/apache/zookeeper/test/system/BaseSysTest.java @@ -25,6 +25,7 @@ import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.util.HashMap; +import java.util.Map; import junit.framework.TestCase; @@ -144,7 +145,7 @@ private void distributedConfigureServers(int count) throws IOException { private QuorumPeer qps[]; private File qpsDirs[]; - HashMap peers; + Map peers; private void fakeConfigureServers(int count) throws IOException { peers = new HashMap(); qps = new QuorumPeer[count]; diff --git a/src/java/systest/org/apache/zookeeper/test/system/InstanceContainer.java b/src/java/systest/org/apache/zookeeper/test/system/InstanceContainer.java index 244e4d85778..5a954e2c3dc 100644 --- a/src/java/systest/org/apache/zookeeper/test/system/InstanceContainer.java +++ b/src/java/systest/org/apache/zookeeper/test/system/InstanceContainer.java @@ -225,7 +225,7 @@ public void process(WatchedEvent event) { } } - HashMap instances = new HashMap(); + Map instances = new HashMap(); public void processResult(int rc, String path, Object ctx, List children) { if (rc != KeeperException.Code.OK.intValue()) { @@ -233,7 +233,7 @@ public void processResult(int rc, String path, Object ctx, zk.getChildren(assignmentsNode, true, this, null); return; } - HashMap newList = new HashMap(); + Map newList = new HashMap(); // check for differences Stat stat = new Stat(); for(String child: children) { diff --git a/src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java b/src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java index 93c51b8b7e4..9f44902f98e 100644 --- a/src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java +++ b/src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import org.slf4j.Logger; @@ -80,8 +81,8 @@ private static final class Assigned { System.err.println("Preferred List is empty"); } } - private HashMap> assignments = new HashMap>(); - private HashMap instanceToAssignment = new HashMap(); + private Map> assignments = new HashMap>(); + private Map instanceToAssignment = new HashMap(); public InstanceManager(ZooKeeper zk, String prefix) throws KeeperException, InterruptedException { this.zk = zk; this.prefixNode = prefix; @@ -138,7 +139,7 @@ synchronized public void processResult(int rc, String path, Object ctx, if (LOG.isDebugEnabled()) { LOG.debug("Got " + children + " children from " + path); } - HashMap> newAssignments = new HashMap>(); + Map> newAssignments = new HashMap>(); for(String c: children) { HashSet a = assignments.remove(c); if (a != null) { diff --git a/src/java/systest/org/apache/zookeeper/test/system/QuorumPeerInstance.java b/src/java/systest/org/apache/zookeeper/test/system/QuorumPeerInstance.java index 95aebc8e644..3888a8a269d 100644 --- a/src/java/systest/org/apache/zookeeper/test/system/QuorumPeerInstance.java +++ b/src/java/systest/org/apache/zookeeper/test/system/QuorumPeerInstance.java @@ -26,6 +26,7 @@ import java.net.ServerSocket; import java.net.Socket; import java.util.HashMap; +import java.util.Map; import java.util.Properties; import org.slf4j.Logger; @@ -53,7 +54,7 @@ public void setReporter(Reporter r) { InetSocketAddress clientAddr; InetSocketAddress quorumAddr; - HashMap peers; + Map peers; File snapDir, logDir; public QuorumPeerInstance() { diff --git a/src/java/test/org/apache/zookeeper/server/quorum/CnxManagerTest.java b/src/java/test/org/apache/zookeeper/server/quorum/CnxManagerTest.java index a82a728e26e..dd08c8239b7 100644 --- a/src/java/test/org/apache/zookeeper/server/quorum/CnxManagerTest.java +++ b/src/java/test/org/apache/zookeeper/server/quorum/CnxManagerTest.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashMap; +import java.util.Map; import java.util.Random; import java.util.concurrent.TimeUnit; import java.net.Socket; @@ -49,7 +50,7 @@ public class CnxManagerTest extends ZKTestCase { protected static final int THRESHOLD = 4; int count; - HashMap peers; + Map peers; File peerTmpdir[]; int peerQuorumPort[]; int peerClientPort[]; diff --git a/src/java/test/org/apache/zookeeper/server/quorum/FLEBackwardElectionRoundTest.java b/src/java/test/org/apache/zookeeper/server/quorum/FLEBackwardElectionRoundTest.java index c0ab3eaaf6d..ceadb228341 100644 --- a/src/java/test/org/apache/zookeeper/server/quorum/FLEBackwardElectionRoundTest.java +++ b/src/java/test/org/apache/zookeeper/server/quorum/FLEBackwardElectionRoundTest.java @@ -22,6 +22,7 @@ import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.util.HashMap; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,7 +44,7 @@ public class FLEBackwardElectionRoundTest extends ZKTestCase { protected static final Logger LOG = LoggerFactory.getLogger(FLELostMessageTest.class); int count; - HashMap peers; + Map peers; File tmpdir[]; int port[]; diff --git a/src/java/test/org/apache/zookeeper/test/ACLTest.java b/src/java/test/org/apache/zookeeper/test/ACLTest.java index 793265c510d..a916530307f 100644 --- a/src/java/test/org/apache/zookeeper/test/ACLTest.java +++ b/src/java/test/org/apache/zookeeper/test/ACLTest.java @@ -114,7 +114,7 @@ public void testAcls() throws Exception { id.setId("1.1.1."+j); id.setScheme("ip"); acl.setId(id); - ArrayList list = new ArrayList(); + List list = new ArrayList(); list.add(acl); zk.create(path, path.getBytes(), list, CreateMode.PERSISTENT); } diff --git a/src/java/test/org/apache/zookeeper/test/AsyncTest.java b/src/java/test/org/apache/zookeeper/test/AsyncTest.java index 2182032966b..dba7776829d 100644 --- a/src/java/test/org/apache/zookeeper/test/AsyncTest.java +++ b/src/java/test/org/apache/zookeeper/test/AsyncTest.java @@ -24,6 +24,7 @@ import java.util.LinkedList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -95,7 +96,7 @@ private ZooKeeper createClient(String hp) return zk; } - LinkedList results = new LinkedList(); + List results = new LinkedList(); @Test public void testAsync() throws IOException, InterruptedException, KeeperException diff --git a/src/java/test/org/apache/zookeeper/test/ClientBase.java b/src/java/test/org/apache/zookeeper/test/ClientBase.java index 7595a029bb9..9250afd940f 100644 --- a/src/java/test/org/apache/zookeeper/test/ClientBase.java +++ b/src/java/test/org/apache/zookeeper/test/ClientBase.java @@ -213,7 +213,7 @@ protected TestableZooKeeper createClient(CountdownWatcher watcher) return createClient(watcher, hostPort); } - private LinkedList allClients; + private List allClients; private boolean allClientsSetup = false; protected TestableZooKeeper createClient(CountdownWatcher watcher, String hp) diff --git a/src/java/test/org/apache/zookeeper/test/FLETest.java b/src/java/test/org/apache/zookeeper/test/FLETest.java index 6281a57d9e4..4170da0039d 100644 --- a/src/java/test/org/apache/zookeeper/test/FLETest.java +++ b/src/java/test/org/apache/zookeeper/test/FLETest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Random; import java.util.Set; @@ -62,9 +63,9 @@ int countVotes(HashSet hs, long id) { } int count; - HashMap peers; + Map peers; ArrayList threads; - HashMap > voteMap; + Map > voteMap; File tmpdir[]; int port[]; int successCount; diff --git a/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java b/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java index e8a8cf79272..357fe185db2 100644 --- a/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java +++ b/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java @@ -22,6 +22,7 @@ import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.HashMap; +import java.util.Map; import java.util.Properties; import java.util.Random; @@ -46,7 +47,7 @@ public class FLEZeroWeightTest extends ZKTestCase { Properties qp; int count; - HashMap peers; + Map peers; ArrayList threads; File tmpdir[]; int port[]; diff --git a/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java b/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java index 9a01a6587f7..27816300fd7 100644 --- a/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java +++ b/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.util.Date; import java.util.HashMap; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,7 +54,7 @@ public class IntegrityCheck implements Watcher, StatCallback, DataCallback { ZooKeeper zk; - HashMap lastValue = new HashMap(); + Map lastValue = new HashMap(); int count; diff --git a/src/java/test/org/apache/zookeeper/test/OOMTest.java b/src/java/test/org/apache/zookeeper/test/OOMTest.java index 465df98380b..e8e76839be0 100644 --- a/src/java/test/org/apache/zookeeper/test/OOMTest.java +++ b/src/java/test/org/apache/zookeeper/test/OOMTest.java @@ -23,6 +23,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.List; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; @@ -47,7 +48,7 @@ public void testOOM() throws IOException, InterruptedException, KeeperException File tmpDir = ClientBase.createTmpDir(); // Grab some memory so that it is easier to cause an // OOM condition; - ArrayList hog = new ArrayList(); + List hog = new ArrayList(); while (true) { try { hog.add(new byte[1024 * 1024 * 2]); diff --git a/src/java/test/org/apache/zookeeper/test/QuorumBase.java b/src/java/test/org/apache/zookeeper/test/QuorumBase.java index 49cff350f3c..40536d5e546 100644 --- a/src/java/test/org/apache/zookeeper/test/QuorumBase.java +++ b/src/java/test/org/apache/zookeeper/test/QuorumBase.java @@ -23,6 +23,7 @@ import java.net.InetSocketAddress; import java.util.HashMap; import java.util.LinkedHashSet; +import java.util.Map; import java.util.Set; import org.slf4j.Logger; @@ -117,7 +118,7 @@ void startServers(boolean withObservers) throws Exception { int tickTime = 2000; int initLimit = 3; int syncLimit = 3; - HashMap peers = new HashMap(); + Map peers = new HashMap(); peers.put(Long.valueOf(1), new QuorumServer(1, "127.0.0.1", port1 + 1000, portLE1 + 1000, LearnerType.PARTICIPANT)); @@ -218,7 +219,7 @@ public void setupServers() throws IOException { setupServer(5); } - HashMap peers = null; + Map peers = null; public void setupServer(int i) throws IOException { int tickTime = 2000; int initLimit = 3; diff --git a/src/java/test/org/apache/zookeeper/test/SessionTest.java b/src/java/test/org/apache/zookeeper/test/SessionTest.java index 0740ebbd1e9..75d695c6122 100644 --- a/src/java/test/org/apache/zookeeper/test/SessionTest.java +++ b/src/java/test/org/apache/zookeeper/test/SessionTest.java @@ -414,7 +414,7 @@ public void testSessionTimeoutAccess() throws Exception { } private class DupWatcher extends CountdownWatcher { - public LinkedList states = new LinkedList(); + public List states = new LinkedList(); public void process(WatchedEvent event) { super.process(event); if (event.getType() == EventType.None) { diff --git a/src/java/test/org/apache/zookeeper/test/TruncateTest.java b/src/java/test/org/apache/zookeeper/test/TruncateTest.java index 66ff63d0ffa..6ae6e42ebc6 100644 --- a/src/java/test/org/apache/zookeeper/test/TruncateTest.java +++ b/src/java/test/org/apache/zookeeper/test/TruncateTest.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.util.HashMap; +import java.util.Map; import junit.framework.Assert; @@ -200,7 +201,7 @@ public void testTruncate() throws IOException, InterruptedException, KeeperExcep int port3 = baseHostPort+3; // Start up two of the quorum and add 10 txns - HashMap peers = new HashMap(); + Map peers = new HashMap(); peers.put(Long.valueOf(1), new QuorumServer(1, "127.0.0.1", port1 + 1000, 0, null)); peers.put(Long.valueOf(2), new QuorumServer(2, "127.0.0.1", port2 + 1000, 0, null)); peers.put(Long.valueOf(3), new QuorumServer(3, "127.0.0.1", port3 + 1000, 0, null)); diff --git a/src/recipes/queue/src/java/org/apache/zookeeper/recipes/queue/DistributedQueue.java b/src/recipes/queue/src/java/org/apache/zookeeper/recipes/queue/DistributedQueue.java index c5d7c83eca1..c35c332e251 100644 --- a/src/recipes/queue/src/java/org/apache/zookeeper/recipes/queue/DistributedQueue.java +++ b/src/recipes/queue/src/java/org/apache/zookeeper/recipes/queue/DistributedQueue.java @@ -19,6 +19,7 @@ package org.apache.zookeeper.recipes.queue; import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; import java.util.TreeMap; import java.util.concurrent.CountDownLatch; @@ -68,8 +69,8 @@ public DistributedQueue(ZooKeeper zookeeper, String dir, List acl){ * @param watcher optional watcher on getChildren() operation. * @return map from id to child name for all children */ - private TreeMap orderedChildren(Watcher watcher) throws KeeperException, InterruptedException { - TreeMap orderedChildren = new TreeMap(); + private Map orderedChildren(Watcher watcher) throws KeeperException, InterruptedException { + Map orderedChildren = new TreeMap(); List childNames = null; try{ @@ -147,7 +148,7 @@ private String smallestChildName() throws KeeperException, InterruptedException * @throws InterruptedException */ public byte[] element() throws NoSuchElementException, KeeperException, InterruptedException { - TreeMap orderedChildren; + Map orderedChildren; // element, take, and remove follow the same pattern. // We want to return the child node with the smallest sequence number. @@ -184,7 +185,7 @@ public byte[] element() throws NoSuchElementException, KeeperException, Interrup * @throws InterruptedException */ public byte[] remove() throws NoSuchElementException, KeeperException, InterruptedException { - TreeMap orderedChildren; + Map orderedChildren; // Same as for element. Should refactor this. while(true){ try{ @@ -234,7 +235,7 @@ public void await() throws InterruptedException { * @throws InterruptedException */ public byte[] take() throws KeeperException, InterruptedException { - TreeMap orderedChildren; + Map orderedChildren; // Same as for element. Should refactor this. while(true){ LatchChildWatcher childWatcher = new LatchChildWatcher(); From a4bbcf2ecc9069ed00016d25c6e40bfb0b13bf0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20P=C3=A9nzes?= Date: Mon, 9 Oct 2017 16:55:24 -0700 Subject: [PATCH 2/2] fix ACLTest.java missing import --- src/java/test/org/apache/zookeeper/test/ACLTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/java/test/org/apache/zookeeper/test/ACLTest.java b/src/java/test/org/apache/zookeeper/test/ACLTest.java index a916530307f..5a0994e67a2 100644 --- a/src/java/test/org/apache/zookeeper/test/ACLTest.java +++ b/src/java/test/org/apache/zookeeper/test/ACLTest.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory;