Skip to content

Commit

Permalink
[maven-release-plugin] copy for tag camel-2.11.0
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/camel/tags/camel-2.11.0@1468764 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Christian Mueller committed Apr 17, 2013
2 parents 2e7a721 + a1acd34 commit 99b5784
Show file tree
Hide file tree
Showing 110 changed files with 1,071 additions and 635 deletions.
24 changes: 24 additions & 0 deletions camel-core/src/main/java/org/apache/camel/CamelContext.java
Expand Up @@ -1128,6 +1128,30 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
@Deprecated
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.
*
Expand Down
Expand Up @@ -39,4 +39,10 @@ public interface ManagedTypeConverterRegistryMBean extends ManagedServiceMBean {
@ManagedOperation(description = "Resets the type conversion counters")
void resetTypeConversionCounters();

@ManagedAttribute(description = "Utilization statistics enabled")
boolean isStatisticsEnabled();

@ManagedAttribute(description = "Utilization statistics enabled")
void setStatisticsEnabled(boolean statisticsEnabled);

}
Expand Up @@ -500,7 +500,7 @@ protected MethodInfo chooseMethod(Object pojo, Exchange exchange, String name) t
if (noParameters && localOperationsWithNoBody.size() == 1) {
// if there was a method name configured and it has no parameters, then use the method with no body (eg no parameters)
return localOperationsWithNoBody.get(0);
} else if (localOperationsWithBody.size() == 1) {
} else if (!noParameters && localOperationsWithBody.size() == 1) {
// if there is one method with body then use that one
return localOperationsWithBody.get(0);
}
Expand Down Expand Up @@ -874,9 +874,15 @@ private boolean matchMethod(Method method, String methodName) {
return false;
}

// is it a method with no parameters
boolean noParameters = methodName.endsWith("()");
if (noParameters) {
return method.getParameterTypes().length == 0;
}

// match qualifier types which is used to select among overloaded methods
String types = ObjectHelper.between(methodName, "(", ")");
if (types != null) {
if (ObjectHelper.isNotEmpty(types)) {
// we must qualify based on types to match method
String[] parameters = StringQuoteHelper.splitSafeQuote(types, ',');
Iterator<?> it = ObjectHelper.createIterator(parameters);
Expand Down
Expand Up @@ -426,8 +426,8 @@ public <T> T evaluate(Exchange exchange, Class<T> type) {
if (methodParameters != null) {
// split the parameters safely separated by comma, but beware that we can have
// quoted parameters which contains comma as well, so do a safe quote split
String[] parameters = StringQuoteHelper.splitSafeQuote(methodParameters, ',');
it = ObjectHelper.createIterator(parameters);
String[] parameters = StringQuoteHelper.splitSafeQuote(methodParameters, ',', false);
it = ObjectHelper.createIterator(parameters, ",", true);
}

// remove headers as they should not be propagated
Expand Down Expand Up @@ -490,8 +490,6 @@ private Object evaluateParameterValue(Exchange exchange, int index, Object param
// convert the parameter value to a String
String exp = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, parameterValue);
if (exp != null) {
// must trim first as there may be spaces between parameters
exp = exp.trim();
// check if its a valid parameter value
boolean valid = BeanHelper.isValidParameterValue(exp);

Expand Down
Expand Up @@ -16,17 +16,18 @@
*/
package org.apache.camel.component.directvm;

import org.apache.camel.AsyncCallback;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.processor.DelegateProcessor;
import org.apache.camel.processor.DelegateAsyncProcessor;
import org.apache.camel.util.ExchangeHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
*/
public final class DirectVmProcessor extends DelegateProcessor {
public final class DirectVmProcessor extends DelegateAsyncProcessor {

private static final transient Logger LOG = LoggerFactory.getLogger(DirectVmProcessor.class);
private final DirectVmEndpoint endpoint;
Expand All @@ -37,9 +38,9 @@ public DirectVmProcessor(Processor processor, DirectVmEndpoint endpoint) {
}

@Override
public void process(Exchange exchange) throws Exception {
public boolean process(final Exchange exchange, final AsyncCallback callback) {
// need to use a copy of the incoming exchange, so we route using this camel context
Exchange copy = prepareExchange(exchange);
final Exchange copy = prepareExchange(exchange);

ClassLoader current = Thread.currentThread().getContextClassLoader();
boolean changed = false;
Expand All @@ -51,10 +52,19 @@ public void process(Exchange exchange) throws Exception {
Thread.currentThread().setContextClassLoader(appClassLoader);
changed = true;
}
getProcessor().process(copy);
return getProcessor().process(copy, new AsyncCallback() {
@Override
public void done(boolean done) {
try {
// make sure to copy results back
ExchangeHelper.copyResults(exchange, copy);
} finally {
// must call callback when we are done
callback.done(done);
}
}
});
} finally {
// make sure to copy results back
ExchangeHelper.copyResults(exchange, copy);
// restore TCCL if it was changed during processing
if (changed) {
LOG.trace("Restoring Thread ContextClassLoader to {}", current);
Expand Down
Expand Up @@ -175,6 +175,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
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;
Expand Down Expand Up @@ -2152,6 +2153,10 @@ protected void forceLazyInitialization() {
getLanguageResolver();
getTypeConverterRegistry();
getTypeConverter();

if (isTypeConverterStatisticsEnabled() != null) {
getTypeConverterRegistry().getStatistics().setStatisticsEnabled(isTypeConverterStatisticsEnabled());
}
}

/**
Expand Down Expand Up @@ -2422,6 +2427,14 @@ public void setLazyLoadTypeConverters(Boolean lazyLoadTypeConverters) {
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;
}
Expand Down
Expand Up @@ -107,10 +107,14 @@ public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {

Object answer;
try {
attemptCounter.incrementAndGet();
if (statistics.isStatisticsEnabled()) {
attemptCounter.incrementAndGet();
}
answer = doConvertTo(type, exchange, value, false);
} catch (Exception e) {
failedCounter.incrementAndGet();
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
Expand All @@ -127,12 +131,15 @@ public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
}
}
if (answer == Void.TYPE) {
// Could not find suitable conversion
missCounter.incrementAndGet();
if (statistics.isStatisticsEnabled()) {
missCounter.incrementAndGet();
}
// Could not find suitable conversion
return null;
} else {
hitCounter.incrementAndGet();
if (statistics.isStatisticsEnabled()) {
hitCounter.incrementAndGet();
}
return (T) answer;
}
}
Expand All @@ -151,10 +158,14 @@ public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value)

Object answer;
try {
attemptCounter.incrementAndGet();
if (statistics.isStatisticsEnabled()) {
attemptCounter.incrementAndGet();
}
answer = doConvertTo(type, exchange, value, false);
} catch (Exception e) {
failedCounter.incrementAndGet();
if (statistics.isStatisticsEnabled()) {
failedCounter.incrementAndGet();
}
// error occurred during type conversion
if (e instanceof TypeConversionException) {
throw (TypeConversionException) e;
Expand All @@ -163,12 +174,15 @@ public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value)
}
}
if (answer == Void.TYPE || value == null) {
// Could not find suitable conversion
missCounter.incrementAndGet();
if (statistics.isStatisticsEnabled()) {
missCounter.incrementAndGet();
}
// Could not find suitable conversion
throw new NoTypeConversionAvailableException(value, type);
} else {
hitCounter.incrementAndGet();
if (statistics.isStatisticsEnabled()) {
hitCounter.incrementAndGet();
}
return (T) answer;
}
}
Expand All @@ -187,18 +201,26 @@ public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {

Object answer;
try {
attemptCounter.incrementAndGet();
if (statistics.isStatisticsEnabled()) {
attemptCounter.incrementAndGet();
}
answer = doConvertTo(type, exchange, value, true);
} catch (Exception e) {
failedCounter.incrementAndGet();
if (statistics.isStatisticsEnabled()) {
failedCounter.incrementAndGet();
}
return null;
}
if (answer == Void.TYPE) {
missCounter.incrementAndGet();
// Could not find suitable conversion
if (statistics.isStatisticsEnabled()) {
missCounter.incrementAndGet();
}
return null;
} else {
hitCounter.incrementAndGet();
if (statistics.isStatisticsEnabled()) {
hitCounter.incrementAndGet();
}
return (T) answer;
}
}
Expand Down Expand Up @@ -517,9 +539,11 @@ protected void doStart() throws Exception {
@Override
protected void doStop() throws Exception {
// log utilization statistics when stopping, including mappings
String info = statistics.toString();
info += String.format(" mappings[total=%s, misses=%s]", typeMappings.size(), misses.size());
log.info(info);
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();
Expand All @@ -531,6 +555,8 @@ protected void doStop() throws Exception {
*/
private final class UtilizationStatistics implements Statistics {

private boolean statisticsEnabled;

@Override
public long getAttemptCounter() {
return attemptCounter.get();
Expand Down Expand Up @@ -559,6 +585,16 @@ public void reset() {
failedCounter.set(0);
}

@Override
public boolean isStatisticsEnabled() {
return statisticsEnabled;
}

@Override
public void setStatisticsEnabled(boolean statisticsEnabled) {
this.statisticsEnabled = statisticsEnabled;
}

@Override
public String toString() {
return String.format("TypeConverterRegistry utilization[attempts=%s, hits=%s, misses=%s, failures=%s]",
Expand Down
Expand Up @@ -57,4 +57,12 @@ public long getFailedCounter() {
public void resetTypeConversionCounters() {
registry.getStatistics().reset();
}

public boolean isStatisticsEnabled() {
return registry.getStatistics().isStatisticsEnabled();
}

public void setStatisticsEnabled(boolean statisticsEnabled) {
registry.getStatistics().setStatisticsEnabled(statisticsEnabled);
}
}
Expand Up @@ -21,6 +21,9 @@

/**
* 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
*/
Expand Down Expand Up @@ -55,6 +58,18 @@ interface Statistics {
* 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);
}

/**
Expand Down
Expand Up @@ -22,6 +22,7 @@

import org.apache.camel.ServiceStatus;
import org.apache.camel.StatefulService;
import org.apache.camel.util.IOHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -277,17 +278,21 @@ public synchronized String getVersion() {
if (version != null) {
return version;
}

InputStream is = null;
// try to load from maven properties first
try {
Properties p = new Properties();
InputStream is = getClass().getResourceAsStream("/META-INF/maven/org.apache.camel/camel-core/pom.properties");
is = getClass().getResourceAsStream("/META-INF/maven/org.apache.camel/camel-core/pom.properties");
if (is != null) {
p.load(is);
version = p.getProperty("version", "");
}
} catch (Exception e) {
// ignore
} finally {
if (is != null) {
IOHelper.close(is);
}
}

// fallback to using Java API
Expand Down

0 comments on commit 99b5784

Please sign in to comment.