28
28
import com .arpnetworking .tsdcore .model .PeriodicData ;
29
29
import com .fasterxml .jackson .annotation .JacksonInject ;
30
30
import com .google .common .collect .Lists ;
31
+ import net .sf .oval .constraint .CheckWith ;
32
+ import net .sf .oval .constraint .CheckWithCheck ;
31
33
import net .sf .oval .constraint .Min ;
32
34
import net .sf .oval .constraint .NotNull ;
33
35
import org .asynchttpclient .AsyncHttpClient ;
@@ -133,6 +135,33 @@ protected URI getUri() {
133
135
protected Uri getAysncHttpClientUri () {
134
136
return _aysncHttpClientUri ;
135
137
}
138
+
139
+ /**
140
+ * Accessor for the MaximumAttempts.
141
+ *
142
+ * @return The MaximumAttempts.
143
+ */
144
+ protected int getMaximumAttempts () {
145
+ return _maximumAttempts ;
146
+ }
147
+
148
+ /**
149
+ * Accessor for the BaseBackoff of retries <code>Period</code>.
150
+ *
151
+ * @return The BaseBackoff <code>Period</code>.
152
+ */
153
+ protected Period getRetryBaseBackoff () {
154
+ return _baseBackoff ;
155
+ }
156
+
157
+ /**
158
+ * Accessor for the MaximumDelay of retries <code>Period</code>.
159
+ *
160
+ * @return The MaximumDelay <code>Period</code>.
161
+ */
162
+ protected Period getRetryMaximumDelay () {
163
+ return _maximumDelay ;
164
+ }
136
165
137
166
/**
138
167
* Serialize the <code>PeriodicData</code> and <code>Condition</code> instances
@@ -161,11 +190,18 @@ protected HttpPostSink(final Builder<?, ?> builder) {
161
190
builder ._maximumQueueSize ,
162
191
builder ._spreadPeriod ,
163
192
builder ._metricsFactory ));
193
+
194
+ _maximumAttempts = builder ._maximumAttempts ;
195
+ _baseBackoff = builder ._baseBackoff ;
196
+ _maximumDelay = builder ._maximumDelay ;
164
197
}
165
198
166
199
private final URI _uri ;
167
200
private final Uri _aysncHttpClientUri ;
168
201
private final ActorRef _sinkActor ;
202
+ private final int _maximumAttempts ;
203
+ private final Period _baseBackoff ;
204
+ private final Period _maximumDelay ;
169
205
170
206
private static final Logger LOGGER = LoggerFactory .getLogger (HttpPostSink .class );
171
207
private static final AsyncHttpClient CLIENT ;
@@ -244,6 +280,18 @@ public B setSpreadPeriod(final Period value) {
244
280
return self ();
245
281
}
246
282
283
+ /**
284
+ * Sets the maximum number of attempts of the http requests. Optional. Cannot be null.
285
+ * Default is 1. Minimum is 1.
286
+ *
287
+ * @param value the maximum number of attempts of the http requests.
288
+ * @return this builder
289
+ */
290
+ public B setMaximumAttempts (final Integer value ) {
291
+ _maximumAttempts = value ;
292
+ return self ();
293
+ }
294
+
247
295
/**
248
296
* Sets the maximum pending queue size. Optional Cannot be null.
249
297
* Default is 25000. Minimum is 1.
@@ -256,6 +304,30 @@ public B setMaximumQueueSize(final Integer value) {
256
304
return self ();
257
305
}
258
306
307
+ /**
308
+ * Sets the base backoff period. Optional Cannot be null.
309
+ * Default is 50 milliseconds.
310
+ *
311
+ * @param value the base backoff period
312
+ * @return this builder
313
+ */
314
+ public B setBaseBackoff (final Period value ) {
315
+ _baseBackoff = value ;
316
+ return self ();
317
+ }
318
+
319
+ /**
320
+ * Sets the maximum delay for retries. Optional Cannot be null.
321
+ * Default is 60 seconds.
322
+ *
323
+ * @param value the maximum delay for retries
324
+ * @return this builder
325
+ */
326
+ public B setMaximumDelay (final Period value ) {
327
+ _maximumDelay = value ;
328
+ return self ();
329
+ }
330
+
259
331
/**
260
332
* Protected constructor for subclasses.
261
333
*
@@ -281,5 +353,28 @@ protected Builder(final Function<B, S> targetConstructor) {
281
353
@ JacksonInject
282
354
@ NotNull
283
355
private MetricsFactory _metricsFactory ;
356
+ @ NotNull
357
+ @ Min (1 )
358
+ private Integer _maximumAttempts = 1 ;
359
+ @ NotNull
360
+ private Period _baseBackoff = Period .millis (50 );
361
+ @ NotNull
362
+ @ CheckWith (CheckPeriod .class )
363
+ private Period _maximumDelay = Period .seconds (60 );
364
+
365
+
366
+ private static final class CheckPeriod implements CheckWithCheck .SimpleCheck {
367
+
368
+ private static final long serialVersionUID = -6924010227680984149L ;
369
+
370
+ @ Override
371
+ public boolean isSatisfied (final Object validatedObject , final Object value ) {
372
+ if (!(validatedObject instanceof HttpPostSink .Builder )) {
373
+ return false ;
374
+ }
375
+ final HttpPostSink .Builder <?, ?> builder = (HttpPostSink .Builder <?, ?>) validatedObject ;
376
+ return builder ._baseBackoff .getMillis () >= 0 && builder ._maximumDelay .getMillis () >= 0 ;
377
+ }
378
+ }
284
379
}
285
380
}
0 commit comments