Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

JCR-3531: Borrow all available RepositoryHelpers

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/trunk@1453907 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit cf8f6eee98c33446228fc63f47f6dc8bbb7873e4 1 parent 55b60e9
@mreutegg mreutegg authored
View
2  jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
@@ -51,7 +51,7 @@
/**
* 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.
View
10 jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPool.java
@@ -31,6 +31,16 @@
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.
View
32 jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPoolImpl.java
@@ -21,7 +21,6 @@
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 @@
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 RepositoryHelperPoolImpl() {
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 synchronized RepositoryHelper borrowHelper()
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) {
Please sign in to comment.
Something went wrong with that request. Please try again.