Repository: camel
Updated Branches:
  refs/heads/master d4671fda1 -> f4886f8c8


CAMEL-8004: Fixed concurreny dead-lock potential when using getRoutes from 
CamelContext. Thanks to Babak for researching this.


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

Branch: refs/heads/master
Commit: f4886f8c8eb02a11f99fbaacb9e7285e634add13
Parents: d4671fd
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri Nov 7 14:17:38 2014 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Nov 7 14:43:15 2014 +0100

----------------------------------------------------------------------
 .../apache/camel/impl/DefaultCamelContext.java    | 18 ++++++++++++------
 .../camel/component/quartz2/QuartzEndpoint.java   |  2 +-
 .../quartz2/QuartzNameCollisionTest.java          |  2 +-
 3 files changed, 14 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f4886f8c/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index a91d176..1ca5e19 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -657,12 +657,14 @@ public class DefaultCamelContext extends ServiceSupport 
implements ModelCamelCon
         return routeStartupOrder;
     }
 
-    public synchronized List<Route> getRoutes() {
+    public List<Route> getRoutes() {
         // lets return a copy of the collection as objects are removed later 
when services are stopped
         if (routes.isEmpty()) {
             return Collections.emptyList();
         } else {
-            return new ArrayList<Route>(routes);
+            synchronized (routes) {
+                return new ArrayList<Route>(routes);
+            }
         }
     }
 
@@ -680,12 +682,16 @@ public class DefaultCamelContext extends ServiceSupport 
implements ModelCamelCon
         throw new UnsupportedOperationException("Overriding existing routes is 
not supported yet, use addRouteCollection instead");
     }
 
-    synchronized void removeRouteCollection(Collection<Route> routes) {
-        this.routes.removeAll(routes);
+    void removeRouteCollection(Collection<Route> routes) {
+        synchronized (routes) {
+            this.routes.removeAll(routes);
+        }
     }
 
-    synchronized void addRouteCollection(Collection<Route> routes) throws 
Exception {
-        this.routes.addAll(routes);
+    void addRouteCollection(Collection<Route> routes) throws Exception {
+        synchronized (routes) {
+            this.routes.addAll(routes);
+        }
     }
 
     public void addRoutes(RoutesBuilder builder) throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/f4886f8c/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
----------------------------------------------------------------------
diff --git 
a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
 
b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
index ff70323..4acb773 100644
--- 
a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
+++ 
b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
@@ -269,7 +269,7 @@ public class QuartzEndpoint extends DefaultEndpoint {
                 QuartzEndpoint quartzEndpoint = (QuartzEndpoint) 
route.getEndpoint();
                 TriggerKey checkTriggerKey = quartzEndpoint.getTriggerKey();
                 if (triggerKey.equals(checkTriggerKey)) {
-                    throw new IllegalArgumentException("Trigger key " + 
triggerKey + " is already in used by " + quartzEndpoint);
+                    throw new IllegalArgumentException("Trigger key " + 
triggerKey + " is already in use by " + quartzEndpoint);
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/f4886f8c/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java
 
b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java
index 66a620f..7444b2b 100644
--- 
a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java
+++ 
b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java
@@ -55,7 +55,7 @@ public class QuartzNameCollisionTest {
             Assert.fail("Should have thrown an exception");
         } catch (FailedToCreateRouteException e) {
             String reason = e.getMessage();
-            Assert.assertEquals(reason.indexOf("Trigger key 
myGroup.myTimerName is already in used") >= 0, true);
+            Assert.assertEquals(reason.indexOf("Trigger key 
myGroup.myTimerName is already in use") >= 0, true);
         }
     }
 

Reply via email to