Ver código fonte

changes to the api to take List as param rahter than arraylist

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@670961 13f79535-47bb-0310-9956-ffa450edef68
17 anos atrás
pai
commit
e2f182cf0c

+ 3 - 2
zookeeper/java/src/com/yahoo/jute/BinaryOutputArchive.java

@@ -20,6 +20,7 @@ package com.yahoo.jute;
 
 import java.io.IOException;
 import java.io.ByteArrayOutputStream;
+import java.util.List;
 import java.util.TreeMap;
 import java.util.ArrayList;
 import java.io.DataOutput;
@@ -129,7 +130,7 @@ public class BinaryOutputArchive implements OutputArchive {
     
     public void endRecord(Record r, String tag) throws IOException {}
     
-    public void startVector(ArrayList v, String tag) throws IOException {
+    public void startVector(List v, String tag) throws IOException {
     	if (v == null) {
     		writeInt(-1, tag);
     		return;
@@ -137,7 +138,7 @@ public class BinaryOutputArchive implements OutputArchive {
         writeInt(v.size(), tag);
     }
     
-    public void endVector(ArrayList v, String tag) throws IOException {}
+    public void endVector(List v, String tag) throws IOException {}
     
     public void startMap(TreeMap v, String tag) throws IOException {
         writeInt(v.size(), tag);

+ 3 - 4
zookeeper/java/src/com/yahoo/jute/CsvOutputArchive.java

@@ -19,9 +19,8 @@
 package com.yahoo.jute;
 
 import java.io.IOException;
-import java.io.ByteArrayOutputStream;
+import java.util.List;
 import java.util.TreeMap;
-import java.util.ArrayList;
 import java.io.PrintStream;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
@@ -125,13 +124,13 @@ public class CsvOutputArchive implements OutputArchive {
         }
     }
     
-    public void startVector(ArrayList v, String tag) throws IOException {
+    public void startVector(List v, String tag) throws IOException {
         printCommaUnlessFirst();
         stream.print("v{");
         isFirst = true;
     }
     
-    public void endVector(ArrayList v, String tag) throws IOException {
+    public void endVector(List v, String tag) throws IOException {
         stream.print("}");
         isFirst = false;
     }

+ 3 - 4
zookeeper/java/src/com/yahoo/jute/OutputArchive.java

@@ -19,9 +19,8 @@
 package com.yahoo.jute;
 
 import java.io.IOException;
-import java.io.ByteArrayOutputStream;
+import java.util.List;
 import java.util.TreeMap;
-import java.util.ArrayList;
 
 /**
  * Interface that alll the serializers have to implement.
@@ -41,8 +40,8 @@ public interface OutputArchive {
     public void writeRecord(Record r, String tag) throws IOException;
     public void startRecord(Record r, String tag) throws IOException;
     public void endRecord(Record r, String tag) throws IOException;
-    public void startVector(ArrayList v, String tag) throws IOException;
-    public void endVector(ArrayList v, String tag) throws IOException;
+    public void startVector(List v, String tag) throws IOException;
+    public void endVector(List v, String tag) throws IOException;
     public void startMap(TreeMap v, String tag) throws IOException;
     public void endMap(TreeMap v, String tag) throws IOException;
 

+ 3 - 4
zookeeper/java/src/com/yahoo/jute/XmlOutputArchive.java

@@ -19,9 +19,8 @@
 package com.yahoo.jute;
 
 import java.io.IOException;
-import java.io.ByteArrayOutputStream;
+import java.util.List;
 import java.util.TreeMap;
-import java.util.ArrayList;
 import java.io.PrintStream;
 import java.io.OutputStream;
 import java.util.Stack;
@@ -224,13 +223,13 @@ class XmlOutputArchive implements OutputArchive {
         outsideRecord(tag);
     }
     
-    public void startVector(ArrayList v, String tag) throws IOException {
+    public void startVector(List v, String tag) throws IOException {
         insideVector(tag);
         stream.print("<array>\n");
         addIndent();
     }
     
-    public void endVector(ArrayList v, String tag) throws IOException {
+    public void endVector(List v, String tag) throws IOException {
         closeIndent();
         putIndent();
         stream.print("</array>");

+ 3 - 3
zookeeper/java/src/com/yahoo/jute/compiler/JVector.java

@@ -38,7 +38,7 @@ public class JVector extends JCompType {
     
     /** Creates a new instance of JVector */
     public JVector(JType t) {
-        super("struct " + extractVectorName(t), " ::std::vector<"+t.getCppType()+">", "java.util.ArrayList", "Vector", "java.util.ArrayList");
+        super("struct " + extractVectorName(t), " ::std::vector<"+t.getCppType()+">", "java.util.List<" + t.getJavaType() + ">", "Vector", "java.util.ArrayList<" + t.getJavaType() + ">");
         mElement = t;
     }
     
@@ -53,13 +53,13 @@ public class JVector extends JCompType {
     public String genJavaReadWrapper(String fname, String tag, boolean decl) {
         StringBuffer ret = new StringBuffer("");
         if (decl) {
-            ret.append("      java.util.ArrayList "+fname+";\n");
+            ret.append("      java.util.List "+fname+";\n");
         }
         ret.append("    {\n");
         incrLevel();
         ret.append("      Index "+getId("vidx")+" = a_.startVector(\""+tag+"\");\n");
         ret.append("      if ("+getId("vidx")+"!= null) {");
-        ret.append("          "+fname+"=new java.util.ArrayList();\n");
+        ret.append("          "+fname+"=new java.util.ArrayList<"+ mElement.getJavaType() + ">();\n");
         ret.append("          for (; !"+getId("vidx")+".done(); "+getId("vidx")+".incr()) {\n");
         ret.append(mElement.genJavaReadWrapper(getId("e"), getId("e"), true));
         ret.append("            "+fname+".add("+getId("e")+");\n");

+ 3 - 3
zookeeper/java/src/com/yahoo/zookeeper/AsyncCallback.java

@@ -15,7 +15,7 @@
  */
 package com.yahoo.zookeeper;
 
-import java.util.ArrayList;
+import java.util.List;
 
 import com.yahoo.zookeeper.data.ACL;
 import com.yahoo.zookeeper.data.Stat;
@@ -32,12 +32,12 @@ public interface AsyncCallback {
 
     interface ACLCallback extends AsyncCallback {
         public void processResult(int rc, String path, Object ctx,
-                ArrayList<ACL> acl, Stat stat);
+                List<ACL> acl, Stat stat);
     }
 
     interface ChildrenCallback extends AsyncCallback {
         public void processResult(int rc, String path, Object ctx,
-                ArrayList<String> children);
+                List<String> children);
     }
 
     interface StringCallback extends AsyncCallback {

+ 13 - 12
zookeeper/java/src/com/yahoo/zookeeper/ZooKeeper.java

@@ -20,6 +20,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
+import java.util.List;
 import java.util.Date;
 
 import org.apache.log4j.Logger;
@@ -226,7 +227,7 @@ public class ZooKeeper {
      * @throws com.yahoo.zookeeper.KeeperException.InvalidACLException if the ACL is invalid
      * @throws InterruptedException if the transaction is interrrupted
      */
-    public String create(String path, byte data[], ArrayList<ACL> acl, int flags)
+    public String create(String path, byte data[], List<ACL> acl, int flags)
             throws KeeperException, InterruptedException {
         RequestHeader h = new RequestHeader();
         h.setType(ZooDefs.OpCode.create);
@@ -250,10 +251,10 @@ public class ZooKeeper {
      * The Asynchronous version of create. The request doesn't actually until
      * the asynchronous callback is called.
      *
-     * @see #create(String, byte[], ArrayList, int)
+     * @see #create(String, byte[], List, int)
      */
 
-    public void create(String path, byte data[], ArrayList<ACL> acl, int flags,
+    public void create(String path, byte data[], List<ACL> acl, int flags,
             StringCallback cb, Object ctx) {
         RequestHeader h = new RequestHeader();
         h.setType(ZooDefs.OpCode.create);
@@ -507,7 +508,7 @@ public class ZooKeeper {
      * @throws InterruptedException If the server transaction is interrupted.
      * @throws KeeperException If the server signals an error with a non-zero error code.
      */
-    public ArrayList<ACL> getACL(String path, Stat stat)
+    public List<ACL> getACL(String path, Stat stat)
             throws KeeperException, InterruptedException {
         RequestHeader h = new RequestHeader();
         h.setType(ZooDefs.OpCode.getACL);
@@ -558,7 +559,7 @@ public class ZooKeeper {
      * @throws KeeperException If the server signals an error with a non-zero error code.
      * @throws com.yahoo.zookeeper.KeeperException.InvalidACLException If the acl is invalide.
      */
-    public Stat setACL(String path, ArrayList<ACL> acl, int version)
+    public Stat setACL(String path, List<ACL> acl, int version)
             throws KeeperException, InterruptedException {
         RequestHeader h = new RequestHeader();
         h.setType(ZooDefs.OpCode.setACL);
@@ -581,9 +582,9 @@ public class ZooKeeper {
      * The Asynchronous version of setACL. The request doesn't actually until
      * the asynchronous callback is called.
      *
-     * @see #setACL(String, ArrayList, int)
+     * @see #setACL(String, List, int)
      */
-    public void setACL(String path, ArrayList<ACL> acl, int version,
+    public void setACL(String path, List<ACL> acl, int version,
             StatCallback cb, Object ctx) {
         RequestHeader h = new RequestHeader();
         h.setType(ZooDefs.OpCode.setACL);
@@ -614,7 +615,7 @@ public class ZooKeeper {
      * @throws InterruptedException If the server transaction is interrupted.
      * @throws KeeperException If the server signals an error with a non-zero error code.
      */
-    public ArrayList<String> getChildren(String path, boolean watch)
+    public List<String> getChildren(String path, boolean watch)
             throws KeeperException, InterruptedException {
         RequestHeader h = new RequestHeader();
         h.setType(ZooDefs.OpCode.getChildren);
@@ -769,7 +770,7 @@ public class ZooKeeper {
         String cmd = args[1];
         boolean watch = args.length > 3;
         String path = args[2];
-        ArrayList<ACL> acl = Ids.OPEN_ACL_UNSAFE;
+        List<ACL> acl = Ids.OPEN_ACL_UNSAFE;
         System.out.println("Processing " + cmd);
         if (cmd.equals("create") && args.length >= 4) {
             if (args.length == 5) {
@@ -790,7 +791,7 @@ public class ZooKeeper {
             System.out.println(new String(data));
             printStat(stat);
         } else if (cmd.equals("ls") && args.length >= 3) {
-            ArrayList<String> children = zooKeeper.getChildren(path, watch);
+            List<String> children = zooKeeper.getChildren(path, watch);
             System.out.println(children);
         } else if (cmd.equals("getAcl") && args.length >= 2) {
             acl = zooKeeper.getACL(path, stat);
@@ -832,8 +833,8 @@ public class ZooKeeper {
         return p.toString();
     }
 
-    private static ArrayList<ACL> parseACLs(String aclString) {
-        ArrayList<ACL> acl;
+    private static List<ACL> parseACLs(String aclString) {
+        List<ACL> acl;
         String acls[] = aclString.split(",");
         acl = new ArrayList<ACL>();
         for (String a : acls) {

+ 4 - 2
zookeeper/java/src/com/yahoo/zookeeper/server/DataNode.java

@@ -19,6 +19,8 @@ package com.yahoo.zookeeper.server;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
+
 import com.yahoo.jute.Index;
 import com.yahoo.jute.InputArchive;
 import com.yahoo.jute.OutputArchive;
@@ -37,7 +39,7 @@ public class DataNode implements Record {
     DataNode() {
     }
 
-    DataNode(DataNode parent, byte data[], ArrayList<ACL> acl, Stat stat) {
+    DataNode(DataNode parent, byte data[], List<ACL> acl, Stat stat) {
         this.parent = parent;
         this.data = data;
         this.acl = acl;
@@ -49,7 +51,7 @@ public class DataNode implements Record {
 
     byte data[];
 
-    ArrayList<ACL> acl;
+    List<ACL> acl;
 
     public Stat stat;
 

+ 5 - 4
zookeeper/java/src/com/yahoo/zookeeper/server/DataTree.java

@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -147,7 +148,7 @@ public class DataTree {
      * @return
      * @throws KeeperException
      */
-    public String createNode(String path, byte data[], ArrayList<ACL> acl,
+    public String createNode(String path, byte data[], List<ACL> acl,
             long ephemeralOwner, long zxid, long time) throws KeeperException.NoNodeException, KeeperException.NodeExistsException {
         int lastSlash = path.lastIndexOf('/');
         String parentName = path.substring(0, lastSlash);
@@ -286,7 +287,7 @@ public class DataTree {
         }
     }
 
-    public Stat setACL(String path, ArrayList<ACL> acl, int version) throws KeeperException.NoNodeException {
+    public Stat setACL(String path, List<ACL> acl, int version) throws KeeperException.NoNodeException {
         Stat stat = new Stat();
         DataNode n = nodes.get(path);
         if (n == null) {
@@ -301,14 +302,14 @@ public class DataTree {
     }
 
     @SuppressWarnings("unchecked")
-    public ArrayList<ACL> getACL(String path, Stat stat) throws KeeperException.NoNodeException {
+    public List<ACL> getACL(String path, Stat stat) throws KeeperException.NoNodeException {
         DataNode n = nodes.get(path);
         if (n == null) {
             throw new KeeperException.NoNodeException();
         }
         synchronized (n) {
             copyStat(n.stat, stat);
-            return (ArrayList<ACL>) n.acl.clone();
+            return new ArrayList<ACL>(n.acl);
         }
     }
 

+ 3 - 2
zookeeper/java/src/com/yahoo/zookeeper/server/FinalRequestProcessor.java

@@ -19,6 +19,7 @@ package com.yahoo.zookeeper.server;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.log4j.Logger;
 
@@ -193,8 +194,8 @@ public class FinalRequestProcessor implements RequestProcessor {
                 ZooKeeperServer.byteBuffer2Record(request.request,
                         getACLRequest);
                 stat = new Stat();
-                ArrayList<ACL> acl = zks.dataTree.getACL(getACLRequest
-                        .getPath(), stat);
+                List<ACL> acl = 
+                    zks.dataTree.getACL(getACLRequest.getPath(), stat);
                 rsp = new GetACLResponse(acl, stat);
                 break;
             case OpCode.getChildren:

+ 4 - 3
zookeeper/java/src/com/yahoo/zookeeper/server/PrepRequestProcessor.java

@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.List;
 import java.util.concurrent.LinkedBlockingQueue;
 
 import org.apache.log4j.Logger;
@@ -129,8 +130,8 @@ public class PrepRequestProcessor extends Thread implements RequestProcessor {
         }
     }
 
-    static void checkACL(ZooKeeperServer zks, ArrayList<ACL> acl, int perm,
-            ArrayList<Id> ids) throws KeeperException.NoAuthException {
+    static void checkACL(ZooKeeperServer zks, List<ACL> acl, int perm,
+            List<Id> ids) throws KeeperException.NoAuthException {
         if (skipACL) {
             return;
         }
@@ -384,7 +385,7 @@ public class PrepRequestProcessor extends Thread implements RequestProcessor {
      * @param acl list of ACLs being assigned to the node (create or setACL operation)
      * @return
      */
-    private boolean fixupACL(ArrayList<Id> authInfo, ArrayList<ACL> acl) {
+    private boolean fixupACL(List<Id> authInfo, List<ACL> acl) {
         if (skipACL) {
             return true;
         }

+ 3 - 2
zookeeper/java/src/com/yahoo/zookeeper/server/Request.java

@@ -18,6 +18,7 @@ package com.yahoo.zookeeper.server;
 
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.List;
 
 import com.yahoo.jute.Record;
 import com.yahoo.zookeeper.ZooDefs.OpCode;
@@ -41,7 +42,7 @@ public class Request {
      * @param bb
      */
     public Request(ServerCnxn cnxn, long sessionId, int xid, int type,
-            ByteBuffer bb, ArrayList<Id> authInfo) {
+            ByteBuffer bb, List<Id> authInfo) {
         this.cnxn = cnxn;
         this.sessionId = sessionId;
         this.cxid = xid;
@@ -66,7 +67,7 @@ public class Request {
 
     public long zxid = -1;
 
-    public ArrayList<Id> authInfo;
+    public List<Id> authInfo;
 
     public long createTime = System.currentTimeMillis();
 

+ 5 - 6
zookeeper/java/src/com/yahoo/zookeeper/server/ZooKeeperServer.java

@@ -126,7 +126,7 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
      */
     final private long superSecret = 0XB3415C00L;
     int requestsInProcess;
-    ArrayList<ChangeRecord> outstandingChanges = new ArrayList<ChangeRecord>();
+    List<ChangeRecord> outstandingChanges = new ArrayList<ChangeRecord>();
     private NIOServerCnxn.Factory serverCnxnFactory;
 
     /*
@@ -759,7 +759,7 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
      */
     static class ChangeRecord {
         ChangeRecord(long zxid, String path, Stat stat, int childCount,
-                ArrayList<ACL> acl) {
+                List<ACL> acl) {
             this.zxid = zxid;
             this.path = path;
             this.stat = stat;
@@ -775,7 +775,7 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
 
         int childCount;
 
-        ArrayList<ACL> acl; /* Make sure to create a new object when changing */
+        List<ACL> acl; /* Make sure to create a new object when changing */
 
         @SuppressWarnings("unchecked")
         ChangeRecord duplicate(long zxid) {
@@ -784,8 +784,7 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
                 DataTree.copyStat(this.stat, stat);
             }
             return new ChangeRecord(zxid, path, stat, childCount,
-                    acl == null ? new ArrayList<ACL>() : (ArrayList<ACL>) acl
-                            .clone());
+                    acl == null ? new ArrayList<ACL>() : new ArrayList(acl));
         }
     }
 
@@ -847,7 +846,7 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
      * @param bb
      */
     public void submitRequest(ServerCnxn cnxn, long sessionId, int type,
-            int xid, ByteBuffer bb, ArrayList<Id> authInfo) {
+            int xid, ByteBuffer bb, List<Id> authInfo) {
         if (firstProcessor == null) {
             synchronized (this) {
                 try {

+ 6 - 5
zookeeper/test/com/yahoo/zookeeper/test/ClientTest.java

@@ -5,6 +5,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
+import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
@@ -150,7 +151,7 @@ public class ClientTest extends TestCase implements Watcher {
             System.out.println("Before create /ben");
             zk.create("/ben", "Ben was here".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
             System.out.println("Before getChildren /");
-            ArrayList<String> children = zk.getChildren("/", false);
+            List<String> children = zk.getChildren("/", false);
             assertEquals(1, children.size());
             assertEquals("ben", children.get(0));
             String value = new String(zk.getData("/ben", false, stat));
@@ -316,13 +317,13 @@ public class ClientTest extends TestCase implements Watcher {
             LOG.error("******************* Connected to ZooKeeper" + new Date());
             for (int i = 0; i < threadCount; i++) {
                 System.err.println("Doing thread: " + i + " " + new Date());
-                ArrayList<String> children = zk
-                        .getChildren("/test-" + i, false);
+                List<String> children = 
+                    zk.getChildren("/test-" + i, false);
                 assertEquals(childCount, children.size());
             }
             for (int i = 0; i < threadCount; i++) {
-                ArrayList<String> children = zk
-                        .getChildren("/test-" + i, false);
+                List<String> children = 
+                    zk.getChildren("/test-" + i, false);
                 assertEquals(childCount, children.size());
             }
         } finally {

+ 3 - 2
zookeeper/test/com/yahoo/zookeeper/test/SledgeHammer.java

@@ -3,6 +3,7 @@ package com.yahoo.zookeeper.test;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
 
 import com.yahoo.zookeeper.KeeperException;
 import com.yahoo.zookeeper.Watcher;
@@ -43,8 +44,8 @@ public class SledgeHammer extends Thread implements Watcher {
             for (int i = 0; i < count; i++) {
                 try {
                     System.out.print(i + "\r");
-                    ArrayList<String> childs = zk
-                            .getChildren("/hammers", false);
+                    List<String> childs = 
+                        zk.getChildren("/hammers", false);
                     Collections.shuffle(childs);
                     for (String s : childs) {
                         if (s.startsWith("hammer-")) {

+ 4 - 4
zookeeper/test/com/yahoo/zookeeper/test/ZooKeeperTestClient.java

@@ -1,7 +1,7 @@
 package com.yahoo.zookeeper.test;
 
 import java.io.IOException;
-import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 
@@ -49,7 +49,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
       return;
     }
 
-    ArrayList<String> children = zk.getChildren(nodeName, false);
+    List<String> children = zk.getChildren(nodeName, false);
     if (children.size() == 0) {
       zk.delete(nodeName, -1);
       return;
@@ -170,7 +170,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
       }
     }
 
-    ArrayList<String> firstGen = zk_1.getChildren(parentName, true);
+    List<String> firstGen = zk_1.getChildren(parentName, true);
 
     try {
       zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, ZooDefs.CreateFlags.EPHEMERAL);
@@ -221,7 +221,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     }
 
     try {
-      ArrayList<String> children = zk.getChildren(nodeName, false);
+      List<String> children = zk.getChildren(nodeName, false);
       if (children.size() > 0) {
         fail("ephemeral node " + nodeName + " should not have children");
       }