[Dive4elements-commits] [PATCH] GWT client: prevent too many create artifact calls at the same time by limiting them to 5

Wald Commits scm-commit at wald.intevation.org
Wed Jun 26 21:35:58 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1372275353 -7200
# Node ID eb4d0950ae87c106c7a0d5646f3e5ea48c79c773
# Parent  00aa1bc72a65f4ddfedb48e01be7210d52a78e9e
GWT client: prevent too many create artifact calls at the same time by limiting them to 5.

diff -r 00aa1bc72a65 -r eb4d0950ae87 gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactHelper.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactHelper.java	Wed Jun 26 20:50:58 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactHelper.java	Wed Jun 26 21:35:53 2013 +0200
@@ -16,6 +16,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Semaphore;
 
 import org.dive4elements.artifacts.common.utils.ClientProtocolUtils;
 import org.dive4elements.artifacts.common.utils.CreationFilter;
@@ -52,6 +53,12 @@
 
     private static final String SQ_RELATION_ARTIFACT = "staticsqrelation";
 
+    // To prevent pile up of create artifact calls only permit a limited
+    // number of parallel creates.
+    public static final int MAX_CREATE = 5;
+
+    private static final Semaphore CREATE_SEMAPHORE = new Semaphore(MAX_CREATE);
+
     private ArtifactHelper() {
     }
 
@@ -90,7 +97,6 @@
             factory, uuid, ids, filter, targetOut);
 
         return sendCreate(serverUrl, locale, create);
-
     }
 
     /**
@@ -170,16 +176,27 @@
             Document doc)
     throws ServerException
     {
-        HttpClient client = new HttpClientImpl(serverUrl, locale);
+        try {
+            CREATE_SEMAPHORE.acquire();
+        }
+        catch (InterruptedException ie) {
+            throw new ServerException(ERROR_CREATE_ARTIFACT);
+        }
+        try {
+            HttpClient client = new HttpClientImpl(serverUrl, locale);
 
-        try {
-            return (Artifact) client.create(doc, new FLYSArtifactCreator());
+            try {
+                return (Artifact) client.create(doc, new FLYSArtifactCreator());
+            }
+            catch (ConnectionException ce) {
+                logger.error(ce, ce);
+            }
+
+            throw new ServerException(ERROR_CREATE_ARTIFACT);
         }
-        catch (ConnectionException ce) {
-            logger.error(ce, ce);
+        finally {
+            CREATE_SEMAPHORE.release();
         }
-
-        throw new ServerException(ERROR_CREATE_ARTIFACT);
     }
 
 


More information about the Dive4elements-commits mailing list