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 2010/12/18 10:40:25 UTC
svn commit: r1050603 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/impl/
camel-core/src/main/java/org/apache/camel/management/
camel-core/src/main/java/org/apache/camel/management/mbean/
camel-core/src/main/java/org/apache/camel/spi/ cam...
Author: davsclaus
Date: Sat Dec 18 09:40:24 2010
New Revision: 1050603
URL: http://svn.apache.org/viewvc?rev=1050603&view=rev
Log:
CAMEL-3437: Thread pools now use better naming in JMX, so its much easier for end user to spot whats the thread pool is used for.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/management/DualManagedThreadPoolProfileTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/management/DualManagedThreadPoolWithIdTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolProfileTest.java
- copied, changed from r1050327, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolWithIdTest.java
- copied, changed from r1050327, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/DualSpringManagedThreadsThreadPoolTest.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringManagedThreadsThreadPoolTest.java
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDualManagedThreadsThreadPoolTest.xml
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringManagedThreadsThreadPoolTest.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThreadPool.java
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/LifecycleStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java
camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
camel/trunk/components/camel-spring-security/src/main/java/org/apache/camel/component/spring/security/config/SpringSecurityAuthorizationPolicyParser.java
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/BeanDefinitionParser.java
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java Sat Dec 18 09:40:24 2010
@@ -29,6 +29,10 @@ import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
import org.apache.camel.ThreadPoolRejectedPolicy;
+import org.apache.camel.model.OptionalIdentifiedDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ProcessorDefinitionHelper;
+import org.apache.camel.model.RouteDefinition;
import org.apache.camel.spi.ExecutorServiceStrategy;
import org.apache.camel.spi.LifecycleStrategy;
import org.apache.camel.spi.ThreadPoolProfile;
@@ -202,7 +206,7 @@ public class DefaultExecutorServiceStrat
Integer maxQueueSize = profile.getMaxQueueSize() != null ? profile.getMaxQueueSize() : defaultProfile.getMaxQueueSize();
RejectedExecutionHandler handler = profile.getRejectedExecutionHandler() != null ? profile.getRejectedExecutionHandler() : defaultProfile.getRejectedExecutionHandler();
// create the pool
- return newThreadPool(source, name, poolSize, maxPoolSize, keepAliveTime, timeUnit, maxQueueSize, handler, false);
+ return newThreadPool(threadPoolProfileId, source, name, poolSize, maxPoolSize, keepAliveTime, timeUnit, maxQueueSize, handler, false);
} else {
// no profile with that id
return null;
@@ -211,7 +215,7 @@ public class DefaultExecutorServiceStrat
public ExecutorService newCachedThreadPool(Object source, String name) {
ExecutorService answer = ExecutorServiceHelper.newCachedThreadPool(threadNamePattern, name, true);
- onThreadPoolCreated(answer);
+ onThreadPoolCreated(answer, source, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Created new cached thread pool for source: " + source + " with name: " + name + ". -> " + answer);
@@ -226,7 +230,7 @@ public class DefaultExecutorServiceStrat
public ScheduledExecutorService newScheduledThreadPool(Object source, String name, int poolSize) {
ScheduledExecutorService answer = ExecutorServiceHelper.newScheduledThreadPool(poolSize, threadNamePattern, name, true);
- onThreadPoolCreated(answer);
+ onThreadPoolCreated(answer, source, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Created new scheduled thread pool for source: " + source + " with name: " + name + ". [poolSize=" + poolSize + "]. -> " + answer);
@@ -236,7 +240,7 @@ public class DefaultExecutorServiceStrat
public ExecutorService newFixedThreadPool(Object source, String name, int poolSize) {
ExecutorService answer = ExecutorServiceHelper.newFixedThreadPool(poolSize, threadNamePattern, name, true);
- onThreadPoolCreated(answer);
+ onThreadPoolCreated(answer, source, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Created new fixed thread pool for source: " + source + " with name: " + name + ". [poolSize=" + poolSize + "]. -> " + answer);
@@ -246,7 +250,7 @@ public class DefaultExecutorServiceStrat
public ExecutorService newSingleThreadExecutor(Object source, String name) {
ExecutorService answer = ExecutorServiceHelper.newSingleThreadExecutor(threadNamePattern, name, true);
- onThreadPoolCreated(answer);
+ onThreadPoolCreated(answer, source, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Created new single thread pool for source: " + source + " with name: " + name + ". -> " + answer);
@@ -256,7 +260,7 @@ public class DefaultExecutorServiceStrat
public ExecutorService newSynchronousThreadPool(Object source, String name) {
ExecutorService answer = ExecutorServiceHelper.newSynchronousThreadPool();
- onThreadPoolCreated(answer);
+ onThreadPoolCreated(answer, source, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Created new synchronous thread pool for source: " + source + " with name: " + name + ". -> " + answer);
@@ -266,7 +270,7 @@ public class DefaultExecutorServiceStrat
public ExecutorService newThreadPool(Object source, String name, int corePoolSize, int maxPoolSize) {
ExecutorService answer = ExecutorServiceHelper.newThreadPool(threadNamePattern, name, corePoolSize, maxPoolSize);
- onThreadPoolCreated(answer);
+ onThreadPoolCreated(answer, source, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Created new thread pool for source: " + source + " with name: " + name + ". [poolSize=" + corePoolSize
@@ -277,7 +281,7 @@ public class DefaultExecutorServiceStrat
public ExecutorService newThreadPool(Object source, String name, int corePoolSize, int maxPoolSize, int maxQueueSize) {
ExecutorService answer = ExecutorServiceHelper.newThreadPool(threadNamePattern, name, corePoolSize, maxPoolSize, maxQueueSize);
- onThreadPoolCreated(answer);
+ onThreadPoolCreated(answer, source, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Created new thread pool for source: " + source + " with name: " + name + ". [poolSize=" + corePoolSize
@@ -286,22 +290,22 @@ public class DefaultExecutorServiceStrat
return answer;
}
- public ExecutorService newThreadPool(Object source, String name, int corePoolSize, int maxPoolSize, long keepAliveTime,
+ private ExecutorService newThreadPool(String threadPoolProfileId, Object source, String name, int corePoolSize, int maxPoolSize, long keepAliveTime,
TimeUnit timeUnit, int maxQueueSize, RejectedExecutionHandler rejectedExecutionHandler,
boolean daemon) {
// the thread name must not be null
ObjectHelper.notNull(name, "ThreadName");
-
+
// If we set the corePoolSize to be 0, the whole camel application will hang in JDK5
- // just add a check here to throw the IllegalArgumentException
+ // just add a check here to throw the IllegalArgumentException
if (corePoolSize < 1) {
throw new IllegalArgumentException("The corePoolSize can't be lower than 1");
}
-
+
ExecutorService answer = ExecutorServiceHelper.newThreadPool(threadNamePattern, name, corePoolSize, maxPoolSize, keepAliveTime,
timeUnit, maxQueueSize, rejectedExecutionHandler, daemon);
- onThreadPoolCreated(answer);
+ onThreadPoolCreated(answer, source, threadPoolProfileId);
if (LOG.isDebugEnabled()) {
LOG.debug("Created new thread pool for source: " + source + " with name: " + name + ". [poolSize=" + corePoolSize
@@ -312,6 +316,13 @@ public class DefaultExecutorServiceStrat
return answer;
}
+
+ public ExecutorService newThreadPool(Object source, String name, int corePoolSize, int maxPoolSize, long keepAliveTime,
+ TimeUnit timeUnit, int maxQueueSize, RejectedExecutionHandler rejectedExecutionHandler,
+ boolean daemon) {
+ return newThreadPool(null, source, name, corePoolSize, maxPoolSize, keepAliveTime, timeUnit, maxQueueSize, rejectedExecutionHandler, daemon);
+ }
+
public void shutdown(ExecutorService executorService) {
ObjectHelper.notNull(executorService, "executorService");
@@ -346,15 +357,36 @@ public class DefaultExecutorServiceStrat
return answer;
}
- private void onThreadPoolCreated(ExecutorService executorService) {
+ private void onThreadPoolCreated(ExecutorService executorService, Object source, String threadPoolProfileId) {
// add to internal list of thread pools
executorServices.add(executorService);
+ String id = null; //threadPoolProfileId;
+ String sourceId = null;
+ String routeId = null;
+
+ // extract id from source
+ if (source instanceof OptionalIdentifiedDefinition) {
+ id = ((OptionalIdentifiedDefinition) source).idOrCreate(camelContext.getNodeIdFactory());
+ // and let source be the short name of the pattern
+ sourceId = ((OptionalIdentifiedDefinition) source).getShortName();
+ } else if (source instanceof String) {
+ id = (String) source;
+ }
+
+ // extract route id if possible
+ if (source instanceof ProcessorDefinition) {
+ RouteDefinition route = ProcessorDefinitionHelper.getRoute((ProcessorDefinition) source);
+ if (route != null) {
+ routeId = route.idOrCreate(camelContext.getNodeIdFactory());
+ }
+ }
+
// let lifecycle strategy be notified as well which can let it be managed in JMX as well
if (executorService instanceof ThreadPoolExecutor) {
ThreadPoolExecutor threadPool = (ThreadPoolExecutor) executorService;
for (LifecycleStrategy lifecycle : camelContext.getLifecycleStrategies()) {
- lifecycle.onThreadPoolAdd(camelContext, threadPool);
+ lifecycle.onThreadPoolAdd(camelContext, threadPool, id, sourceId, routeId, threadPoolProfileId);
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java Sat Dec 18 09:40:24 2010
@@ -598,13 +598,15 @@ public class DefaultManagementLifecycleS
}
}
- public void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor threadPool) {
+ public void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor threadPool, String id,
+ String sourceId, String routeId, String threadPoolProfileId) {
// the agent hasn't been started
if (!initialized) {
return;
}
- ManagedThreadPool mtp = new ManagedThreadPool(camelContext, threadPool);
+ // use a String representation of source
+ ManagedThreadPool mtp = new ManagedThreadPool(camelContext, threadPool, id, sourceId, routeId, threadPoolProfileId);
mtp.init(getManagementStrategy());
// skip already managed services, for example if a route has been restarted
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java Sat Dec 18 09:40:24 2010
@@ -249,14 +249,24 @@ public class DefaultManagementNamingStra
return createObjectName(buffer);
}
- public ObjectName getObjectNameForThreadPool(CamelContext context, ThreadPoolExecutor threadPool) throws MalformedObjectNameException {
+ public ObjectName getObjectNameForThreadPool(CamelContext context, ThreadPoolExecutor threadPool, String id, String sourceId) throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_THREAD_POOL + ",");
- buffer.append(KEY_NAME + "=")
- .append(threadPool.getClass().getSimpleName())
- .append("(").append(ObjectHelper.getIdentityHashCode(threadPool)).append(")");
+ buffer.append(KEY_NAME + "=");
+ if (id == null) {
+ // if no id then use class name as source id
+ buffer.append(threadPool.getClass().getSimpleName());
+ } else {
+ buffer.append(id);
+ }
+ if (id == null && sourceId == null) {
+ // if we dont really know the id or source id then use hashcode so its unique
+ buffer.append("(").append(ObjectHelper.getIdentityHashCode(threadPool)).append(")");
+ } else if (sourceId != null) {
+ buffer.append("(").append(sourceId).append(")");
+ }
return createObjectName(buffer);
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java Sat Dec 18 09:40:24 2010
@@ -117,7 +117,7 @@ public class ManagedManagementStrategy e
objectName = getManagementNamingStrategy().getObjectNameForEventNotifier(men.getContext(), men.getEventNotifier());
} else if (managedObject instanceof ManagedThreadPool) {
ManagedThreadPool mes = (ManagedThreadPool) managedObject;
- objectName = getManagementNamingStrategy().getObjectNameForThreadPool(mes.getContext(), mes.getThreadPool());
+ objectName = getManagementNamingStrategy().getObjectNameForThreadPool(mes.getContext(), mes.getThreadPool(), mes.getId(), mes.getSourceId());
} else if (managedObject instanceof ManagedService) {
// check for managed service should be last
ManagedService ms = (ManagedService) managedObject;
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThreadPool.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThreadPool.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThreadPool.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThreadPool.java Sat Dec 18 09:40:24 2010
@@ -32,10 +32,19 @@ public class ManagedThreadPool {
private final CamelContext camelContext;
private final ThreadPoolExecutor threadPool;
+ private final String id;
+ private final String sourceId;
+ private final String routeId;
+ private final String threadPoolProfileId;
- public ManagedThreadPool(CamelContext camelContext, ThreadPoolExecutor threadPool) {
+ public ManagedThreadPool(CamelContext camelContext, ThreadPoolExecutor threadPool, String id,
+ String sourceId, String routeId, String threadPoolProfileId) {
this.camelContext = camelContext;
this.threadPool = threadPool;
+ this.sourceId = sourceId;
+ this.id = id;
+ this.routeId = routeId;
+ this.threadPoolProfileId = threadPoolProfileId;
}
public void init(ManagementStrategy strategy) {
@@ -50,6 +59,26 @@ public class ManagedThreadPool {
return threadPool;
}
+ @ManagedAttribute(description = "Thread Pool id")
+ public String getId() {
+ return id;
+ }
+
+ @ManagedAttribute(description = "Id of source for creating Thread Pool")
+ public String getSourceId() {
+ return sourceId;
+ }
+
+ @ManagedAttribute(description = "Route id for the source, which created the Thread Pool")
+ public String getRouteId() {
+ return routeId;
+ }
+
+ @ManagedAttribute(description = "Id of the thread pool profile which this pool is based upon")
+ public String getThreadPoolProfileId() {
+ return threadPoolProfileId;
+ }
+
@ManagedAttribute(description = "Core pool size")
public int getCorePoolSize() {
return threadPool.getCorePoolSize();
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/LifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/LifecycleStrategy.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/LifecycleStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/LifecycleStrategy.java Sat Dec 18 09:40:24 2010
@@ -38,7 +38,7 @@ public interface LifecycleStrategy {
*
* @param context the camel context
* @throws VetoCamelContextStartException can be thrown to veto starting {@link CamelContext}.
- * Any other runtime exceptions will be logged at <tt>WARN</tt> level by Camel will continue starting itself.
+ * Any other runtime exceptions will be logged at <tt>WARN</tt> level by Camel will continue starting itself.
*/
void onContextStart(CamelContext context) throws VetoCamelContextStartException;
@@ -52,7 +52,7 @@ public interface LifecycleStrategy {
/**
* Notification on adding an {@link org.apache.camel.Component}.
*
- * @param name the unique name of this component
+ * @param name the unique name of this component
* @param component the added component
*/
void onComponentAdd(String name, Component component);
@@ -60,7 +60,7 @@ public interface LifecycleStrategy {
/**
* Notification on removing an {@link org.apache.camel.Component}.
*
- * @param name the unique name of this component
+ * @param name the unique name of this component
* @param component the removed component
*/
void onComponentRemove(String name, Component component);
@@ -130,9 +130,14 @@ public interface LifecycleStrategy {
/**
* Notification on adding a thread pool.
*
- * @param camelContext the camel context
- * @param threadPool the thread pool
+ * @param camelContext the camel context
+ * @param threadPool the thread pool
+ * @param id id of the thread pool (can be null in special cases)
+ * @param sourceId id of the source creating the thread pool (can be null in special cases)
+ * @param routeId id of the route for the source (is null if no source)
+ * @param threadPoolProfileId id of the thread pool profile, if used for creating this thread pool (can be null)
*/
- void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor threadPool);
+ void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor threadPool, String id,
+ String sourceId, String routeId, String threadPoolProfileId);
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java Sat Dec 18 09:40:24 2010
@@ -60,7 +60,7 @@ public interface ManagementNamingStrateg
ObjectName getObjectNameForService(CamelContext context, Service service) throws MalformedObjectNameException;
- ObjectName getObjectNameForThreadPool(CamelContext context, ThreadPoolExecutor threadPool) throws MalformedObjectNameException;
+ ObjectName getObjectNameForThreadPool(CamelContext context, ThreadPoolExecutor threadPool, String id, String sourceId) throws MalformedObjectNameException;
ObjectName getObjectNameForEventNotifier(CamelContext context, EventNotifier eventNotifier) throws MalformedObjectNameException;
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java Sat Dec 18 09:40:24 2010
@@ -86,7 +86,8 @@ public class DummyLifecycleStrategy impl
events.add("onErrorHandlerAdd");
}
- public void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor threadPool) {
+ public void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor threadPool, String id,
+ String sourceId, String routeId, String threadPoolProfileId) {
events.add("onThreadPoolAdd");
}
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/management/DualManagedThreadPoolProfileTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/DualManagedThreadPoolProfileTest.java?rev=1050603&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/DualManagedThreadPoolProfileTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/DualManagedThreadPoolProfileTest.java Sat Dec 18 09:40:24 2010
@@ -0,0 +1,115 @@
+/**
+ * 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.management;
+
+import java.util.Iterator;
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ThreadPoolRejectedPolicy;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.ThreadPoolProfileSupport;
+import org.apache.camel.spi.ThreadPoolProfile;
+
+/**
+ * @version $Revision: 1005721 $
+ */
+public class DualManagedThreadPoolProfileTest extends ContextTestSupport {
+
+ @Override
+ protected boolean useJmx() {
+ return true;
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ DefaultManagementNamingStrategy naming = (DefaultManagementNamingStrategy) context.getManagementStrategy().getManagementNamingStrategy();
+ naming.setHostName("localhost");
+ naming.setDomainName("org.apache.camel");
+ return context;
+ }
+
+ public void testManagedThreadPool() throws Exception {
+ MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
+
+ ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=threadpools,name=threads1(threads)");
+
+ Integer corePoolSize = (Integer) mbeanServer.getAttribute(on, "CorePoolSize");
+ assertEquals(5, corePoolSize.intValue());
+
+ Integer maxPoolSize = (Integer) mbeanServer.getAttribute(on, "MaximumPoolSize");
+ assertEquals(15, maxPoolSize.intValue());
+
+ String id = (String) mbeanServer.getAttribute(on, "Id");
+ assertEquals("threads1", id);
+
+ String source = (String) mbeanServer.getAttribute(on, "SourceId");
+ assertEquals("threads", source);
+
+ String route = (String) mbeanServer.getAttribute(on, "RouteId");
+ assertEquals("route1", route);
+
+ String profile = (String) mbeanServer.getAttribute(on, "ThreadPoolProfileId");
+ assertEquals("custom", profile);
+
+ on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=threadpools,name=threads2(threads)");
+
+ corePoolSize = (Integer) mbeanServer.getAttribute(on, "CorePoolSize");
+ assertEquals(5, corePoolSize.intValue());
+
+ maxPoolSize = (Integer) mbeanServer.getAttribute(on, "MaximumPoolSize");
+ assertEquals(15, maxPoolSize.intValue());
+
+ id = (String) mbeanServer.getAttribute(on, "Id");
+ assertEquals("threads2", id);
+
+ source = (String) mbeanServer.getAttribute(on, "SourceId");
+ assertEquals("threads", source);
+
+ route = (String) mbeanServer.getAttribute(on, "RouteId");
+ assertEquals("route2", route);
+
+ profile = (String) mbeanServer.getAttribute(on, "ThreadPoolProfileId");
+ assertEquals("custom", profile);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ ThreadPoolProfile profile = new ThreadPoolProfileSupport("custom");
+ profile.setPoolSize(5);
+ profile.setMaxPoolSize(15);
+ profile.setKeepAliveTime(25L);
+ profile.setMaxQueueSize(250);
+ profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
+
+ context.getExecutorServiceStrategy().registerThreadPoolProfile(profile);
+
+ from("direct:start").threads().executorServiceRef("custom").to("mock:result");
+
+ from("direct:foo").threads().executorServiceRef("custom").to("mock:foo");
+ }
+ };
+ }
+
+}
\ No newline at end of file
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/management/DualManagedThreadPoolWithIdTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/DualManagedThreadPoolWithIdTest.java?rev=1050603&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/DualManagedThreadPoolWithIdTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/DualManagedThreadPoolWithIdTest.java Sat Dec 18 09:40:24 2010
@@ -0,0 +1,97 @@
+/**
+ * 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.management;
+
+import java.util.Iterator;
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision: 1005721 $
+ */
+public class DualManagedThreadPoolWithIdTest extends ContextTestSupport {
+
+ @Override
+ protected boolean useJmx() {
+ return true;
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ DefaultManagementNamingStrategy naming = (DefaultManagementNamingStrategy) context.getManagementStrategy().getManagementNamingStrategy();
+ naming.setHostName("localhost");
+ naming.setDomainName("org.apache.camel");
+ return context;
+ }
+
+ public void testManagedThreadPool() throws Exception {
+ MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
+
+ ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=threadpools,name=myThreads(threads)");
+
+ Integer corePoolSize = (Integer) mbeanServer.getAttribute(on, "CorePoolSize");
+ assertEquals(15, corePoolSize.intValue());
+
+ Integer maxPoolSize = (Integer) mbeanServer.getAttribute(on, "MaximumPoolSize");
+ assertEquals(30, maxPoolSize.intValue());
+
+ String id = (String) mbeanServer.getAttribute(on, "Id");
+ assertEquals("myThreads", id);
+
+ String source = (String) mbeanServer.getAttribute(on, "SourceId");
+ assertEquals("threads", source);
+
+ String route = (String) mbeanServer.getAttribute(on, "RouteId");
+ assertEquals("route1", route);
+
+ on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=threadpools,name=myOtherThreads(threads)");
+
+ corePoolSize = (Integer) mbeanServer.getAttribute(on, "CorePoolSize");
+ assertEquals(1, corePoolSize.intValue());
+
+ maxPoolSize = (Integer) mbeanServer.getAttribute(on, "MaximumPoolSize");
+ assertEquals(2, maxPoolSize.intValue());
+
+ id = (String) mbeanServer.getAttribute(on, "Id");
+ assertEquals("myOtherThreads", id);
+
+ source = (String) mbeanServer.getAttribute(on, "SourceId");
+ assertEquals("threads", source);
+
+ route = (String) mbeanServer.getAttribute(on, "RouteId");
+ assertEquals("route2", route);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").threads(15, 30).id("myThreads").to("mock:result");
+
+ from("direct:foo").threads(1, 2).id("myOtherThreads").to("mock:foo");
+ }
+ };
+ }
+
+}
\ No newline at end of file
Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolProfileTest.java (from r1050327, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolProfileTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolProfileTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java&r1=1050327&r2=1050603&rev=1050603&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolProfileTest.java Sat Dec 18 09:40:24 2010
@@ -23,12 +23,15 @@ import javax.management.ObjectName;
import org.apache.camel.CamelContext;
import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ThreadPoolRejectedPolicy;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.ThreadPoolProfileSupport;
+import org.apache.camel.spi.ThreadPoolProfile;
/**
* @version $Revision$
*/
-public class ManagedThreadPoolTest extends ContextTestSupport {
+public class ManagedThreadPoolProfileTest extends ContextTestSupport {
@Override
protected boolean useJmx() {
@@ -43,52 +46,43 @@ public class ManagedThreadPoolTest exten
naming.setDomainName("org.apache.camel");
return context;
}
-
+
public void testManagedThreadPool() throws Exception {
MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
- Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=threadpools,*"), null);
- Iterator<ObjectName> it = set.iterator();
- ObjectName on = null;
- while (it.hasNext()) {
- on = it.next();
- if (on.getCanonicalName().contains("ScheduledThreadPoolExecutor")) {
- continue;
- }
- // find the first non scheduled
- break;
- }
+ ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=threadpools,name=threads1(threads)");
Boolean shutdown = (Boolean) mbeanServer.getAttribute(on, "Shutdown");
assertEquals(false, shutdown.booleanValue());
Integer corePoolSize = (Integer) mbeanServer.getAttribute(on, "CorePoolSize");
- assertEquals(15, corePoolSize.intValue());
+ assertEquals(5, corePoolSize.intValue());
Integer maxPoolSize = (Integer) mbeanServer.getAttribute(on, "MaximumPoolSize");
- assertEquals(30, maxPoolSize.intValue());
+ assertEquals(15, maxPoolSize.intValue());
Integer poolSize = (Integer) mbeanServer.getAttribute(on, "PoolSize");
assertEquals(0, poolSize.intValue());
Long keepAlive = (Long) mbeanServer.getAttribute(on, "KeepAliveTime");
- assertEquals(60, keepAlive.intValue());
+ assertEquals(25, keepAlive.intValue());
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
- // wait a bit to ensure JMX have updated values
- Thread.sleep(2000);
+ String id = (String) mbeanServer.getAttribute(on, "Id");
+ assertEquals("threads1", id);
+
+ String source = (String) mbeanServer.getAttribute(on, "SourceId");
+ assertEquals("threads", source);
- poolSize = (Integer) mbeanServer.getAttribute(on, "PoolSize");
- assertEquals(1, poolSize.intValue());
+ String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
+ assertEquals("route1", routeId);
- Integer largest = (Integer) mbeanServer.getAttribute(on, "LargestPoolSize");
- assertEquals(1, largest.intValue());
+ String profileId = (String) mbeanServer.getAttribute(on, "ThreadPoolProfileId");
+ assertEquals("custom", profileId);
- Long completed = (Long) mbeanServer.getAttribute(on, "CompletedTaskCount");
- assertEquals(1, completed.intValue());
}
@Override
@@ -96,7 +90,16 @@ public class ManagedThreadPoolTest exten
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start").threads(15, 30).to("mock:result");
+ ThreadPoolProfile profile = new ThreadPoolProfileSupport("custom");
+ profile.setPoolSize(5);
+ profile.setMaxPoolSize(15);
+ profile.setKeepAliveTime(25L);
+ profile.setMaxQueueSize(250);
+ profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
+
+ context.getExecutorServiceStrategy().registerThreadPoolProfile(profile);
+
+ from("direct:start").threads().executorServiceRef("custom").to("mock:result");
}
};
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java Sat Dec 18 09:40:24 2010
@@ -16,8 +16,6 @@
*/
package org.apache.camel.management;
-import java.util.Iterator;
-import java.util.Set;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -47,17 +45,7 @@ public class ManagedThreadPoolTest exten
public void testManagedThreadPool() throws Exception {
MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
- Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=threadpools,*"), null);
- Iterator<ObjectName> it = set.iterator();
- ObjectName on = null;
- while (it.hasNext()) {
- on = it.next();
- if (on.getCanonicalName().contains("ScheduledThreadPoolExecutor")) {
- continue;
- }
- // find the first non scheduled
- break;
- }
+ ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=threadpools,name=threads1(threads)");
Boolean shutdown = (Boolean) mbeanServer.getAttribute(on, "Shutdown");
assertEquals(false, shutdown.booleanValue());
Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolWithIdTest.java (from r1050327, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolWithIdTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolWithIdTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java&r1=1050327&r2=1050603&rev=1050603&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedThreadPoolWithIdTest.java Sat Dec 18 09:40:24 2010
@@ -16,8 +16,6 @@
*/
package org.apache.camel.management;
-import java.util.Iterator;
-import java.util.Set;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -28,7 +26,7 @@ import org.apache.camel.builder.RouteBui
/**
* @version $Revision$
*/
-public class ManagedThreadPoolTest extends ContextTestSupport {
+public class ManagedThreadPoolWithIdTest extends ContextTestSupport {
@Override
protected boolean useJmx() {
@@ -47,17 +45,7 @@ public class ManagedThreadPoolTest exten
public void testManagedThreadPool() throws Exception {
MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
- Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=threadpools,*"), null);
- Iterator<ObjectName> it = set.iterator();
- ObjectName on = null;
- while (it.hasNext()) {
- on = it.next();
- if (on.getCanonicalName().contains("ScheduledThreadPoolExecutor")) {
- continue;
- }
- // find the first non scheduled
- break;
- }
+ ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=threadpools,name=myThreads(threads)");
Boolean shutdown = (Boolean) mbeanServer.getAttribute(on, "Shutdown");
assertEquals(false, shutdown.booleanValue());
@@ -78,17 +66,14 @@ public class ManagedThreadPoolTest exten
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
- // wait a bit to ensure JMX have updated values
- Thread.sleep(2000);
-
- poolSize = (Integer) mbeanServer.getAttribute(on, "PoolSize");
- assertEquals(1, poolSize.intValue());
+ String id = (String) mbeanServer.getAttribute(on, "Id");
+ assertEquals("myThreads", id);
- Integer largest = (Integer) mbeanServer.getAttribute(on, "LargestPoolSize");
- assertEquals(1, largest.intValue());
+ String source = (String) mbeanServer.getAttribute(on, "SourceId");
+ assertEquals("threads", source);
- Long completed = (Long) mbeanServer.getAttribute(on, "CompletedTaskCount");
- assertEquals(1, completed.intValue());
+ String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
+ assertEquals("myRoute", routeId);
}
@Override
@@ -96,7 +81,7 @@ public class ManagedThreadPoolTest exten
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start").threads(15, 30).to("mock:result");
+ from("direct:start").routeId("myRoute").threads(15, 30).id("myThreads").to("mock:result");
}
};
}
Modified: camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java (original)
+++ camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java Sat Dec 18 09:40:24 2010
@@ -77,15 +77,15 @@ public class OsgiServiceRegistry impleme
}
public void onComponentAdd(String name, Component component) {
- // Do nothing here
+ // noop
}
public void onComponentRemove(String name, Component component) {
- // Do nothing here
+ // noop
}
public void onContextStart(CamelContext context) {
- // Do nothing here
+ // noop
}
public void onContextStop(CamelContext context) {
@@ -100,39 +100,39 @@ public class OsgiServiceRegistry impleme
}
public void onEndpointAdd(Endpoint endpoint) {
- // Do nothing here
+ // noop
}
public void onEndpointRemove(Endpoint endpoint) {
- // Do nothing here
+ // noop
}
public void onRouteContextCreate(RouteContext routeContext) {
- // Do nothing here
+ // noop
}
public void onRoutesAdd(Collection<Route> routes) {
- // Do nothing here
+ // noop
}
public void onRoutesRemove(Collection<Route> routes) {
- // Do nothing here
+ // noop
}
public void onServiceAdd(CamelContext context, Service service, Route route) {
- // Do nothing here
+ // noop
}
public void onServiceRemove(CamelContext context, Service service, Route route) {
- // Do nothing here
+ // noop
}
public void onErrorHandlerAdd(RouteContext routeContext, Processor processor, ErrorHandlerBuilder errorHandlerBuilder) {
- // Do nothing here
+ // noop
}
- public void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor threadPool) {
- // Do nothing here
+ public void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor threadPoolExecutor,
+ String id, String sourceId, String routeId, String threadPoolProfileId) {
+ // noop
}
-
}
Modified: camel/trunk/components/camel-spring-security/src/main/java/org/apache/camel/component/spring/security/config/SpringSecurityAuthorizationPolicyParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-security/src/main/java/org/apache/camel/component/spring/security/config/SpringSecurityAuthorizationPolicyParser.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/components/camel-spring-security/src/main/java/org/apache/camel/component/spring/security/config/SpringSecurityAuthorizationPolicyParser.java (original)
+++ camel/trunk/components/camel-spring-security/src/main/java/org/apache/camel/component/spring/security/config/SpringSecurityAuthorizationPolicyParser.java Sat Dec 18 09:40:24 2010
@@ -27,7 +27,8 @@ import org.springframework.beans.factory
public class SpringSecurityAuthorizationPolicyParser extends BeanDefinitionParser {
public SpringSecurityAuthorizationPolicyParser() {
- super(SpringSecurityAuthorizationPolicy.class);
+ // true = allow id to be set as there is a setter method on target bean
+ super(SpringSecurityAuthorizationPolicy.class, true);
}
protected boolean isEligibleAttribute(String attributeName) {
@@ -45,9 +46,6 @@ public class SpringSecurityAuthorization
if (ObjectHelper.isNotEmpty(element.getAttribute("authenticationAdapter"))) {
builder.addPropertyReference("authenticationAdapter", element.getAttribute("authenticationAdapter"));
}
- if (ObjectHelper.isNotEmpty(element.getAttribute("id"))) {
- builder.addPropertyValue("id", element.getAttribute("id"));
- }
BeanDefinitionBuilder accessPolicyBuilder = BeanDefinitionBuilder.genericBeanDefinition(
SpringSecurityAccessPolicy.class.getCanonicalName());
Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/BeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/BeanDefinitionParser.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/BeanDefinitionParser.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/BeanDefinitionParser.java Sat Dec 18 09:40:24 2010
@@ -16,15 +16,14 @@
*/
package org.apache.camel.spring.handler;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.core.Conventions;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
/**
* A base class for a parser for a bean.
@@ -35,12 +34,21 @@ import org.springframework.util.StringUt
// as doParse() is final and isEligableAttribute does not allow us to filter out attributes
// with the name "xmlns:"
public class BeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
- private Class type;
-
- public BeanDefinitionParser(Class type) {
+ private final Class type;
+ private final boolean assignId;
+
+ /**
+ * Bean definition parser
+ *
+ * @param type the type, can be null
+ * @param assignId whether to allow assigning id from the id attribute on the type
+ * (there must be getter/setter id on type class).
+ */
+ public BeanDefinitionParser(Class type, boolean assignId) {
this.type = type;
+ this.assignId = assignId;
}
-
+
protected Class getBeanClass(Element element) {
return type;
}
@@ -77,7 +85,14 @@ public class BeanDefinitionParser extend
Attr attribute = (Attr) attributes.item(x);
String name = attribute.getLocalName();
String fullName = attribute.getName();
- if (!fullName.startsWith("xmlns:") && !fullName.equals("xmlns") && isEligibleAttribute(name)) {
+ // assign id as we want them as well
+ if (fullName.equals("id") && assignId) {
+ // for some id is optional as we have convention over configuration
+ if (attribute.getValue() != null) {
+ builder.addPropertyValue("id", attribute.getValue());
+ }
+ // assign other attributes if eligible
+ } else if (!fullName.startsWith("xmlns:") && !fullName.equals("xmlns") && isEligibleAttribute(name)) {
String propertyName = extractPropertyName(name);
Assert.state(StringUtils.hasText(propertyName),
"Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty.");
@@ -117,4 +132,4 @@ public class BeanDefinitionParser extend
protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) {
}
-}
\ No newline at end of file
+}
Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java Sat Dec 18 09:40:24 2010
@@ -67,8 +67,8 @@ import org.springframework.beans.factory
public class CamelNamespaceHandler extends NamespaceHandlerSupport {
private static final String SPRING_NS = "http://camel.apache.org/schema/spring";
private static final Log LOG = LogFactory.getLog(CamelNamespaceHandler.class);
- protected BeanDefinitionParser endpointParser = new BeanDefinitionParser(CamelEndpointFactoryBean.class);
- protected BeanDefinitionParser beanPostProcessorParser = new BeanDefinitionParser(CamelBeanPostProcessor.class);
+ protected BeanDefinitionParser endpointParser = new BeanDefinitionParser(CamelEndpointFactoryBean.class, false);
+ protected BeanDefinitionParser beanPostProcessorParser = new BeanDefinitionParser(CamelBeanPostProcessor.class, false);
protected Set<String> parserElementNames = new HashSet<String>();
private JAXBContext jaxbContext;
private Map<String, BeanDefinitionParser> parserMap = new HashMap<String, BeanDefinitionParser>();
@@ -95,16 +95,16 @@ public class CamelNamespaceHandler exten
// register routeContext parser
registerParser("routeContext", new RouteContextDefinitionParser());
- addBeanDefinitionParser("proxy", CamelProxyFactoryBean.class, true);
- addBeanDefinitionParser("template", CamelProducerTemplateFactoryBean.class, true);
- addBeanDefinitionParser("consumerTemplate", CamelConsumerTemplateFactoryBean.class, true);
- addBeanDefinitionParser("export", CamelServiceExporter.class, true);
- addBeanDefinitionParser("endpoint", CamelEndpointFactoryBean.class, true);
- addBeanDefinitionParser("threadPool", CamelThreadPoolFactoryBean.class, true);
+ addBeanDefinitionParser("proxy", CamelProxyFactoryBean.class, true, false);
+ addBeanDefinitionParser("template", CamelProducerTemplateFactoryBean.class, true, false);
+ addBeanDefinitionParser("consumerTemplate", CamelConsumerTemplateFactoryBean.class, true, false);
+ addBeanDefinitionParser("export", CamelServiceExporter.class, true, false);
+ addBeanDefinitionParser("endpoint", CamelEndpointFactoryBean.class, true, false);
+ addBeanDefinitionParser("threadPool", CamelThreadPoolFactoryBean.class, true, true);
// jmx agent and property placeholder cannot be used outside of the camel context
- addBeanDefinitionParser("jmxAgent", CamelJMXAgentDefinition.class, false);
- addBeanDefinitionParser("propertyPlaceholder", CamelPropertyPlaceholderDefinition.class, false);
+ addBeanDefinitionParser("jmxAgent", CamelJMXAgentDefinition.class, false, false);
+ addBeanDefinitionParser("propertyPlaceholder", CamelPropertyPlaceholderDefinition.class, false, false);
// errorhandler could be the sub element of camelContext or defined outside camelContext
BeanDefinitionParser errorHandlerParser = new ErrorHandlerDefinitionParser();
@@ -137,8 +137,8 @@ public class CamelNamespaceHandler exten
registerParser("camelContext", new CamelContextBeanDefinitionParser(cl));
}
- private void addBeanDefinitionParser(String elementName, Class<?> type, boolean register) {
- BeanDefinitionParser parser = new BeanDefinitionParser(type);
+ private void addBeanDefinitionParser(String elementName, Class<?> type, boolean register, boolean assignId) {
+ BeanDefinitionParser parser = new BeanDefinitionParser(type, assignId);
if (register) {
registerParser(elementName, parser);
}
@@ -203,7 +203,7 @@ public class CamelNamespaceHandler exten
protected class RouteContextDefinitionParser extends BeanDefinitionParser {
public RouteContextDefinitionParser() {
- super(CamelRouteContextFactoryBean.class);
+ super(CamelRouteContextFactoryBean.class, false);
}
@Override
@@ -231,7 +231,7 @@ public class CamelNamespaceHandler exten
protected class CamelContextBeanDefinitionParser extends BeanDefinitionParser {
public CamelContextBeanDefinitionParser(Class type) {
- super(type);
+ super(type, false);
}
@Override
Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java Sat Dec 18 09:40:24 2010
@@ -39,7 +39,7 @@ public class ErrorHandlerDefinitionParse
public ErrorHandlerDefinitionParser() {
// need to override the default
- super(null);
+ super(null, false);
}
protected Class getBeanClass(Element element) {
@@ -114,8 +114,9 @@ public class ErrorHandlerDefinitionParse
}
protected class RedeliveryPolicyDefinitionParser extends BeanDefinitionParser {
+
public RedeliveryPolicyDefinitionParser(Class type) {
- super(type);
+ super(type, false);
}
protected boolean shouldGenerateId() {
Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java?rev=1050603&r1=1050602&r2=1050603&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java Sat Dec 18 09:40:24 2010
@@ -72,6 +72,7 @@ public class DummyLifecycleStrategy impl
public void onRoutesAdd(Collection<Route> routes) {
}
- public void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor threadPool) {
+ public void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor threadPool, String id,
+ String sourceId, String routeId, String threadPoolProfileId) {
}
}
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/DualSpringManagedThreadsThreadPoolTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/DualSpringManagedThreadsThreadPoolTest.java?rev=1050603&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/DualSpringManagedThreadsThreadPoolTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/DualSpringManagedThreadsThreadPoolTest.java Sat Dec 18 09:40:24 2010
@@ -0,0 +1,79 @@
+/**
+ * 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.spring.processor;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class DualSpringManagedThreadsThreadPoolTest extends SpringTestSupport {
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/spring/processor/SpringDualManagedThreadsThreadPoolTest.xml");
+ }
+
+ public void testDualManagedThreadPool() throws Exception {
+ MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
+
+ ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=threadpools,name=myPool");
+
+ Integer corePoolSize = (Integer) mbeanServer.getAttribute(on, "CorePoolSize");
+ assertEquals(2, corePoolSize.intValue());
+
+ Integer maxPoolSize = (Integer) mbeanServer.getAttribute(on, "MaximumPoolSize");
+ assertEquals(4, maxPoolSize.intValue());
+
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ template.sendBody("direct:start", "Hello World");
+ template.sendBody("direct:foo", "Bye World");
+ assertMockEndpointsSatisfied();
+
+ String id = (String) mbeanServer.getAttribute(on, "Id");
+ assertEquals("myPool", id);
+
+ // no source or route as its a shared thread pool
+ String source = (String) mbeanServer.getAttribute(on, "SourceId");
+ assertEquals(null, source);
+
+ String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
+ assertEquals(null, routeId);
+
+ on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=threadpools,name=myOtherPool");
+
+ corePoolSize = (Integer) mbeanServer.getAttribute(on, "CorePoolSize");
+ assertEquals(7, corePoolSize.intValue());
+
+ maxPoolSize = (Integer) mbeanServer.getAttribute(on, "MaximumPoolSize");
+ assertEquals(9, maxPoolSize.intValue());
+
+ id = (String) mbeanServer.getAttribute(on, "Id");
+ assertEquals("myOtherPool", id);
+
+ // no source or route as its a shared thread pool
+ source = (String) mbeanServer.getAttribute(on, "SourceId");
+ assertEquals(null, source);
+
+ routeId = (String) mbeanServer.getAttribute(on, "RouteId");
+ assertEquals(null, routeId);
+ }
+
+}
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringManagedThreadsThreadPoolTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringManagedThreadsThreadPoolTest.java?rev=1050603&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringManagedThreadsThreadPoolTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringManagedThreadsThreadPoolTest.java Sat Dec 18 09:40:24 2010
@@ -0,0 +1,59 @@
+/**
+ * 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.spring.processor;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringManagedThreadsThreadPoolTest extends SpringTestSupport {
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/spring/processor/SpringManagedThreadsThreadPoolTest.xml");
+ }
+
+ public void testManagedThreadPool() throws Exception {
+ MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
+
+ ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=threadpools,name=myPool");
+
+ Integer corePoolSize = (Integer) mbeanServer.getAttribute(on, "CorePoolSize");
+ assertEquals(2, corePoolSize.intValue());
+
+ Integer maxPoolSize = (Integer) mbeanServer.getAttribute(on, "MaximumPoolSize");
+ assertEquals(4, maxPoolSize.intValue());
+
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ template.sendBody("direct:start", "Hello World");
+ assertMockEndpointsSatisfied();
+
+ String id = (String) mbeanServer.getAttribute(on, "Id");
+ assertEquals("myPool", id);
+
+ // no source or route as its a shared thread pool
+ String source = (String) mbeanServer.getAttribute(on, "SourceId");
+ assertEquals(null, source);
+
+ String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
+ assertEquals(null, routeId);
+ }
+
+}
Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDualManagedThreadsThreadPoolTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDualManagedThreadsThreadPoolTest.xml?rev=1050603&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDualManagedThreadsThreadPoolTest.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDualManagedThreadsThreadPoolTest.xml Sat Dec 18 09:40:24 2010
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <bean id="naming" class="org.apache.camel.management.DefaultManagementNamingStrategy">
+ <property name="hostName" value="localhost"/>
+ <property name="domainName" value="org.apache.camel"/>
+ </bean>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <!-- enable JMX -->
+ <jmxAgent id="jmx"/>
+
+ <!-- create thread pools with id -->
+ <threadPool id="myPool" poolSize="2" maxPoolSize="4" threadName="myThreads"/>
+ <threadPool id="myOtherPool" poolSize="7" maxPoolSize="9" threadName="myOtherThreads"/>
+
+ <route>
+ <from uri="direct:start"/>
+ <threads executorServiceRef="myPool">
+ <to uri="mock:result"/>
+ </threads>
+ </route>
+
+ <route>
+ <from uri="direct:foo"/>
+ <threads executorServiceRef="myOtherPool">
+ <to uri="mock:foo"/>
+ </threads>
+ </route>
+
+ </camelContext>
+
+</beans>
Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringManagedThreadsThreadPoolTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringManagedThreadsThreadPoolTest.xml?rev=1050603&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringManagedThreadsThreadPoolTest.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringManagedThreadsThreadPoolTest.xml Sat Dec 18 09:40:24 2010
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <bean id="naming" class="org.apache.camel.management.DefaultManagementNamingStrategy">
+ <property name="hostName" value="localhost"/>
+ <property name="domainName" value="org.apache.camel"/>
+ </bean>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <!-- enable JMX -->
+ <jmxAgent id="jmx"/>
+
+ <!-- create thread pool with id -->
+ <threadPool id="myPool" poolSize="2" maxPoolSize="4" threadName="myThreads"/>
+
+ <route>
+ <from uri="direct:start"/>
+ <threads executorServiceRef="myPool">
+ <to uri="mock:result"/>
+ </threads>
+ </route>
+
+ </camelContext>
+
+</beans>