001/*
002 * Copyright 2002-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.scheduling.annotation;
018
019import java.util.concurrent.Executor;
020
021import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
022import org.springframework.lang.Nullable;
023
024/**
025 * Interface to be implemented by @{@link org.springframework.context.annotation.Configuration
026 * Configuration} classes annotated with @{@link EnableAsync} that wish to customize the
027 * {@link Executor} instance used when processing async method invocations or the
028 * {@link AsyncUncaughtExceptionHandler} instance used to process exception thrown from
029 * async method with {@code void} return type.
030 *
031 * <p>Consider using {@link AsyncConfigurerSupport} providing default implementations for
032 * both methods if only one element needs to be customized. Furthermore, backward compatibility
033 * of this interface will be insured in case new customization options are introduced
034 * in the future.
035 *
036 * <p>See @{@link EnableAsync} for usage examples.
037 *
038 * @author Chris Beams
039 * @author Stephane Nicoll
040 * @since 3.1
041 * @see AbstractAsyncConfiguration
042 * @see EnableAsync
043 * @see AsyncConfigurerSupport
044 */
045public interface AsyncConfigurer {
046
047        /**
048         * The {@link Executor} instance to be used when processing async
049         * method invocations.
050         */
051        @Nullable
052        default Executor getAsyncExecutor() {
053                return null;
054        }
055
056        /**
057         * The {@link AsyncUncaughtExceptionHandler} instance to be used
058         * when an exception is thrown during an asynchronous method execution
059         * with {@code void} return type.
060         */
061        @Nullable
062        default AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
063                return null;
064        }
065
066}