spring-retry RetryState 源码

  • 2022-08-16
  • 浏览 (387)

spring-retry RetryState 代码

文件路径:/src/main/java/org/springframework/retry/RetryState.java

/*
 * Copyright 2006-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
 *
 *      https://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.retry;

/**
 * Stateful retry is characterised by having to recognise the items that are being
 * processed, so this interface is used primarily to provide a cache key in between failed
 * attempts. It also provides a hints to the {@link RetryOperations} for optimisations to
 * do with avoidable cache hits and switching to stateless retry if a rollback is not
 * needed.
 *
 * @author Dave Syer
 *
 */
public interface RetryState {

	/**
	 * Key representing the state for a retry attempt. Stateful retry is characterised by
	 * having to recognise the items that are being processed, so this value is used as a
	 * cache key in between failed attempts.
	 * @return the key that this state represents
	 */
	Object getKey();

	/**
	 * Indicate whether a cache lookup can be avoided. If the key is known ahead of the
	 * retry attempt to be fresh (i.e. has never been seen before) then a cache lookup can
	 * be avoided if this flag is true.
	 * @return true if the state does not require an explicit check for the key
	 */
	boolean isForceRefresh();

	/**
	 * Check whether this exception requires a rollback. The default is always true, which
	 * is conservative, so this method provides an optimisation for switching to stateless
	 * retry if there is an exception for which rollback is unnecessary. Example usage
	 * would be for a stateful retry to specify a validation exception as not for
	 * rollback.
	 * @param exception the exception that caused a retry attempt to fail
	 * @return true if this exception should cause a rollback
	 */
	boolean rollbackFor(Throwable exception);

}

相关信息

spring-retry 源码目录

相关文章

spring-retry ExhaustedRetryException 源码

spring-retry RecoveryCallback 源码

spring-retry RetryCallback 源码

spring-retry RetryContext 源码

spring-retry RetryException 源码

spring-retry RetryListener 源码

spring-retry RetryOperations 源码

spring-retry RetryPolicy 源码

spring-retry RetryStatistics 源码

spring-retry TerminatedRetryException 源码

0  赞