Skip to content

Commit

Permalink
CAMEL-8229: Moved some impl classes to support.
Browse files Browse the repository at this point in the history
  • Loading branch information
davsclaus committed Feb 6, 2015
1 parent 984de3d commit 259648f
Show file tree
Hide file tree
Showing 37 changed files with 317 additions and 235 deletions.
Expand Up @@ -17,7 +17,7 @@
package org.apache.camel.component.file; package org.apache.camel.component.file;


import org.apache.camel.Exchange; import org.apache.camel.Exchange;
import org.apache.camel.impl.LoggingExceptionHandler; import org.apache.camel.support.LoggingExceptionHandler;
import org.apache.camel.spi.ExceptionHandler; import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.spi.Synchronization; import org.apache.camel.spi.Synchronization;
import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.ObjectHelper;
Expand Down
Expand Up @@ -31,7 +31,7 @@
import org.apache.camel.Processor; import org.apache.camel.Processor;
import org.apache.camel.ShutdownRunningTask; import org.apache.camel.ShutdownRunningTask;
import org.apache.camel.SuspendableService; import org.apache.camel.SuspendableService;
import org.apache.camel.impl.LoggingExceptionHandler; import org.apache.camel.support.LoggingExceptionHandler;
import org.apache.camel.processor.MulticastProcessor; import org.apache.camel.processor.MulticastProcessor;
import org.apache.camel.spi.ExceptionHandler; import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.spi.ShutdownAware; import org.apache.camel.spi.ShutdownAware;
Expand Down
Expand Up @@ -20,6 +20,7 @@
import org.apache.camel.Processor; import org.apache.camel.Processor;
import org.apache.camel.spi.ExceptionHandler; import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.spi.UnitOfWork; import org.apache.camel.spi.UnitOfWork;
import org.apache.camel.support.LoggingExceptionHandler;
import org.apache.camel.util.UnitOfWorkHelper; import org.apache.camel.util.UnitOfWorkHelper;


/** /**
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.apache.camel.RouteAware; import org.apache.camel.RouteAware;
import org.apache.camel.spi.ExceptionHandler; import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.spi.UnitOfWork; import org.apache.camel.spi.UnitOfWork;
import org.apache.camel.support.LoggingExceptionHandler;
import org.apache.camel.support.ServiceSupport; import org.apache.camel.support.ServiceSupport;
import org.apache.camel.util.AsyncProcessorConverterHelper; import org.apache.camel.util.AsyncProcessorConverterHelper;
import org.apache.camel.util.ServiceHelper; import org.apache.camel.util.ServiceHelper;
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.apache.camel.PollingConsumerPollingStrategy; import org.apache.camel.PollingConsumerPollingStrategy;
import org.apache.camel.Processor; import org.apache.camel.Processor;
import org.apache.camel.spi.ExceptionHandler; import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.support.LoggingExceptionHandler;
import org.apache.camel.util.ServiceHelper; import org.apache.camel.util.ServiceHelper;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
Expand Down
Expand Up @@ -17,105 +17,36 @@
package org.apache.camel.impl; package org.apache.camel.impl;


import org.apache.camel.CamelContext; import org.apache.camel.CamelContext;
import org.apache.camel.CamelExchangeException;
import org.apache.camel.Exchange;
import org.apache.camel.LoggingLevel; import org.apache.camel.LoggingLevel;
import org.apache.camel.RollbackExchangeException;
import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.util.CamelLogger; import org.apache.camel.util.CamelLogger;
import org.slf4j.LoggerFactory;


/** /**
* A default implementation of {@link ExceptionHandler} which uses a {@link org.apache.camel.util.CamelLogger} to * @deprecated use {@link org.apache.camel.support.LoggingExceptionHandler}
* log the exception.
* <p/>
* This implementation will by default log the exception with stack trace at WARN level.
* <p/>
* This implementation honors the {@link org.apache.camel.impl.DefaultShutdownStrategy#isSuppressLoggingOnTimeout()}
* option to avoid logging if the logging should be suppressed.
*
* @version
*/ */
public class LoggingExceptionHandler implements ExceptionHandler { @Deprecated
private final CamelLogger logger; public class LoggingExceptionHandler extends org.apache.camel.support.LoggingExceptionHandler {
private final CamelContext camelContext;


@Deprecated
public LoggingExceptionHandler(Class<?> ownerType) { public LoggingExceptionHandler(Class<?> ownerType) {
this(null, new CamelLogger(LoggerFactory.getLogger(ownerType), LoggingLevel.WARN)); super(ownerType);
} }


public LoggingExceptionHandler(CamelContext camelContext, Class<?> ownerType) { public LoggingExceptionHandler(CamelContext camelContext, Class<?> ownerType) {
this(camelContext, new CamelLogger(LoggerFactory.getLogger(ownerType), LoggingLevel.WARN)); super(camelContext, ownerType);
} }


@Deprecated
public LoggingExceptionHandler(Class<?> ownerType, LoggingLevel level) { public LoggingExceptionHandler(Class<?> ownerType, LoggingLevel level) {
this(null, new CamelLogger(LoggerFactory.getLogger(ownerType), level)); super(ownerType, level);
} }


public LoggingExceptionHandler(CamelContext camelContext, Class<?> ownerType, LoggingLevel level) { public LoggingExceptionHandler(CamelContext camelContext, Class<?> ownerType, LoggingLevel level) {
this(camelContext, new CamelLogger(LoggerFactory.getLogger(ownerType), level)); super(camelContext, ownerType, level);
} }


@Deprecated
public LoggingExceptionHandler(CamelLogger logger) { public LoggingExceptionHandler(CamelLogger logger) {
this(null, logger); super(logger);
} }


public LoggingExceptionHandler(CamelContext camelContext, CamelLogger logger) { public LoggingExceptionHandler(CamelContext camelContext, CamelLogger logger) {
this.camelContext = camelContext; super(camelContext, logger);
this.logger = logger;
}

public void handleException(Throwable exception) {
handleException(null, null, exception);
}

public void handleException(String message, Throwable exception) {
handleException(message, null, exception);
}

public void handleException(String message, Exchange exchange, Throwable exception) {
try {
if (!isSuppressLogging()) {
String msg = CamelExchangeException.createExceptionMessage(message, exchange, exception);
if (isCausedByRollbackExchangeException(exception)) {
// do not log stack trace for intended rollbacks
logger.log(msg);
} else {
if (exception != null) {
logger.log(msg, exception);
} else {
logger.log(msg);
}
}
}
} catch (Throwable e) {
// the logging exception handler must not cause new exceptions to occur
}
}

protected boolean isCausedByRollbackExchangeException(Throwable exception) {
if (exception == null) {
return false;
}
if (exception instanceof RollbackExchangeException) {
return true;
} else if (exception.getCause() != null) {
// recursive children
return isCausedByRollbackExchangeException(exception.getCause());
}

return false;
}

protected boolean isSuppressLogging() {
if (camelContext != null) {
return (camelContext.getStatus().isStopping() || camelContext.getStatus().isStopped())
&& camelContext.getShutdownStrategy().hasTimeoutOccurred() && camelContext.getShutdownStrategy().isSuppressLoggingOnTimeout();
} else {
return false;
}
} }
} }
Expand Up @@ -19,6 +19,7 @@
import org.apache.camel.Endpoint; import org.apache.camel.Endpoint;
import org.apache.camel.PollingConsumer; import org.apache.camel.PollingConsumer;
import org.apache.camel.spi.ExceptionHandler; import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.support.LoggingExceptionHandler;
import org.apache.camel.support.ServiceSupport; import org.apache.camel.support.ServiceSupport;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
Expand Down
132 changes: 3 additions & 129 deletions camel-core/src/main/java/org/apache/camel/impl/RoutePolicySupport.java
Expand Up @@ -16,135 +16,9 @@
*/ */
package org.apache.camel.impl; package org.apache.camel.impl;


import java.util.concurrent.TimeUnit;

import org.apache.camel.Consumer;
import org.apache.camel.Exchange;
import org.apache.camel.Route;
import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.spi.RoutePolicy;
import org.apache.camel.support.ServiceSupport;
import org.apache.camel.util.ServiceHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** /**
* A base class for developing custom {@link RoutePolicy} implementations. * @deprecated use {@link org.apache.camel.support.RoutePolicySupport}
*
* @version
*/ */
public abstract class RoutePolicySupport extends ServiceSupport implements RoutePolicy { @Deprecated

public class RoutePolicySupport extends org.apache.camel.support.RoutePolicySupport {
// TODO: Move to support package

protected final Logger log = LoggerFactory.getLogger(getClass());
private ExceptionHandler exceptionHandler;

public void onInit(Route route) {
if (exceptionHandler == null) {
exceptionHandler = new LoggingExceptionHandler(route.getRouteContext().getCamelContext(), getClass());
}
}

public void onRemove(Route route) {
// noop
}

@Override
public void onStart(Route route) {
// noop
}

@Override
public void onStop(Route route) {
// noop
}

@Override
public void onSuspend(Route route) {
// noop
}

@Override
public void onResume(Route route) {
// noop
}

public void onExchangeBegin(Route route, Exchange exchange) {
// noop
}

public void onExchangeDone(Route route, Exchange exchange) {
// noop
}

protected boolean startConsumer(Consumer consumer) throws Exception {
boolean resumed = ServiceHelper.resumeService(consumer);
if (resumed) {
log.debug("Resuming consumer {}", consumer);
}
return resumed;
}

protected boolean stopConsumer(Consumer consumer) throws Exception {
boolean suspended = ServiceHelper.suspendService(consumer);
if (suspended) {
log.debug("Suspended consumer {}", consumer);
}
return suspended;
}

protected void startRoute(Route route) throws Exception {
route.getRouteContext().getCamelContext().startRoute(route.getId());
}

protected void resumeRoute(Route route) throws Exception {
route.getRouteContext().getCamelContext().resumeRoute(route.getId());
}

protected void suspendRoute(Route route) throws Exception {
route.getRouteContext().getCamelContext().suspendRoute(route.getId());
}

protected void suspendRoute(Route route, long timeout, TimeUnit timeUnit) throws Exception {
route.getRouteContext().getCamelContext().suspendRoute(route.getId(), timeout, timeUnit);
}

protected void stopRoute(Route route) throws Exception {
route.getRouteContext().getCamelContext().stopRoute(route.getId());
}

protected void stopRoute(Route route, long timeout, TimeUnit timeUnit) throws Exception {
route.getRouteContext().getCamelContext().stopRoute(route.getId(), timeout, timeUnit);
}

/**
* Handles the given exception using the {@link #getExceptionHandler()}
*
* @param t the exception to handle
*/
protected void handleException(Throwable t) {
if (exceptionHandler != null) {
exceptionHandler.handleException(t);
}
}

@Override
protected void doStart() throws Exception {
// noop
}

@Override
protected void doStop() throws Exception {
// noop
}

public ExceptionHandler getExceptionHandler() {
return exceptionHandler;
}

public void setExceptionHandler(ExceptionHandler exceptionHandler) {
this.exceptionHandler = exceptionHandler;
}

} }
Expand Up @@ -30,6 +30,7 @@
import org.apache.camel.Route; import org.apache.camel.Route;
import org.apache.camel.management.event.ExchangeCompletedEvent; import org.apache.camel.management.event.ExchangeCompletedEvent;
import org.apache.camel.support.EventNotifierSupport; import org.apache.camel.support.EventNotifierSupport;
import org.apache.camel.support.RoutePolicySupport;
import org.apache.camel.util.CamelLogger; import org.apache.camel.util.CamelLogger;
import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ServiceHelper; import org.apache.camel.util.ServiceHelper;
Expand Down
Expand Up @@ -37,7 +37,7 @@
import org.apache.camel.Navigate; import org.apache.camel.Navigate;
import org.apache.camel.Predicate; import org.apache.camel.Predicate;
import org.apache.camel.Processor; import org.apache.camel.Processor;
import org.apache.camel.impl.LoggingExceptionHandler; import org.apache.camel.support.LoggingExceptionHandler;
import org.apache.camel.spi.ExceptionHandler; import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.support.ServiceSupport; import org.apache.camel.support.ServiceSupport;
import org.apache.camel.util.AsyncProcessorHelper; import org.apache.camel.util.AsyncProcessorHelper;
Expand Down
Expand Up @@ -31,7 +31,7 @@
import org.apache.camel.Navigate; import org.apache.camel.Navigate;
import org.apache.camel.Processor; import org.apache.camel.Processor;
import org.apache.camel.Traceable; import org.apache.camel.Traceable;
import org.apache.camel.impl.LoggingExceptionHandler; import org.apache.camel.support.LoggingExceptionHandler;
import org.apache.camel.processor.resequencer.ResequencerEngine; import org.apache.camel.processor.resequencer.ResequencerEngine;
import org.apache.camel.processor.resequencer.SequenceElementComparator; import org.apache.camel.processor.resequencer.SequenceElementComparator;
import org.apache.camel.processor.resequencer.SequenceSender; import org.apache.camel.processor.resequencer.SequenceSender;
Expand Down
Expand Up @@ -45,7 +45,7 @@
import org.apache.camel.ProducerTemplate; import org.apache.camel.ProducerTemplate;
import org.apache.camel.TimeoutMap; import org.apache.camel.TimeoutMap;
import org.apache.camel.Traceable; import org.apache.camel.Traceable;
import org.apache.camel.impl.LoggingExceptionHandler; import org.apache.camel.support.LoggingExceptionHandler;
import org.apache.camel.spi.AggregationRepository; import org.apache.camel.spi.AggregationRepository;
import org.apache.camel.spi.ExceptionHandler; import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.spi.OptimisticLockingAggregationRepository; import org.apache.camel.spi.OptimisticLockingAggregationRepository;
Expand Down

0 comments on commit 259648f

Please sign in to comment.