Author: davsclaus
Date: Wed Sep 5 10:59:28 2012
New Revision: 1381138
URL: http://svn.apache.org/viewvc?rev=1381138&view=rev
Log:
CAMEL-5564: Ensure default error handler thread pool and management load task
pool is shutdown properly.
Modified:
camel/branches/camel-2.10.x/ (props changed)
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/support/TimerListenerManager.java
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/management/LoadTimerTest.java
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/support/TimerListenerManagerTest.java
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Merged /camel/trunk:r1381089
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1381138&r1=1381137&r2=1381138&view=diff
==============================================================================
---
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Wed Sep 5 10:59:28 2012
@@ -1604,6 +1604,12 @@ public class DefaultCamelContext extends
// the stop order is important
+ // shutdown default error handler thread pool
+ if (errorHandlerExecutorService != null) {
+ getExecutorServiceManager().shutdown(errorHandlerExecutorService);
+ errorHandlerExecutorService = null;
+ }
+
// shutdown debugger
ServiceHelper.stopAndShutdownService(getDebugger());
Modified:
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java?rev=1381138&r1=1381137&r2=1381138&view=diff
==============================================================================
---
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
(original)
+++
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
Wed Sep 5 10:59:28 2012
@@ -85,7 +85,6 @@ import org.apache.camel.support.ServiceS
import org.apache.camel.support.TimerListenerManager;
import org.apache.camel.util.KeyValueHolder;
import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.ServiceHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -857,12 +856,10 @@ public class DefaultManagementLifecycleS
boolean enabled =
camelContext.getManagementStrategy().getStatisticsLevel() !=
ManagementStatisticsLevel.Off;
if (enabled) {
LOG.info("StatisticsLevel at {} so enabling load performance
statistics", camelContext.getManagementStrategy().getStatisticsLevel());
- // we have to defer creating this until CamelContext has been
started
- ScheduledExecutorService executorService =
camelContext.getExecutorServiceManager().newSingleThreadScheduledExecutor(this,
"ManagementLoadTask");
- timerListenerManager.setExecutorService(executorService);
// must use 1 sec interval as the load statistics is based on
1 sec calculations
timerListenerManager.setInterval(1000);
- ServiceHelper.startService(timerListenerManager);
+ // we have to defer enlisting timer lister manager as a
service until CamelContext has been started
+ getCamelContext().addService(timerListenerManager);
}
}
}
@@ -875,7 +872,6 @@ public class DefaultManagementLifecycleS
wrappedProcessors.clear();
managedTracers.clear();
managedThreadPools.clear();
- ServiceHelper.stopService(timerListenerManager);
}
/**
Modified:
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/support/TimerListenerManager.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/support/TimerListenerManager.java?rev=1381138&r1=1381137&r2=1381138&view=diff
==============================================================================
---
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/support/TimerListenerManager.java
(original)
+++
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/support/TimerListenerManager.java
Wed Sep 5 10:59:28 2012
@@ -22,6 +22,8 @@ import java.util.concurrent.ScheduledExe
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
import org.apache.camel.TimerListener;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
@@ -31,18 +33,16 @@ import org.slf4j.LoggerFactory;
* A {@link TimerListener} manager which triggers the
* {@link org.apache.camel.TimerListener} listeners once every second.
* <p/>
- * The {@link
#setExecutorService(java.util.concurrent.ScheduledExecutorService)} method
- * must be invoked prior to starting this manager using the {@link #start()}
method.
- * <p/>
* Also ensure when adding and remove listeners, that they are correctly
removed to avoid
* leaking memory.
*
* @see TimerListener
*/
-public class TimerListenerManager extends ServiceSupport implements Runnable {
+public class TimerListenerManager extends ServiceSupport implements Runnable,
CamelContextAware {
private static final Logger LOG =
LoggerFactory.getLogger(TimerListenerManager.class);
private final Set<TimerListener> listeners = new
LinkedHashSet<TimerListener>();
+ private CamelContext camelContext;
private ScheduledExecutorService executorService;
private volatile ScheduledFuture<?> task;
private long interval = 1000L;
@@ -50,8 +50,14 @@ public class TimerListenerManager extend
public TimerListenerManager() {
}
- public void setExecutorService(ScheduledExecutorService executorService) {
- this.executorService = executorService;
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
}
/**
@@ -122,8 +128,11 @@ public class TimerListenerManager extend
@Override
protected void doStart() throws Exception {
- ObjectHelper.notNull(executorService, "executorService", this);
- task = executorService.scheduleAtFixedRate(this, 1000L, interval,
TimeUnit.MILLISECONDS);
+ ObjectHelper.notNull(camelContext, "camelContext", this);
+
+ // create scheduled thread pool to trigger the task to run every
interval
+ executorService =
camelContext.getExecutorServiceManager().newSingleThreadScheduledExecutor(this,
"ManagementLoadTask");
+ task = executorService.scheduleAtFixedRate(this, interval, interval,
TimeUnit.MILLISECONDS);
LOG.debug("Started scheduled TimerListener task to run with interval
{} ms", interval);
}
@@ -139,6 +148,9 @@ public class TimerListenerManager extend
@Override
protected void doShutdown() throws Exception {
super.doShutdown();
+ // shutdown thread pool when we are shutting down
+ camelContext.getExecutorServiceManager().shutdown(executorService);
+ executorService = null;
listeners.clear();
}
}
Modified:
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/management/LoadTimerTest.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/management/LoadTimerTest.java?rev=1381138&r1=1381137&r2=1381138&view=diff
==============================================================================
---
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/management/LoadTimerTest.java
(original)
+++
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/management/LoadTimerTest.java
Wed Sep 5 10:59:28 2012
@@ -16,23 +16,23 @@
*/
package org.apache.camel.management;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-
-import junit.framework.TestCase;
+import org.apache.camel.ContextTestSupport;
import org.apache.camel.TimerListener;
import org.apache.camel.management.mbean.LoadTriplet;
import org.apache.camel.support.TimerListenerManager;
-public class LoadTimerTest extends TestCase {
+public class LoadTimerTest extends ContextTestSupport {
private static final int SAMPLES = 3;
- public void testTimer() throws Exception {
- ScheduledExecutorService executorService =
Executors.newScheduledThreadPool(1);
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+ public void testTimer() throws Exception {
TimerListenerManager myTimer = new TimerListenerManager();
- myTimer.setExecutorService(executorService);
+ myTimer.setCamelContext(context);
myTimer.start();
TestLoadAware test = new TestLoadAware();
@@ -48,7 +48,6 @@ public class LoadTimerTest extends TestC
}
myTimer.stop();
- executorService.shutdown();
}
private class TestLoadAware implements TimerListener {
Modified:
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java?rev=1381138&r1=1381137&r2=1381138&view=diff
==============================================================================
---
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
(original)
+++
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
Wed Sep 5 10:59:28 2012
@@ -53,7 +53,7 @@ public class ManagedRouteAddRemoveTest e
// number of services
Set<ObjectName> names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Adding 2nd route");
@@ -73,7 +73,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Removing 2nd route");
@@ -84,7 +84,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Shutting down...");
}
@@ -100,7 +100,7 @@ public class ManagedRouteAddRemoveTest e
// number of services
Set<ObjectName> names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Adding 2nd route");
@@ -120,7 +120,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Removing 2nd route");
@@ -131,7 +131,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Shutting down...");
}
@@ -147,7 +147,7 @@ public class ManagedRouteAddRemoveTest e
// number of services
Set<ObjectName> names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Adding 2nd route");
@@ -167,7 +167,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Removing 2nd route");
@@ -178,7 +178,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Shutting down...");
}
@@ -194,7 +194,7 @@ public class ManagedRouteAddRemoveTest e
// number of services
Set<ObjectName> names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Adding 2nd route");
@@ -224,7 +224,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
// now stop and remove the 2nd route
log.info("Stopping 2nd route");
@@ -236,7 +236,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Shutting down...");
}
@@ -252,7 +252,7 @@ public class ManagedRouteAddRemoveTest e
// number of services
Set<ObjectName> names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Adding 2nd route");
@@ -283,7 +283,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
// now stop and remove the 2nd route
log.info("Stopping 2nd route");
@@ -295,7 +295,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Shutting down...");
}
@@ -311,7 +311,7 @@ public class ManagedRouteAddRemoveTest e
// number of services
Set<ObjectName> names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Adding 2nd route");
@@ -340,7 +340,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
// now stop and remove the 2nd route
log.info("Stopping 2nd route");
@@ -352,7 +352,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Shutting down...");
}
@@ -368,7 +368,7 @@ public class ManagedRouteAddRemoveTest e
// number of services
Set<ObjectName> names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Adding 2nd route");
@@ -398,7 +398,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
// now stop and remove the 2nd route
log.info("Stopping 2nd route");
@@ -410,7 +410,7 @@ public class ManagedRouteAddRemoveTest e
// there should still be the same number of services
names = mbeanServer.queryNames(on, null);
- assertEquals(7, names.size());
+ assertEquals(8, names.size());
log.info("Shutting down...");
}
Modified:
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/support/TimerListenerManagerTest.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/support/TimerListenerManagerTest.java?rev=1381138&r1=1381137&r2=1381138&view=diff
==============================================================================
---
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/support/TimerListenerManagerTest.java
(original)
+++
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/support/TimerListenerManagerTest.java
Wed Sep 5 10:59:28 2012
@@ -21,20 +21,25 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-import junit.framework.TestCase;
+import org.apache.camel.ContextTestSupport;
import org.apache.camel.TimerListener;
/**
*
*/
-public class TimerListenerManagerTest extends TestCase {
+public class TimerListenerManagerTest extends ContextTestSupport {
private final MyTask task = new MyTask();
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
public void testTimerListenerManager() throws Exception {
ScheduledExecutorService executor =
Executors.newScheduledThreadPool(1);
TimerListenerManager manager = new TimerListenerManager();
- manager.setExecutorService(executor);
+ manager.setCamelContext(context);
manager.addTimerListener(task);
manager.start();