1 /* 2 * Copyright 2017 Google LLC 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google LLC nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 package com.google.api.gax.retrying; 31 32 import com.google.api.core.ApiClock; 33 import com.google.auto.value.AutoValue; 34 import org.threeten.bp.Duration; 35 36 /** Timed attempt execution settings. Defines time-specific properties of a retry attempt. */ 37 @AutoValue 38 public abstract class TimedAttemptSettings { 39 40 /** Returns global (attempt-independent) retry settings. */ getGlobalSettings()41 public abstract RetrySettings getGlobalSettings(); 42 43 /** 44 * Returns the calculated retry delay. Note that the actual delay used for retry scheduling may be 45 * different (randomized, based on this value). 46 */ getRetryDelay()47 public abstract Duration getRetryDelay(); 48 49 /** Returns rpc timeout used for this attempt. */ getRpcTimeout()50 public abstract Duration getRpcTimeout(); 51 52 /** 53 * Returns randomized attempt delay. By default this value is calculated based on the {@code 54 * retryDelay} value, and is used as the actual attempt execution delay. 55 */ getRandomizedRetryDelay()56 public abstract Duration getRandomizedRetryDelay(); 57 58 /** 59 * The attempt count. It is a zero-based value (first attempt will have this value set to 0). For 60 * streamed RPCs this will be reset after every successful message. 61 */ getAttemptCount()62 public abstract int getAttemptCount(); 63 64 /** 65 * The overall attempt count. It is a zero-based value (first attempt will have this value set to 66 * 0). This will be the sum of all attempt counts for a streaming RPC and will be equal to {@link 67 * #getAttemptCount()} for unary RPCs. 68 */ getOverallAttemptCount()69 public abstract int getOverallAttemptCount(); 70 71 /** 72 * The start time of the first attempt. Note that this value is dependent on the actual {@link 73 * ApiClock} used during the process. 74 */ getFirstAttemptStartTimeNanos()75 public abstract long getFirstAttemptStartTimeNanos(); 76 toBuilder()77 public abstract Builder toBuilder(); 78 newBuilder()79 public static Builder newBuilder() { 80 return new AutoValue_TimedAttemptSettings.Builder().setOverallAttemptCount(0); 81 } 82 83 @AutoValue.Builder 84 public abstract static class Builder { 85 /** Sets global (attempt-independent) retry settings. */ setGlobalSettings(RetrySettings value)86 public abstract Builder setGlobalSettings(RetrySettings value); 87 88 /** 89 * Sets the calculated retry delay. Note that the actual delay used for retry scheduling may be 90 * different (randomized, based on this value). 91 */ setRetryDelay(Duration value)92 public abstract Builder setRetryDelay(Duration value); 93 94 /** Sets rpc timeout used for this attempt. */ setRpcTimeout(Duration value)95 public abstract Builder setRpcTimeout(Duration value); 96 97 /** 98 * Sets randomized attempt delay. By default this value is calculated based on the {@code 99 * retryDelay} value, and is used as the actual attempt execution delay. 100 */ setRandomizedRetryDelay(Duration value)101 public abstract Builder setRandomizedRetryDelay(Duration value); 102 103 /** 104 * Set the attempt count. It is a zero-based value (first attempt will have this value set to 105 * 0). 106 */ setAttemptCount(int value)107 public abstract Builder setAttemptCount(int value); 108 109 /** 110 * Set the overall attempt count. It is a zero-based value (first attempt will have this value 111 * set to 0). 112 */ setOverallAttemptCount(int value)113 public abstract Builder setOverallAttemptCount(int value); 114 115 /** 116 * Set the start time of the first attempt. Note that this value is dependent on the actual 117 * {@link ApiClock} used during the process. 118 */ setFirstAttemptStartTimeNanos(long value)119 public abstract Builder setFirstAttemptStartTimeNanos(long value); 120 build()121 public abstract TimedAttemptSettings build(); 122 } 123 } 124