001/* 002 * Copyright © 2025 CUI-OpenSource-Software (info@cuioss.de) 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 * http://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 */ 016package de.cuioss.http.client.retry; 017 018import java.io.Serializable; 019 020/** 021 * Context information for retry operations. 022 * 023 * Provides immutable context data that can be used by retry strategies 024 * to make decisions about retry behavior, logging, and metrics. 025 * 026 * @param operationName descriptive name of the operation being retried 027 * @param attemptNumber current attempt number (1-based) 028 */ 029public record RetryContext(String operationName, int attemptNumber) implements Serializable { 030 031 /** 032 * Creates a new retry context for the first attempt. 033 * 034 * @param operationName descriptive name of the operation 035 * @return retry context with attempt number 1 036 */ 037 public static RetryContext initial(String operationName) { 038 return new RetryContext(operationName, 1); 039 } 040 041 /** 042 * Creates a new retry context for the next attempt. 043 * 044 * @return retry context with incremented attempt number 045 */ 046 public RetryContext nextAttempt() { 047 return new RetryContext(operationName, attemptNumber + 1); 048 } 049 050 /** 051 * Checks if this is the first attempt. 052 * 053 * @return true if this is attempt number 1 054 */ 055 public boolean isFirstAttempt() { 056 return attemptNumber == 1; 057 } 058}