@@ -35,6 +35,7 @@ public final class HandlerDefinition<REQ, RES> {
3535 private final @ Nullable Duration journalRetention ;
3636 private final @ Nullable Boolean ingressPrivate ;
3737 private final @ Nullable Boolean enableLazyState ;
38+ private final @ Nullable InvocationRetryPolicy invocationRetryPolicy ;
3839
3940 HandlerDefinition (
4041 String name ,
@@ -51,7 +52,8 @@ public final class HandlerDefinition<REQ, RES> {
5152 @ Nullable Duration workflowRetention ,
5253 @ Nullable Duration journalRetention ,
5354 @ Nullable Boolean ingressPrivate ,
54- @ Nullable Boolean enableLazyState ) {
55+ @ Nullable Boolean enableLazyState ,
56+ @ Nullable InvocationRetryPolicy invocationRetryPolicy ) {
5557 this .name = name ;
5658 this .handlerType = handlerType ;
5759 this .acceptContentType = acceptContentType ;
@@ -67,6 +69,7 @@ public final class HandlerDefinition<REQ, RES> {
6769 this .journalRetention = journalRetention ;
6870 this .ingressPrivate = ingressPrivate ;
6971 this .enableLazyState = enableLazyState ;
72+ this .invocationRetryPolicy = invocationRetryPolicy ;
7073 }
7174
7275 /**
@@ -181,6 +184,14 @@ public HandlerRunner<REQ, RES> getRunner() {
181184 return enableLazyState ;
182185 }
183186
187+ /**
188+ * @return Retry policy for all requests to this handler
189+ * @see Configurator#invocationRetryPolicy(InvocationRetryPolicy)
190+ */
191+ public @ Nullable InvocationRetryPolicy getInvocationRetryPolicy () {
192+ return invocationRetryPolicy ;
193+ }
194+
184195 public HandlerDefinition <REQ , RES > withAcceptContentType (String acceptContentType ) {
185196 return new HandlerDefinition <>(
186197 name ,
@@ -197,7 +208,8 @@ public HandlerDefinition<REQ, RES> withAcceptContentType(String acceptContentTyp
197208 workflowRetention ,
198209 journalRetention ,
199210 ingressPrivate ,
200- enableLazyState );
211+ enableLazyState ,
212+ invocationRetryPolicy );
201213 }
202214
203215 public HandlerDefinition <REQ , RES > withDocumentation (@ Nullable String documentation ) {
@@ -216,7 +228,8 @@ public HandlerDefinition<REQ, RES> withDocumentation(@Nullable String documentat
216228 journalRetention ,
217229 workflowRetention ,
218230 ingressPrivate ,
219- enableLazyState );
231+ enableLazyState ,
232+ invocationRetryPolicy );
220233 }
221234
222235 public HandlerDefinition <REQ , RES > withMetadata (Map <String , String > metadata ) {
@@ -235,7 +248,8 @@ public HandlerDefinition<REQ, RES> withMetadata(Map<String, String> metadata) {
235248 workflowRetention ,
236249 journalRetention ,
237250 ingressPrivate ,
238- enableLazyState );
251+ enableLazyState ,
252+ invocationRetryPolicy );
239253 }
240254
241255 /**
@@ -255,7 +269,8 @@ public HandlerDefinition<REQ, RES> configure(
255269 workflowRetention ,
256270 journalRetention ,
257271 ingressPrivate ,
258- enableLazyState );
272+ enableLazyState ,
273+ invocationRetryPolicy );
259274 configurator .accept (configuratorObj );
260275
261276 return new HandlerDefinition <>(
@@ -273,7 +288,8 @@ public HandlerDefinition<REQ, RES> configure(
273288 configuratorObj .workflowRetention ,
274289 configuratorObj .journalRetention ,
275290 configuratorObj .ingressPrivate ,
276- configuratorObj .enableLazyState );
291+ configuratorObj .enableLazyState ,
292+ configuratorObj .invocationRetryPolicy );
277293 }
278294
279295 /** Configurator for a {@link HandlerDefinition}. */
@@ -290,6 +306,7 @@ public static final class Configurator {
290306 private @ Nullable Duration journalRetention ;
291307 private @ Nullable Boolean ingressPrivate ;
292308 private @ Nullable Boolean enableLazyState ;
309+ private @ Nullable InvocationRetryPolicy invocationRetryPolicy ;
293310
294311 private Configurator (
295312 HandlerType handlerType ,
@@ -302,7 +319,8 @@ private Configurator(
302319 @ Nullable Duration workflowRetention ,
303320 @ Nullable Duration journalRetention ,
304321 @ Nullable Boolean ingressPrivate ,
305- @ Nullable Boolean enableLazyState ) {
322+ @ Nullable Boolean enableLazyState ,
323+ @ Nullable InvocationRetryPolicy invocationRetryPolicy ) {
306324 this .handlerType = handlerType ;
307325 this .acceptContentType = acceptContentType ;
308326 this .documentation = documentation ;
@@ -314,6 +332,7 @@ private Configurator(
314332 this .journalRetention = journalRetention ;
315333 this .ingressPrivate = ingressPrivate ;
316334 this .enableLazyState = enableLazyState ;
335+ this .invocationRetryPolicy = invocationRetryPolicy ;
317336 }
318337
319338 /**
@@ -555,6 +574,37 @@ public Configurator enableLazyState(@Nullable Boolean enableLazyState) {
555574 this .enableLazyState = enableLazyState ;
556575 return this ;
557576 }
577+
578+ /**
579+ * @return configured invocation retry policy
580+ * @see #invocationRetryPolicy(InvocationRetryPolicy)
581+ */
582+ public @ Nullable InvocationRetryPolicy invocationRetryPolicy () {
583+ return invocationRetryPolicy ;
584+ }
585+
586+ /**
587+ * Retry policy used by Restate when invoking this handler.
588+ *
589+ * <p><b>NOTE:</b> You can set this field only if you register this service against
590+ * restate-server >= 1.5, otherwise the service discovery will fail.
591+ *
592+ * @see InvocationRetryPolicy
593+ * @return this
594+ */
595+ public Configurator invocationRetryPolicy (
596+ @ Nullable InvocationRetryPolicy invocationRetryPolicy ) {
597+ this .invocationRetryPolicy = invocationRetryPolicy ;
598+ return this ;
599+ }
600+
601+ /**
602+ * @see #invocationRetryPolicy(InvocationRetryPolicy)
603+ */
604+ public Configurator invocationRetryPolicy (InvocationRetryPolicy .Builder invocationRetryPolicy ) {
605+ this .invocationRetryPolicy = invocationRetryPolicy .build ();
606+ return this ;
607+ }
558608 }
559609
560610 public static <REQ , RES > HandlerDefinition <REQ , RES > of (
@@ -578,6 +628,7 @@ public static <REQ, RES> HandlerDefinition<REQ, RES> of(
578628 null ,
579629 null ,
580630 null ,
631+ null ,
581632 null );
582633 }
583634
@@ -598,7 +649,8 @@ && getHandlerType() == that.getHandlerType()
598649 && Objects .equals (getWorkflowRetention (), that .getWorkflowRetention ())
599650 && Objects .equals (getJournalRetention (), that .getJournalRetention ())
600651 && Objects .equals (getIngressPrivate (), that .getIngressPrivate ())
601- && Objects .equals (getEnableLazyState (), that .getEnableLazyState ());
652+ && Objects .equals (getEnableLazyState (), that .getEnableLazyState ())
653+ && Objects .equals (getInvocationRetryPolicy (), that .getInvocationRetryPolicy ());
602654 }
603655
604656 @ Override
@@ -618,6 +670,7 @@ public int hashCode() {
618670 getWorkflowRetention (),
619671 getJournalRetention (),
620672 getIngressPrivate (),
621- getEnableLazyState ());
673+ getEnableLazyState (),
674+ getInvocationRetryPolicy ());
622675 }
623676}
0 commit comments