9
9
10
10
import com .google .common .collect .ImmutableList ;
11
11
12
+ import tech .ydb .common .retry .RetryConfig ;
13
+ import tech .ydb .common .retry .RetryPolicy ;
12
14
import tech .ydb .core .Status ;
15
+ import tech .ydb .core .StatusCode ;
13
16
14
17
/**
15
18
* @author Nikolay Perfilov
@@ -20,17 +23,17 @@ public class ReaderSettings {
20
23
private final String consumerName ;
21
24
private final String readerName ;
22
25
private final List <TopicReadSettings > topics ;
26
+ private final RetryConfig retryConfig ;
23
27
private final long maxMemoryUsageBytes ;
24
28
private final Executor decompressionExecutor ;
25
- private final BiConsumer <Status , Throwable > errorsHandler ;
26
29
27
30
private ReaderSettings (Builder builder ) {
28
31
this .consumerName = builder .consumerName ;
29
32
this .readerName = builder .readerName ;
30
33
this .topics = ImmutableList .copyOf (builder .topics );
34
+ this .retryConfig = builder .retryConfig ;
31
35
this .maxMemoryUsageBytes = builder .maxMemoryUsageBytes ;
32
36
this .decompressionExecutor = builder .decompressionExecutor ;
33
- this .errorsHandler = builder .errorsHandler ;
34
37
}
35
38
36
39
public String getConsumerName () {
@@ -42,12 +45,17 @@ public String getReaderName() {
42
45
return readerName ;
43
46
}
44
47
48
+ public RetryConfig getRetryConfig () {
49
+ return retryConfig ;
50
+ }
51
+
45
52
public List <TopicReadSettings > getTopics () {
46
53
return topics ;
47
54
}
48
55
56
+ @ Deprecated
49
57
public BiConsumer <Status , Throwable > getErrorsHandler () {
50
- return errorsHandler ;
58
+ return null ;
51
59
}
52
60
53
61
public long getMaxMemoryUsageBytes () {
@@ -70,9 +78,9 @@ public static class Builder {
70
78
private boolean readWithoutConsumer = false ;
71
79
private String readerName = null ;
72
80
private List <TopicReadSettings > topics = new ArrayList <>();
81
+ private RetryConfig retryConfig = RetryConfig .idempotentRetryForever ();
73
82
private long maxMemoryUsageBytes = MAX_MEMORY_USAGE_BYTES_DEFAULT ;
74
83
private Executor decompressionExecutor = null ;
75
- private BiConsumer <Status , Throwable > errorsHandler = null ;
76
84
77
85
public Builder setConsumerName (String consumerName ) {
78
86
this .consumerName = consumerName ;
@@ -91,6 +99,7 @@ public Builder withoutConsumer() {
91
99
92
100
/**
93
101
* Set reader name for debug purposes
102
+ * @param readerName name of reader
94
103
* @return settings builder
95
104
*/
96
105
public Builder setReaderName (String readerName ) {
@@ -108,13 +117,42 @@ public Builder setTopics(List<TopicReadSettings> topics) {
108
117
return this ;
109
118
}
110
119
120
+ /**
121
+ * Set {@link RetryConfig} to define behavior of the stream internal retries
122
+ * @param config retry mode
123
+ * @return settings builder
124
+ */
125
+ public Builder setRetryConfig (RetryConfig config ) {
126
+ this .retryConfig = config ;
127
+ return this ;
128
+ }
129
+
111
130
public Builder setMaxMemoryUsageBytes (long maxMemoryUsageBytes ) {
112
131
this .maxMemoryUsageBytes = maxMemoryUsageBytes ;
113
132
return this ;
114
133
}
115
134
135
+ /**
136
+ * @param handler
137
+ * @return builder
138
+ * @deprecated use {@link Builder#setRetryConfig(tech.ydb.common.retry.RetryConfig)} instead
139
+ */
140
+ @ Deprecated
116
141
public Builder setErrorsHandler (BiConsumer <Status , Throwable > handler ) {
117
- this .errorsHandler = handler ;
142
+ final RetryConfig currentConfig = retryConfig ;
143
+ retryConfig = new RetryConfig () {
144
+ @ Override
145
+ public RetryPolicy isStatusRetryable (StatusCode code ) {
146
+ handler .accept (Status .of (code ), null );
147
+ return currentConfig .isStatusRetryable (code );
148
+ }
149
+
150
+ @ Override
151
+ public RetryPolicy isThrowableRetryable (Throwable th ) {
152
+ handler .accept (null , th );
153
+ return currentConfig .isThrowableRetryable (th );
154
+ }
155
+ };
118
156
return this ;
119
157
}
120
158
0 commit comments