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 2013/04/15 10:34:03 UTC
svn commit: r1467896 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/
camel-core/src/main/java/org/apache/camel/api/management/mbean/
camel-core/src/main/java/org/apache/camel/impl/
camel-core/src/main/java/org/apache/camel/impl/converter/...
Author: davsclaus
Date: Mon Apr 15 08:34:03 2013
New Revision: 1467896
URL: http://svn.apache.org/r1467896
Log:
CAMEL-6282: TypeConverterRegistry - Allow to enable or disable utilization statistics. Is disabled by default.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryStatisticsEnabledTest.java
- copied, changed from r1467877, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/impl/SpringTypeConverterRegistryStatisticsEnabledTest.java
- copied, changed from r1467882, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/impl/SpringRefDataFormatTest.java
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/SpringTypeConverterRegistryStatisticsEnabledTest.xml
- copied, changed from r1467882, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/SpringRefDataFormatTest.xml
camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/TypeConverterRegistryStatisticsEnabledTest.java
camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/typeConverterRegistryStatisticsEnabledTest.xml
- copied, changed from r1467882, camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/threadNamePatternTest.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTypeConverterRegistryMBean.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTypeConverterRegistry.java
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=1467896&r1=1467895&r2=1467896&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Mon Apr 15 08:34:03 2013
@@ -1129,6 +1129,30 @@ public interface CamelContext extends Su
void setLazyLoadTypeConverters(Boolean lazyLoadTypeConverters);
/**
+ * Whether or not type converter statistics is enabled.
+ * <p/>
+ * By default the type converter utilization statistics is disabled.
+ * <b>Notice:</b> If enabled then there is a slight performance impact under very heavy load.
+ *
+ * @return <tt>true</tt> if enabled, <tt>false</tt> if disabled (default).
+ */
+ Boolean isTypeConverterStatisticsEnabled();
+
+ /**
+ * Sets whether or not type converter statistics is enabled.
+ * <p/>
+ * By default the type converter utilization statistics is disabled.
+ * <b>Notice:</b> If enabled then there is a slight performance impact under very heavy load.
+ * <p/>
+ * You can enable/disable the statistics at runtime using the
+ * {@link org.apache.camel.spi.TypeConverterRegistry#getStatistics()#setTypeConverterStatisticsEnabled(Boolean)} method,
+ * or from JMX on the {@link org.apache.camel.api.management.mbean.ManagedTypeConverterRegistryMBean} mbean.
+ *
+ * @param typeConverterStatisticsEnabled <tt>true</tt> to enable, <tt>false</tt> to disable
+ */
+ void setTypeConverterStatisticsEnabled(Boolean typeConverterStatisticsEnabled);
+
+ /**
* Whether or not <a href="http://www.slf4j.org/api/org/slf4j/MDC.html">MDC</a> logging is being enabled.
*
* @return <tt>true</tt> if MDC logging is enabled
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTypeConverterRegistryMBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTypeConverterRegistryMBean.java?rev=1467896&r1=1467895&r2=1467896&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTypeConverterRegistryMBean.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTypeConverterRegistryMBean.java Mon Apr 15 08:34:03 2013
@@ -25,23 +25,24 @@ import org.apache.camel.api.management.M
public interface ManagedTypeConverterRegistryMBean extends ManagedServiceMBean {
@ManagedAttribute(description = "Number of type conversion attempts")
- @Deprecated
long getAttemptCounter();
@ManagedAttribute(description = "Number of type conversion hits (successful conversions)")
- @Deprecated
long getHitCounter();
@ManagedAttribute(description = "Number of type conversion misses (no suitable type converter)")
- @Deprecated
long getMissCounter();
@ManagedAttribute(description = "Number of type conversion failures (failed conversions)")
- @Deprecated
long getFailedCounter();
@ManagedOperation(description = "Resets the type conversion counters")
- @Deprecated
void resetTypeConversionCounters();
+ @ManagedAttribute(description = "Utilization statistics enabled")
+ boolean isStatisticsEnabled();
+
+ @ManagedAttribute(description = "Utilization statistics enabled")
+ void setStatisticsEnabled(boolean statisticsEnabled);
+
}
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=1467896&r1=1467895&r2=1467896&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 Mon Apr 15 08:34:03 2013
@@ -175,6 +175,7 @@ public class DefaultCamelContext extends
private Boolean handleFault = Boolean.FALSE;
private Boolean disableJMX = Boolean.FALSE;
private Boolean lazyLoadTypeConverters = Boolean.FALSE;
+ private Boolean typeConverterStatisticsEnabled = Boolean.FALSE;
private Boolean useMDCLogging = Boolean.FALSE;
private Boolean useBreadcrumb = Boolean.TRUE;
private Long delay;
@@ -2152,6 +2153,10 @@ public class DefaultCamelContext extends
getLanguageResolver();
getTypeConverterRegistry();
getTypeConverter();
+
+ if (isTypeConverterStatisticsEnabled() != null) {
+ getTypeConverterRegistry().getStatistics().setStatisticsEnabled(isTypeConverterStatisticsEnabled());
+ }
}
/**
@@ -2175,6 +2180,7 @@ public class DefaultCamelContext extends
answer = new DefaultTypeConverter(packageScanClassResolver, getInjector(), getDefaultFactoryFinder());
}
setTypeConverterRegistry(answer);
+ answer.getStatistics().setStatisticsEnabled(isTypeConverterStatisticsEnabled());
return answer;
}
@@ -2422,6 +2428,14 @@ public class DefaultCamelContext extends
this.lazyLoadTypeConverters = lazyLoadTypeConverters;
}
+ public Boolean isTypeConverterStatisticsEnabled() {
+ return typeConverterStatisticsEnabled != null && typeConverterStatisticsEnabled;
+ }
+
+ public void setTypeConverterStatisticsEnabled(Boolean typeConverterStatisticsEnabled) {
+ this.typeConverterStatisticsEnabled = typeConverterStatisticsEnabled;
+ }
+
public Boolean isUseMDCLogging() {
return useMDCLogging != null && useMDCLogging;
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java?rev=1467896&r1=1467895&r2=1467896&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java Mon Apr 15 08:34:03 2013
@@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHa
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.Exchange;
@@ -63,6 +64,10 @@ public abstract class BaseTypeConverterR
protected Injector injector;
protected final FactoryFinder factoryFinder;
protected final Statistics statistics = new UtilizationStatistics();
+ protected final AtomicLong attemptCounter = new AtomicLong();
+ protected final AtomicLong missCounter = new AtomicLong();
+ protected final AtomicLong hitCounter = new AtomicLong();
+ protected final AtomicLong failedCounter = new AtomicLong();
public BaseTypeConverterRegistry(PackageScanClassResolver resolver, Injector injector, FactoryFinder factoryFinder) {
this.resolver = resolver;
@@ -102,8 +107,14 @@ public abstract class BaseTypeConverterR
Object answer;
try {
+ if (statistics.isStatisticsEnabled()) {
+ attemptCounter.incrementAndGet();
+ }
answer = doConvertTo(type, exchange, value, false);
} catch (Exception e) {
+ if (statistics.isStatisticsEnabled()) {
+ failedCounter.incrementAndGet();
+ }
// if its a ExecutionException then we have rethrow it as its not due to failed conversion
// this is special for FutureTypeConverter
boolean execution = ObjectHelper.getException(ExecutionException.class, e) != null
@@ -120,9 +131,15 @@ public abstract class BaseTypeConverterR
}
}
if (answer == Void.TYPE) {
+ if (statistics.isStatisticsEnabled()) {
+ missCounter.incrementAndGet();
+ }
// Could not find suitable conversion
return null;
} else {
+ if (statistics.isStatisticsEnabled()) {
+ hitCounter.incrementAndGet();
+ }
return (T) answer;
}
}
@@ -141,8 +158,14 @@ public abstract class BaseTypeConverterR
Object answer;
try {
+ if (statistics.isStatisticsEnabled()) {
+ attemptCounter.incrementAndGet();
+ }
answer = doConvertTo(type, exchange, value, false);
} catch (Exception e) {
+ if (statistics.isStatisticsEnabled()) {
+ failedCounter.incrementAndGet();
+ }
// error occurred during type conversion
if (e instanceof TypeConversionException) {
throw (TypeConversionException) e;
@@ -151,9 +174,15 @@ public abstract class BaseTypeConverterR
}
}
if (answer == Void.TYPE || value == null) {
+ if (statistics.isStatisticsEnabled()) {
+ missCounter.incrementAndGet();
+ }
// Could not find suitable conversion
throw new NoTypeConversionAvailableException(value, type);
} else {
+ if (statistics.isStatisticsEnabled()) {
+ hitCounter.incrementAndGet();
+ }
return (T) answer;
}
}
@@ -172,14 +201,26 @@ public abstract class BaseTypeConverterR
Object answer;
try {
+ if (statistics.isStatisticsEnabled()) {
+ attemptCounter.incrementAndGet();
+ }
answer = doConvertTo(type, exchange, value, true);
} catch (Exception e) {
+ if (statistics.isStatisticsEnabled()) {
+ failedCounter.incrementAndGet();
+ }
return null;
}
if (answer == Void.TYPE) {
// Could not find suitable conversion
+ if (statistics.isStatisticsEnabled()) {
+ missCounter.incrementAndGet();
+ }
return null;
} else {
+ if (statistics.isStatisticsEnabled()) {
+ hitCounter.incrementAndGet();
+ }
return (T) answer;
}
}
@@ -497,6 +538,13 @@ public abstract class BaseTypeConverterR
@Override
protected void doStop() throws Exception {
+ // log utilization statistics when stopping, including mappings
+ if (statistics.isStatisticsEnabled()) {
+ String info = statistics.toString();
+ info += String.format(" mappings[total=%s, misses=%s]", typeMappings.size(), misses.size());
+ log.info(info);
+ }
+
typeMappings.clear();
misses.clear();
statistics.reset();
@@ -505,32 +553,46 @@ public abstract class BaseTypeConverterR
/**
* Represents utilization statistics
*/
- @Deprecated
private final class UtilizationStatistics implements Statistics {
+ private boolean statisticsEnabled;
+
@Override
public long getAttemptCounter() {
- return 0;
+ return attemptCounter.get();
}
@Override
public long getHitCounter() {
- return 0;
+ return hitCounter.get();
}
@Override
public long getMissCounter() {
- return 0;
+ return missCounter.get();
}
@Override
public long getFailedCounter() {
- return 0;
+ return failedCounter.get();
}
@Override
public void reset() {
- // noop
+ attemptCounter.set(0);
+ hitCounter.set(0);
+ missCounter.set(0);
+ failedCounter.set(0);
+ }
+
+ @Override
+ public boolean isStatisticsEnabled() {
+ return statisticsEnabled;
+ }
+
+ @Override
+ public void setStatisticsEnabled(boolean statisticsEnabled) {
+ this.statisticsEnabled = statisticsEnabled;
}
@Override
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTypeConverterRegistry.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTypeConverterRegistry.java?rev=1467896&r1=1467895&r2=1467896&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTypeConverterRegistry.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTypeConverterRegistry.java Mon Apr 15 08:34:03 2013
@@ -57,4 +57,12 @@ public class ManagedTypeConverterRegistr
public void resetTypeConversionCounters() {
registry.getStatistics().reset();
}
+
+ public boolean isStatisticsEnabled() {
+ return registry.getStatistics().isStatisticsEnabled();
+ }
+
+ public void setStatisticsEnabled(boolean statisticsEnabled) {
+ registry.getStatistics().setStatisticsEnabled(statisticsEnabled);
+ }
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java?rev=1467896&r1=1467895&r2=1467896&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java Mon Apr 15 08:34:03 2013
@@ -21,6 +21,9 @@ import org.apache.camel.TypeConverter;
/**
* Registry for type converters.
+ * <p/>
+ * The utilization {@link Statistics} is by default disabled, as it has a slight performance impact under very high
+ * concurrent load. The statistics can be enabled using {@link Statistics#setStatisticsEnabled(boolean)} method.
*
* @version
*/
@@ -28,9 +31,7 @@ public interface TypeConverterRegistry e
/**
* Utilization statistics of the this registry.
- * @deprecated the statistics has been disabled and the API will be removed in Camel 2.12
*/
- @Deprecated
interface Statistics {
/**
@@ -57,6 +58,18 @@ public interface TypeConverterRegistry e
* Reset the counters
*/
void reset();
+
+ /**
+ * Whether statistics is enabled.
+ */
+ boolean isStatisticsEnabled();
+
+ /**
+ * Sets whether statistics is enabled.
+ *
+ * @param statisticsEnabled <tt>true</tt> to enable
+ */
+ void setStatisticsEnabled(boolean statisticsEnabled);
}
/**
@@ -103,9 +116,7 @@ public interface TypeConverterRegistry e
* Gets the utilization statistics of this type converter registry
*
* @return the utilization statistics
- * @deprecated the statistics has been disabled and the API will be removed in Camel 2.12
*/
- @Deprecated
Statistics getStatistics();
}
Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryStatisticsEnabledTest.java (from r1467877, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryStatisticsEnabledTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryStatisticsEnabledTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java&r1=1467877&r2=1467896&rev=1467896&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryStatisticsEnabledTest.java Mon Apr 15 08:34:03 2013
@@ -14,18 +14,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.management;
-
-import java.util.Set;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
+package org.apache.camel.impl;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.TypeConverterRegistry;
/**
* @version
*/
-public class ManagedTypeConverterRegistryTest extends ManagementTestSupport {
+public class TypeConverterRegistryStatisticsEnabledTest extends ContextTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ context.setTypeConverterStatisticsEnabled(true);
+ return context;
+ }
public void testTypeConverterRegistry() throws Exception {
getMockEndpoint("mock:a").expectedMessageCount(2);
@@ -35,20 +41,34 @@ public class ManagedTypeConverterRegistr
assertMockEndpointsSatisfied();
- MBeanServer mbeanServer = getMBeanServer();
+ TypeConverterRegistry reg = context.getTypeConverterRegistry();
+ assertTrue("Should be enabled", reg.getStatistics().isStatisticsEnabled());
- ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=services,*");
-
- // number of services
- Set<ObjectName> names = mbeanServer.queryNames(on, null);
- ObjectName name = null;
- for (ObjectName service : names) {
- if (service.toString().contains("DefaultTypeConverter")) {
- name = service;
- break;
- }
+ Long failed = reg.getStatistics().getFailedCounter();
+ assertEquals(0, failed.intValue());
+ Long miss = reg.getStatistics().getMissCounter();
+ assertEquals(0, miss.intValue());
+
+ try {
+ template.sendBody("direct:start", "foo");
+ fail("Should have thrown exception");
+ } catch (Exception e) {
+ // expected
}
- assertNotNull("Cannot find DefaultTypeConverter", name);
+
+ // should now have a failed
+ failed = reg.getStatistics().getFailedCounter();
+ assertEquals(1, failed.intValue());
+ miss = reg.getStatistics().getMissCounter();
+ assertEquals(0, miss.intValue());
+
+ // reset
+ reg.getStatistics().reset();
+
+ failed = reg.getStatistics().getFailedCounter();
+ assertEquals(0, failed.intValue());
+ miss = reg.getStatistics().getMissCounter();
+ assertEquals(0, miss.intValue());
}
@Override
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java?rev=1467896&r1=1467895&r2=1467896&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java Mon Apr 15 08:34:03 2013
@@ -17,6 +17,7 @@
package org.apache.camel.management;
import java.util.Set;
+import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -49,6 +50,39 @@ public class ManagedTypeConverterRegistr
}
}
assertNotNull("Cannot find DefaultTypeConverter", name);
+
+ // is disabled by default
+ Boolean enabled = (Boolean) mbeanServer.getAttribute(name, "StatisticsEnabled");
+ assertEquals(Boolean.FALSE, enabled);
+
+ // need to enable statistics
+ mbeanServer.setAttribute(name, new Attribute("StatisticsEnabled", Boolean.TRUE));
+
+ Long failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
+ assertEquals(0, failed.intValue());
+ Long miss = (Long) mbeanServer.getAttribute(name, "MissCounter");
+ assertEquals(0, miss.intValue());
+
+ try {
+ template.sendBody("direct:start", "foo");
+ fail("Should have thrown exception");
+ } catch (Exception e) {
+ // expected
+ }
+
+ // should now have a failed
+ failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
+ assertEquals(1, failed.intValue());
+ miss = (Long) mbeanServer.getAttribute(name, "MissCounter");
+ assertEquals(0, miss.intValue());
+
+ // reset
+ mbeanServer.invoke(name, "resetTypeConversionCounters", null, null);
+
+ failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
+ assertEquals(0, failed.intValue());
+ miss = (Long) mbeanServer.getAttribute(name, "MissCounter");
+ assertEquals(0, miss.intValue());
}
@Override
Modified: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java?rev=1467896&r1=1467895&r2=1467896&view=diff
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java (original)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java Mon Apr 15 08:34:03 2013
@@ -105,6 +105,8 @@ public class CamelContextFactoryBean ext
@XmlAttribute(required = false)
@Deprecated
private Boolean lazyLoadTypeConverters;
+ @XmlAttribute(required = false)
+ private Boolean typeConverterStatisticsEnabled;
@XmlElement(name = "properties", required = false)
private PropertiesDefinition properties;
@XmlElement(name = "propertyPlaceholder", type = CamelPropertyPlaceholderDefinition.class, required = false)
@@ -351,6 +353,14 @@ public class CamelContextFactoryBean ext
this.lazyLoadTypeConverters = lazyLoadTypeConverters;
}
+ public Boolean getTypeConverterStatisticsEnabled() {
+ return typeConverterStatisticsEnabled;
+ }
+
+ public void setTypeConverterStatisticsEnabled(Boolean typeConverterStatisticsEnabled) {
+ this.typeConverterStatisticsEnabled = typeConverterStatisticsEnabled;
+ }
+
public ShutdownRoute getShutdownRoute() {
return shutdownRoute;
}
Modified: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java?rev=1467896&r1=1467895&r2=1467896&view=diff
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java (original)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java Mon Apr 15 08:34:03 2013
@@ -490,6 +490,8 @@ public abstract class AbstractCamelConte
@Deprecated
public abstract Boolean getLazyLoadTypeConverters();
+ public abstract Boolean getTypeConverterStatisticsEnabled();
+
public abstract CamelJMXAgentDefinition getCamelJMXAgent();
public abstract List<RouteBuilderDefinition> getBuilderRefs();
@@ -561,6 +563,9 @@ public abstract class AbstractCamelConte
if (getDataFormats() != null) {
ctx.setDataFormats(getDataFormats().asMap());
}
+ if (getTypeConverterStatisticsEnabled() != null) {
+ ctx.setTypeConverterStatisticsEnabled(getTypeConverterStatisticsEnabled());
+ }
}
protected void initThreadPoolProfiles(T context) throws Exception {
Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=1467896&r1=1467895&r2=1467896&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Mon Apr 15 08:34:03 2013
@@ -112,6 +112,8 @@ public class CamelContextFactoryBean ext
@XmlAttribute(required = false)
@Deprecated
private Boolean lazyLoadTypeConverters;
+ @XmlAttribute(required = false)
+ private Boolean typeConverterStatisticsEnabled;
@XmlElement(name = "properties", required = false)
private PropertiesDefinition properties;
@XmlElement(name = "propertyPlaceholder", type = CamelPropertyPlaceholderDefinition.class, required = false)
@@ -539,6 +541,14 @@ public class CamelContextFactoryBean ext
this.lazyLoadTypeConverters = lazyLoadTypeConverters;
}
+ public Boolean getTypeConverterStatisticsEnabled() {
+ return typeConverterStatisticsEnabled;
+ }
+
+ public void setTypeConverterStatisticsEnabled(Boolean typeConverterStatisticsEnabled) {
+ this.typeConverterStatisticsEnabled = typeConverterStatisticsEnabled;
+ }
+
public CamelJMXAgentDefinition getCamelJMXAgent() {
return camelJMXAgent;
}
Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/impl/SpringTypeConverterRegistryStatisticsEnabledTest.java (from r1467882, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/impl/SpringRefDataFormatTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/impl/SpringTypeConverterRegistryStatisticsEnabledTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/impl/SpringTypeConverterRegistryStatisticsEnabledTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/impl/SpringRefDataFormatTest.java&r1=1467882&r2=1467896&rev=1467896&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/impl/SpringRefDataFormatTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/impl/SpringTypeConverterRegistryStatisticsEnabledTest.java Mon Apr 15 08:34:03 2013
@@ -17,17 +17,17 @@
package org.apache.camel.spring.impl;
import org.apache.camel.CamelContext;
-import org.apache.camel.impl.RefDataFormatTest;
+import org.apache.camel.impl.TypeConverterRegistryStatisticsEnabledTest;
import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
/**
*
*/
-public class SpringRefDataFormatTest extends RefDataFormatTest {
+public class SpringTypeConverterRegistryStatisticsEnabledTest extends TypeConverterRegistryStatisticsEnabledTest {
protected CamelContext createCamelContext() throws Exception {
- return createSpringCamelContext(this, "org/apache/camel/spring/impl/SpringRefDataFormatTest.xml");
+ return createSpringCamelContext(this, "org/apache/camel/spring/impl/SpringTypeConverterRegistryStatisticsEnabledTest.xml");
}
}
Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/SpringTypeConverterRegistryStatisticsEnabledTest.xml (from r1467882, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/SpringRefDataFormatTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/SpringTypeConverterRegistryStatisticsEnabledTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/SpringTypeConverterRegistryStatisticsEnabledTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/SpringRefDataFormatTest.xml&r1=1467882&r2=1467896&rev=1467896&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/SpringRefDataFormatTest.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/SpringTypeConverterRegistryStatisticsEnabledTest.xml Mon Apr 15 08:34:03 2013
@@ -23,27 +23,13 @@
">
<!-- START SNIPPET: e1 -->
- <!-- this is our custom data format implementation -->
- <bean id="reverse" class="org.apache.camel.impl.RefDataFormatTest$MyReverseDataFormat"/>
-
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:a"/>
- <marshal>
- <!-- refer to my custom data format -->
- <custom ref="reverse"/>
- </marshal>
+ <!-- enable type converter statistics by setting the attribute to true -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring" typeConverterStatisticsEnabled="true">
+ <route id="foo">
+ <from uri="direct:start"/>
+ <convertBodyTo type="int"/>
<to uri="mock:a"/>
</route>
-
- <route>
- <from uri="direct:b"/>
- <unmarshal>
- <!-- refer to my custom data format -->
- <custom ref="reverse"/>
- </unmarshal>
- <to uri="mock:b"/>
- </route>
</camelContext>
<!-- END SNIPPET: e1 -->
Added: camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/TypeConverterRegistryStatisticsEnabledTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/TypeConverterRegistryStatisticsEnabledTest.java?rev=1467896&view=auto
==============================================================================
--- camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/TypeConverterRegistryStatisticsEnabledTest.java (added)
+++ camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/TypeConverterRegistryStatisticsEnabledTest.java Mon Apr 15 08:34:03 2013
@@ -0,0 +1,68 @@
+/**
+ * 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.test.blueprint;
+
+import org.apache.camel.spi.TypeConverterRegistry;
+import org.junit.Test;
+
+public class TypeConverterRegistryStatisticsEnabledTest extends CamelBlueprintTestSupport {
+
+ @Override
+ protected String getBlueprintDescriptor() {
+ return "org/apache/camel/test/blueprint/typeConverterRegistryStatisticsEnabledTest.xml";
+ }
+
+ @Test
+ public void testTypeConverterRegistry() throws Exception {
+ getMockEndpoint("mock:a").expectedMessageCount(2);
+
+ template.sendBody("direct:start", "3");
+ template.sendBody("direct:start", "7");
+
+ assertMockEndpointsSatisfied();
+
+ TypeConverterRegistry reg = context.getTypeConverterRegistry();
+ assertTrue("Should be enabled", reg.getStatistics().isStatisticsEnabled());
+
+ Long failed = reg.getStatistics().getFailedCounter();
+ assertEquals(0, failed.intValue());
+ Long miss = reg.getStatistics().getMissCounter();
+ assertEquals(0, miss.intValue());
+
+ try {
+ template.sendBody("direct:start", "foo");
+ fail("Should have thrown exception");
+ } catch (Exception e) {
+ // expected
+ }
+
+ // should now have a failed
+ failed = reg.getStatistics().getFailedCounter();
+ assertEquals(1, failed.intValue());
+ miss = reg.getStatistics().getMissCounter();
+ assertEquals(0, miss.intValue());
+
+ // reset
+ reg.getStatistics().reset();
+
+ failed = reg.getStatistics().getFailedCounter();
+ assertEquals(0, failed.intValue());
+ miss = reg.getStatistics().getMissCounter();
+ assertEquals(0, miss.intValue());
+ }
+
+}
Copied: camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/typeConverterRegistryStatisticsEnabledTest.xml (from r1467882, camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/threadNamePatternTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/typeConverterRegistryStatisticsEnabledTest.xml?p2=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/typeConverterRegistryStatisticsEnabledTest.xml&p1=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/threadNamePatternTest.xml&r1=1467882&r2=1467896&rev=1467896&view=diff
==============================================================================
--- camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/threadNamePatternTest.xml (original)
+++ camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/typeConverterRegistryStatisticsEnabledTest.xml Mon Apr 15 08:34:03 2013
@@ -20,12 +20,15 @@
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
- <camelContext xmlns="http://camel.apache.org/schema/blueprint" threadNamePattern="Riding the thread #counter#">
- <route>
- <from uri="seda:start"/>
- <to uri="log:result"/>
- <to uri="mock:result"/>
- </route>
- </camelContext>
+ <!-- START SNIPPET: e1 -->
+ <!-- enable type converter statistics by setting the attribute to true -->
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint" typeConverterStatisticsEnabled="true">
+ <route id="foo">
+ <from uri="direct:start"/>
+ <convertBodyTo type="int"/>
+ <to uri="mock:a"/>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: e1 -->
</blueprint>