001/*
002 * Copyright 2002-2014 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.util.backoff;
018
019/**
020 * Provide a {@link BackOffExecution} that indicates the rate at which
021 * an operation should be retried.
022 *
023 * <p>Users of this interface are expected to use it like this:
024 *
025 * <pre class="code">
026 * BackOffExecution exec = backOff.start();
027 *
028 * // In the operation recovery/retry loop:
029 * long waitInterval = exec.nextBackOff();
030 * if (waitInterval == BackOffExecution.STOP) {
031 *     // do not retry operation
032 * }
033 * else {
034 *     // sleep, e.g. Thread.sleep(waitInterval)
035 *     // retry operation
036 * }
037 * }</pre>
038 *
039 * Once the underlying operation has completed successfully,
040 * the execution instance can be simply discarded.
041 *
042 * @author Stephane Nicoll
043 * @since 4.1
044 * @see BackOffExecution
045 */
046public interface BackOff {
047
048        /**
049         * Start a new back off execution.
050         * @return a fresh {@link BackOffExecution} ready to be used
051         */
052        BackOffExecution start();
053
054}