camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-9115: camel-restlet - Should doneUoW using restlet callback
Date Sat, 05 Sep 2015 14:45:29 GMT
Repository: camel
Updated Branches:
  refs/heads/master 50c5e912c -> b712e00f2


CAMEL-9115: camel-restlet - Should doneUoW using restlet callback


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b712e00f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b712e00f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b712e00f

Branch: refs/heads/master
Commit: b712e00f2e8a0ef592fe732bc10d0cb19c10750e
Parents: 50c5e91
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Sep 5 16:45:37 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Sep 5 16:46:19 2015 +0200

----------------------------------------------------------------------
 .../component/restlet/RestletConsumer.java      | 25 +++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b712e00f/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConsumer.java
b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConsumer.java
index fa1f847..227f43d 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConsumer.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConsumer.java
@@ -23,6 +23,7 @@ import org.apache.camel.impl.DefaultConsumer;
 import org.restlet.Request;
 import org.restlet.Response;
 import org.restlet.Restlet;
+import org.restlet.Uniform;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -70,9 +71,14 @@ public class RestletConsumer extends DefaultConsumer {
                     }
                     binding.populateRestletResponseFromExchange(exchange, response);
 
+                    // resetlet will call the callback when its done sending where it would
be safe
+                    // to call doneUoW
+                    Uniform callback = newResponseUniform(exchange);
+                    response.setOnError(callback);
+                    response.setOnSent(callback);
+
                 } catch (Throwable e) {
                     getExceptionHandler().handleException("Error processing request", exchange,
e);
-                } finally {
                     if (exchange != null) {
                         doneUoW(exchange);
                     }
@@ -81,6 +87,23 @@ public class RestletConsumer extends DefaultConsumer {
         };
     }
 
+    /**
+     * Creates a new {@link org.restlet.Uniform} callback that restlet calls when its done
sending the reply message.
+     * <p/>
+     * We use this to defer done on the exchange {@link org.apache.camel.spi.UnitOfWork}
where resources is safe to be
+     * cleaned up as part of the done process.
+     */
+    private Uniform newResponseUniform(final Exchange exchange) {
+        return new Uniform() {
+            @Override
+            public void handle(Request request, Response response) {
+                if (exchange != null) {
+                    doneUoW(exchange);
+                }
+            }
+        };
+    }
+
     @Override
     protected void doStart() throws Exception {
         super.doStart();


Mime
View raw message