jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1453907 - in /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test: AbstractJCRTest.java RepositoryHelperPool.java RepositoryHelperPoolImpl.java
Date Thu, 07 Mar 2013 15:02:05 GMT
Author: mreutegg
Date: Thu Mar  7 15:02:05 2013
New Revision: 1453907

URL: http://svn.apache.org/r1453907
Log:
JCR-3531: Borrow all available RepositoryHelpers

Modified:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPool.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPoolImpl.java

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java?rev=1453907&r1=1453906&r2=1453907&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
Thu Mar  7 15:02:05 2013
@@ -51,7 +51,7 @@ public abstract class AbstractJCRTest ex
     /**
      * Pool of helper objects to access repository transparently
      */
-    private static final RepositoryHelperPool HELPER_POOL = new RepositoryHelperPoolImpl();
+    private static final RepositoryHelperPool HELPER_POOL = RepositoryHelperPoolImpl.getInstance();
 
     /**
      * Namespace URI for jcr prefix.

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPool.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPool.java?rev=1453907&r1=1453906&r2=1453907&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPool.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPool.java
Thu Mar  7 15:02:05 2013
@@ -31,6 +31,16 @@ public interface RepositoryHelperPool {
     public RepositoryHelper borrowHelper() throws InterruptedException;
 
     /**
+     * Borrows all available repository helper instances. Waits until one
+     * becomes available.
+     *
+     * @return a repository helper.
+     * @throws InterruptedException if this thread is interrupted while waiting
+     *                              for a repository helper.
+     */
+    public RepositoryHelper[] borrowHelpers() throws InterruptedException;
+
+    /**
      * Returns the given repository helper to the pool.
      *
      * @param helper the repository helper to return.

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPoolImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPoolImpl.java?rev=1453907&r1=1453906&r2=1453907&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPoolImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPoolImpl.java
Thu Mar  7 15:02:05 2013
@@ -21,7 +21,6 @@ import java.util.LinkedList;
 import java.util.Properties;
 import java.util.Map;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.io.InputStream;
 import java.io.IOException;
 
@@ -33,9 +32,18 @@ public class RepositoryHelperPoolImpl im
 
     private static final String PROP_FILE = "repositoryHelperPool.properties";
 
-    private List helpers = new LinkedList();
+    private List<RepositoryHelper> helpers = new LinkedList<RepositoryHelper>();
 
-    public RepositoryHelperPoolImpl() {
+    private static RepositoryHelperPool POOL = null;
+
+    public synchronized static RepositoryHelperPool getInstance() {
+        if (POOL == null) {
+            POOL = new RepositoryHelperPoolImpl();
+        }
+        return POOL;
+    }
+
+    private RepositoryHelperPoolImpl() {
         InputStream in = RepositoryHelperPoolImpl.class.getClassLoader().getResourceAsStream(PROP_FILE);
         if (in != null) {
             try {
@@ -43,9 +51,8 @@ public class RepositoryHelperPoolImpl im
                 props.load(in);
                 for (int i = 0;; i++) {
                     String prefix = "helper." + i + ".";
-                    Map helperProp = new HashMap();
-                    for (Iterator it = props.entrySet().iterator(); it.hasNext(); ) {
-                        Map.Entry entry = (Map.Entry) it.next();
+                    Map<String, Object> helperProp = new HashMap<String, Object>();
+                    for (Map.Entry<Object, Object> entry : props.entrySet()) {
                         String key = (String) entry.getKey();
                         if (key.startsWith(prefix)) {
                             helperProp.put(key.substring(prefix.length()), entry.getValue());
@@ -81,7 +88,18 @@ public class RepositoryHelperPoolImpl im
         while (helpers.isEmpty()) {
             wait();
         }
-        return (RepositoryHelper) helpers.remove(0);
+        return helpers.remove(0);
+    }
+
+    public synchronized RepositoryHelper[] borrowHelpers() throws InterruptedException {
+        while (helpers.isEmpty()) {
+            wait();
+        }
+        try {
+            return helpers.toArray(new RepositoryHelper[helpers.size()]);
+        } finally {
+            helpers.clear();
+        }
     }
 
     public synchronized void returnHelper(RepositoryHelper helper) {



Mime
View raw message