org.springframework.util.ErrorHandler Java Examples
The following examples show how to use
org.springframework.util.ErrorHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleApplicationEventMulticaster.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * 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); } }
Example #2
Source File: ConcurrentTaskScheduler.java From lams with GNU General Public License v2.0 | 6 votes |
@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); } }
Example #3
Source File: ConcurrentTaskScheduler.java From java-technology-stack with MIT License | 6 votes |
@Override @Nullable 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); } }
Example #4
Source File: ConcurrentTaskScheduler.java From spring-analysis-note with MIT License | 6 votes |
@Override @Nullable 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); } }
Example #5
Source File: ScheduledTaskConfiguration.java From bugsnag-java with MIT License | 6 votes |
/** * If a task scheduler has been defined by the application, get it so that * bugsnag error handling can be added. * <p> * Reflection is the simplest way to get and set an error handler * because the error handler setter is only defined in the concrete classes, * not the TaskScheduler interface. * * @param taskScheduler the task scheduler */ private void configureExistingTaskScheduler(TaskScheduler taskScheduler, BugsnagScheduledTaskExceptionHandler errorHandler) { try { Field errorHandlerField = taskScheduler.getClass().getDeclaredField("errorHandler"); errorHandlerField.setAccessible(true); Object existingErrorHandler = errorHandlerField.get(taskScheduler); // If an error handler has already been defined then make the Bugsnag handler // call this afterwards if (existingErrorHandler instanceof ErrorHandler) { errorHandler.setExistingErrorHandler((ErrorHandler) existingErrorHandler); } // Add the bugsnag error handler to the scheduler. errorHandlerField.set(taskScheduler, errorHandler); } catch (Throwable ex) { LOGGER.warn("Bugsnag scheduled task exception handler could not be configured"); } }
Example #6
Source File: ReschedulingRunnable.java From java-technology-stack with MIT License | 5 votes |
public ReschedulingRunnable( Runnable delegate, Trigger trigger, ScheduledExecutorService executor, ErrorHandler errorHandler) { super(delegate, errorHandler); this.trigger = trigger; this.executor = executor; }
Example #7
Source File: AmqpConfiguration.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
/** * 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())); }
Example #8
Source File: TaskUtils.java From java-technology-stack with MIT License | 5 votes |
/** * 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, @Nullable ErrorHandler errorHandler, boolean isRepeatingTask) { if (task instanceof DelegatingErrorHandlingRunnable) { return (DelegatingErrorHandlingRunnable) task; } ErrorHandler eh = (errorHandler != null ? errorHandler : getDefaultErrorHandler(isRepeatingTask)); return new DelegatingErrorHandlingRunnable(task, eh); }
Example #9
Source File: DelegatingErrorHandlingRunnable.java From lams with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example #10
Source File: JmsNamespaceHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
@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); }
Example #11
Source File: SimpleApplicationEventMulticaster.java From java-technology-stack with MIT License | 5 votes |
/** * Invoke the given listener with the given event. * @param listener the ApplicationListener to invoke * @param event the current event to propagate * @since 4.1 */ protected void invokeListener(ApplicationListener<?> listener, ApplicationEvent event) { ErrorHandler errorHandler = getErrorHandler(); if (errorHandler != null) { try { doInvokeListener(listener, event); } catch (Throwable err) { errorHandler.handleError(err); } } else { doInvokeListener(listener, event); } }
Example #12
Source File: AbstractMessageListenerContainer.java From spring-analysis-note with MIT License | 5 votes |
/** * 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); } }
Example #13
Source File: ThreadPoolTaskScheduler.java From java-technology-stack with MIT License | 5 votes |
@Override public <T> Future<T> submit(Callable<T> task) { ExecutorService executor = getScheduledExecutor(); try { Callable<T> taskToUse = task; ErrorHandler errorHandler = this.errorHandler; if (errorHandler != null) { taskToUse = new DelegatingErrorHandlingCallable<>(task, errorHandler); } return executor.submit(taskToUse); } catch (RejectedExecutionException ex) { throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex); } }
Example #14
Source File: AbstractMessageListenerContainer.java From java-technology-stack with MIT License | 5 votes |
/** * 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); } }
Example #15
Source File: JmsNamespaceHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@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); }
Example #16
Source File: JmsNamespaceHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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); }
Example #17
Source File: DelegatingErrorHandlingRunnable.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * 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; }
Example #18
Source File: ConcurrentTaskScheduler.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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); } }
Example #19
Source File: ExceptionQueueContextConfig.java From sinavi-jfw with Apache License 2.0 | 5 votes |
/** * メッセージ受信側で例外が発生した場合に * リトライ対象例外は警告ログ、リトライ対象外例外はエラーログを出力する{@link ErrorHandler}のインスタンスを生成し、 * インスタンスをDIコンテナに登録します。 * @return {@link LoggingErrorHandler}のインスタンス */ @Bean public ErrorHandler errorHandler() { LoggingErrorHandler handler = new LoggingErrorHandler(); handler.setRetryableExceptions(exceptionMapping()); return handler; }
Example #20
Source File: FatalExceptionStrategyAmqpConfiguration.java From tutorials with MIT License | 4 votes |
@Bean public ErrorHandler errorHandler() { return new ConditionalRejectingErrorHandler(customExceptionStrategy()); }
Example #21
Source File: ConcurrentTaskScheduler.java From spring-analysis-note with MIT License | 4 votes |
/** * Provide an {@link ErrorHandler} strategy. */ public void setErrorHandler(ErrorHandler errorHandler) { Assert.notNull(errorHandler, "ErrorHandler must not be null"); this.errorHandler = errorHandler; }
Example #22
Source File: ReschedulingRunnable.java From spring4-understanding with Apache License 2.0 | 4 votes |
public ReschedulingRunnable(Runnable delegate, Trigger trigger, ScheduledExecutorService executor, ErrorHandler errorHandler) { super(delegate, errorHandler); this.trigger = trigger; this.executor = executor; }
Example #23
Source File: TimerManagerTaskScheduler.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Provide an {@link ErrorHandler} strategy. */ public void setErrorHandler(ErrorHandler errorHandler) { this.errorHandler = errorHandler; }
Example #24
Source File: AbstractJmsListenerContainerFactory.java From spring-analysis-note with MIT License | 4 votes |
/** * @see AbstractMessageListenerContainer#setErrorHandler(ErrorHandler) */ public void setErrorHandler(ErrorHandler errorHandler) { this.errorHandler = errorHandler; }
Example #25
Source File: LazyTraceThreadPoolTaskScheduler.java From elasticactors with Apache License 2.0 | 4 votes |
@Override public void setErrorHandler(ErrorHandler errorHandler) { this.delegate.setErrorHandler(errorHandler); }
Example #26
Source File: TimerManagerTaskScheduler.java From java-technology-stack with MIT License | 4 votes |
/** * Provide an {@link ErrorHandler} strategy. */ public void setErrorHandler(ErrorHandler errorHandler) { this.errorHandler = errorHandler; }
Example #27
Source File: AbstractJmsListenerContainerFactory.java From java-technology-stack with MIT License | 4 votes |
/** * @see AbstractMessageListenerContainer#setErrorHandler(ErrorHandler) */ public void setErrorHandler(ErrorHandler errorHandler) { this.errorHandler = errorHandler; }
Example #28
Source File: ListenerErrorHandlerAmqpConfiguration.java From tutorials with MIT License | 4 votes |
@Bean public ErrorHandler errorHandler() { return new CustomErrorHandler(); }
Example #29
Source File: ConcurrentTaskScheduler.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Provide an {@link ErrorHandler} strategy. */ public void setErrorHandler(ErrorHandler errorHandler) { Assert.notNull(errorHandler, "ErrorHandler must not be null"); this.errorHandler = errorHandler; }
Example #30
Source File: ReschedulingRunnable.java From lams with GNU General Public License v2.0 | 4 votes |
public ReschedulingRunnable(Runnable delegate, Trigger trigger, ScheduledExecutorService executor, ErrorHandler errorHandler) { super(delegate, errorHandler); this.trigger = trigger; this.executor = executor; }