This commit is contained in:
@@ -26,8 +26,12 @@ import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.executor.ErrorHandlingTaskExecutor;
|
||||
import org.springframework.integration.scheduling.IntervalTrigger;
|
||||
import org.springframework.integration.scheduling.Trigger;
|
||||
import org.springframework.integration.util.ErrorHandler;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
@@ -66,6 +70,8 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement
|
||||
private volatile Runnable poller;
|
||||
|
||||
private volatile boolean initialized;
|
||||
|
||||
private volatile ErrorHandler errorHandler;
|
||||
|
||||
private final Object initializationMonitor = new Object();
|
||||
|
||||
@@ -90,6 +96,10 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement
|
||||
public void setTaskExecutor(TaskExecutor taskExecutor) {
|
||||
this.taskExecutor = taskExecutor;
|
||||
}
|
||||
|
||||
public void setErrorHandler(ErrorHandler errorHandler){
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a transaction manager to use for all polling operations.
|
||||
@@ -138,6 +148,14 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement
|
||||
this.transactionManager, this.transactionDefinition);
|
||||
}
|
||||
this.poller = this.createPoller();
|
||||
if(this.taskExecutor != null){
|
||||
if(this.errorHandler == null){
|
||||
taskExecutor = new ErrorHandlingTaskExecutor(
|
||||
new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(getBeanFactory())),taskExecutor);
|
||||
} else {
|
||||
taskExecutor = new ErrorHandlingTaskExecutor(errorHandler, taskExecutor);
|
||||
}
|
||||
}
|
||||
this.initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
*
|
||||
* Licensed 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.springframework.integration.executor;
|
||||
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.util.ErrorHandler;
|
||||
|
||||
public class ErrorHandlingTaskExecutor implements TaskExecutor {
|
||||
|
||||
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
private final TaskExecutor taskExecutor;
|
||||
|
||||
/**
|
||||
* @param errorChannel
|
||||
*/
|
||||
public ErrorHandlingTaskExecutor(ErrorHandler errorHandler, TaskExecutor taskExecutor) {
|
||||
this.errorHandler = errorHandler;
|
||||
this.taskExecutor = taskExecutor;
|
||||
}
|
||||
|
||||
public void execute(Runnable task) {
|
||||
taskExecutor.execute(new ErrorHandlingRunnableWrapper(task,errorHandler));
|
||||
}
|
||||
|
||||
private static class ErrorHandlingRunnableWrapper implements Runnable {
|
||||
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
private final Runnable runnableTarget;
|
||||
|
||||
public ErrorHandlingRunnableWrapper(Runnable runnableTarget,ErrorHandler errorHandler) {
|
||||
this.runnableTarget = runnableTarget;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
runnableTarget.run();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
errorHandler.handle(t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user