本文整理汇总了Java中org.springframework.util.ErrorHandler类的典型用法代码示例。如果您正苦于以下问题:Java ErrorHandler类的具体用法?Java ErrorHandler怎么用?Java ErrorHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ErrorHandler类属于org.springframework.util包,在下文中一共展示了ErrorHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeListener
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
/**
* Invoke the given listener with the given event.
* @param listener the ApplicationListener to invoke
* @param event the current event to propagate
* @since 4.1
*/
@SuppressWarnings({"unchecked", "rawtypes"})
protected void invokeListener(ApplicationListener listener, ApplicationEvent event) {
ErrorHandler errorHandler = getErrorHandler();
if (errorHandler != null) {
try {
listener.onApplicationEvent(event);
}
catch (Throwable err) {
errorHandler.handleError(err);
}
}
else {
listener.onApplicationEvent(event);
}
}
示例2: invokeListener
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
/**
* Invoke the given listener with the given event.
* @param listener the ApplicationListener to invoke
* @param event the current event to propagate
* @since 4.1
*/
@SuppressWarnings({"unchecked", "rawtypes"})
protected void invokeListener(ApplicationListener listener, ApplicationEvent event) {
ErrorHandler errorHandler = getErrorHandler();
if (errorHandler != null) {
try {
listener.onApplicationEvent(event);
}
catch (Throwable err) {
errorHandler.handleError(err);
}
}
else {
try {
listener.onApplicationEvent(event);
}
catch (ClassCastException ex) {
// Possibly a lambda-defined listener which we could not resolve the generic event type for
LogFactory.getLog(getClass()).debug("Non-matching event type for listener: " + listener, ex);
}
}
}
示例3: init
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
@PostConstruct
public void init() {
this.actionMonitor = new ActionMonitor();
this.detectionTasks = new HashMap<>();
this.taskScheduler = new ThreadPoolTaskScheduler();
this.taskScheduler.setPoolSize(10);
this.taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
this.taskScheduler.setRemoveOnCancelPolicy(true);
this.taskScheduler.setErrorHandler(
new ErrorHandler() {
protected Logger log = LoggerFactory.getLogger(this.getClass());
@Override
public void handleError(Throwable t) {
log.error(t.getMessage(), t);
}
});
this.taskScheduler.initialize();
}
示例4: init
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
@PostConstruct
public void init() {
this.actionMonitor = new ActionMonitor();
this.executionEngine.setActionMonitor(actionMonitor);
this.taskScheduler = new ThreadPoolTaskScheduler();
this.taskScheduler.setPoolSize(10);
this.taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
this.taskScheduler.setRemoveOnCancelPolicy(true);
this.taskScheduler.setErrorHandler(
new ErrorHandler() {
protected Logger log = LoggerFactory.getLogger(this.getClass());
@Override
public void handleError(Throwable t) {
log.error(t.getMessage(), t);
}
});
this.taskScheduler.initialize();
}
示例5: init
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
@PostConstruct
public void init() {
this.actionMonitor = new ActionMonitor();
this.taskScheduler = new ThreadPoolTaskScheduler();
this.taskScheduler.setPoolSize(10);
this.taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
this.taskScheduler.setRemoveOnCancelPolicy(true);
this.taskScheduler.setErrorHandler(
new ErrorHandler() {
protected Logger log = LoggerFactory.getLogger(this.getClass());
@Override
public void handleError(Throwable t) {
log.error(t.getMessage(), t);
}
});
this.taskScheduler.initialize();
}
示例6: DelegatingErrorHandlingRunnable
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
/**
* Create a new DelegatingErrorHandlingRunnable.
* @param delegate the Runnable implementation to delegate to
* @param errorHandler the ErrorHandler for handling any exceptions
*/
public DelegatingErrorHandlingRunnable(Runnable delegate, ErrorHandler errorHandler) {
Assert.notNull(delegate, "Delegate must not be null");
Assert.notNull(errorHandler, "ErrorHandler must not be null");
this.delegate = delegate;
this.errorHandler = errorHandler;
}
示例7: decorateTaskWithErrorHandler
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
/**
* Decorate the task for error handling. If the provided {@link ErrorHandler}
* is not {@code null}, it will be used. Otherwise, repeating tasks will have
* errors suppressed by default whereas one-shot tasks will have errors
* propagated by default since those errors may be expected through the
* returned {@link Future}. In both cases, the errors will be logged.
*/
public static DelegatingErrorHandlingRunnable decorateTaskWithErrorHandler(
Runnable task, ErrorHandler errorHandler, boolean isRepeatingTask) {
if (task instanceof DelegatingErrorHandlingRunnable) {
return (DelegatingErrorHandlingRunnable) task;
}
ErrorHandler eh = (errorHandler != null ? errorHandler : getDefaultErrorHandler(isRepeatingTask));
return new DelegatingErrorHandlingRunnable(task, eh);
}
示例8: schedule
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
@Override
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
try {
if (this.enterpriseConcurrentScheduler) {
return new EnterpriseConcurrentTriggerScheduler().schedule(decorateTask(task, true), trigger);
}
else {
ErrorHandler errorHandler = (this.errorHandler != null ? this.errorHandler : TaskUtils.getDefaultErrorHandler(true));
return new ReschedulingRunnable(task, trigger, this.scheduledExecutor, errorHandler).schedule();
}
}
catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + this.scheduledExecutor + "] did not accept task: " + task, ex);
}
}
示例9: schedule
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
@Override
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
ScheduledExecutorService executor = getScheduledExecutor();
try {
ErrorHandler errorHandler =
(this.errorHandler != null ? this.errorHandler : TaskUtils.getDefaultErrorHandler(true));
return new ReschedulingRunnable(task, trigger, executor, errorHandler).schedule();
}
catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
}
}
示例10: invokeErrorHandler
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
/**
* Invoke the registered ErrorHandler, if any. Log at warn level otherwise.
* @param ex the uncaught error that arose during JMS processing.
* @see #setErrorHandler
*/
protected void invokeErrorHandler(Throwable ex) {
ErrorHandler errorHandler = getErrorHandler();
if (errorHandler != null) {
errorHandler.handleError(ex);
}
else {
logger.warn("Execution of JMS message listener failed, and no ErrorHandler has been set.", ex);
}
}
示例11: testErrorHandlers
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
@Test
public void testErrorHandlers() {
ErrorHandler expected = this.context.getBean("testErrorHandler", ErrorHandler.class);
ErrorHandler errorHandler1 = getErrorHandler("listener1");
ErrorHandler errorHandler2 = getErrorHandler("listener2");
ErrorHandler defaultErrorHandler = getErrorHandler(DefaultMessageListenerContainer.class.getName() + "#0");
assertSame(expected, errorHandler1);
assertSame(expected, errorHandler2);
assertNull(defaultErrorHandler);
}
示例12: errorHandler
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
/**
* Register the bean for the custom error handler.
*
* @return custom error handler
*/
@Bean
@ConditionalOnMissingBean(ErrorHandler.class)
public ErrorHandler errorHandler() {
return new ConditionalRejectingErrorHandler(
new DelayedRequeueExceptionStrategy(amqpProperties.getRequeueDelay()));
}
示例13: listenerContainerFactory
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(name = "listenerContainerFactory")
public RabbitListenerContainerFactory<SimpleMessageListenerContainer> listenerContainerFactory(
final SimpleRabbitListenerContainerFactoryConfigurer configurer, final ErrorHandler errorHandler) {
final ConfigurableRabbitListenerContainerFactory factory = new ConfigurableRabbitListenerContainerFactory(
amqpProperties.isMissingQueuesFatal(), amqpProperties.getDeclarationRetries(), errorHandler);
configurer.configure(factory, rabbitConnectionFactory);
return factory;
}
示例14: taskScheduler
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
@Bean(destroyMethod = "shutdown")
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setErrorHandler(new ErrorHandler() {
@Override
public void handleError(Throwable t) {
LogManager.getLogger().error("error while handling job", t);
}
});
scheduler.initialize();
return scheduler;
}
示例15: decorateTaskWithErrorHandler
import org.springframework.util.ErrorHandler; //导入依赖的package包/类
/**
* Decorates the task for error handling. If the provided
* {@link ErrorHandler} is not null, it will be used. Otherwise,
* repeating tasks will have errors suppressed by default whereas
* one-shot tasks will have errors propagated by default since those
* errors may be expected through the returned {@link Future}. In both
* cases, the errors will be logged.
*/
public static DelegatingErrorHandlingRunnable decorateTaskWithErrorHandler(
Runnable task, ErrorHandler errorHandler, boolean isRepeatingTask) {
if (task instanceof DelegatingErrorHandlingRunnable) {
return (DelegatingErrorHandlingRunnable) task;
}
ErrorHandler eh = errorHandler != null ? errorHandler : getDefaultErrorHandler(isRepeatingTask);
return new DelegatingErrorHandlingRunnable(task, eh);
}