You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2012/04/21 10:44:56 UTC
svn commit: r1328614 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/impl/DefaultCamelContext.java
test/java/org/apache/camel/issues/NotifyBuilderOnFailureShutdownCamelIssueTest.java
Author: davsclaus
Date: Sat Apr 21 08:44:55 2012
New Revision: 1328614
URL: http://svn.apache.org/viewvc?rev=1328614&view=rev
Log:
CAMEL-5200: Fixed potential dead-lock with getRoutes on CamelContext, during shutdown of Camel.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/NotifyBuilderOnFailureShutdownCamelIssueTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1328614&r1=1328613&r2=1328614&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Sat Apr 21 08:44:55 2012
@@ -144,7 +144,7 @@ public class DefaultCamelContext extends
private final AtomicInteger endpointKeyCounter = new AtomicInteger();
private final List<EndpointStrategy> endpointStrategies = new ArrayList<EndpointStrategy>();
private final Map<String, Component> components = new HashMap<String, Component>();
- private Set<Route> routes;
+ private final Set<Route> routes = new LinkedHashSet<Route>();
private final List<Service> servicesToClose = new ArrayList<Service>();
private final Set<StartupListener> startupListeners = new LinkedHashSet<StartupListener>();
private TypeConverter typeConverter;
@@ -583,13 +583,8 @@ public class DefaultCamelContext extends
return routeStartupOrder;
}
- public synchronized List<Route> getRoutes() {
- if (routes == null) {
- routes = new LinkedHashSet<Route>();
- }
-
- // lets return a copy of the collection as objects are removed later
- // when services are stopped
+ public List<Route> getRoutes() {
+ // lets return a copy of the collection as objects are removed later when services are stopped
return new ArrayList<Route>(routes);
}
@@ -608,19 +603,11 @@ public class DefaultCamelContext extends
}
synchronized void removeRouteCollection(Collection<Route> routes) {
- if (this.routes != null) {
- this.routes.removeAll(routes);
- }
+ this.routes.removeAll(routes);
}
synchronized void addRouteCollection(Collection<Route> routes) throws Exception {
- if (this.routes == null) {
- this.routes = new LinkedHashSet<Route>();
- }
-
- if (routes != null) {
- this.routes.addAll(routes);
- }
+ this.routes.addAll(routes);
}
public void addRoutes(RoutesBuilder builder) throws Exception {
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/NotifyBuilderOnFailureShutdownCamelIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/NotifyBuilderOnFailureShutdownCamelIssueTest.java?rev=1328614&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/issues/NotifyBuilderOnFailureShutdownCamelIssueTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/issues/NotifyBuilderOnFailureShutdownCamelIssueTest.java Sat Apr 21 08:44:55 2012
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class NotifyBuilderOnFailureShutdownCamelIssueTest extends ContextTestSupport {
+
+ public void testIssue() throws Exception {
+ NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();
+ assertTrue(notify.matchesMockWaitTime());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("timer:foo?period=100")
+ .throwException(new IllegalArgumentException("Forced"));
+ }
+ };
+ }
+}