Skip to content

Commit eae647c

Browse files
authored
Add statically-typed support for enqueueStart (#886)
The preferred mechanism for interacting with workflows is via the statically typed interface so that parameter types can be checked at compile time. Add the 14 required overloads of WorkflowClient#enqueueStart to mirror WorkflowClient#start, and implement support for it in WorkflowInvocationHandler.
1 parent bf06a8d commit eae647c

File tree

4 files changed

+457
-0
lines changed

4 files changed

+457
-0
lines changed

src/main/java/com/uber/cadence/client/WorkflowClient.java

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,299 @@ static <A1, A2, A3, A4, A5, A6, R> WorkflowExecution start(
469469
return WorkflowClientInternal.start(workflow, arg1, arg2, arg3, arg4, arg5, arg6);
470470
}
471471

472+
/**
473+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
474+
* requires that async execution has been enabled for this domain.
475+
*
476+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
477+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
478+
* workflow actually starts.
479+
*
480+
* @param workflow The only supported value is method reference to a proxy created through {@link
481+
* #newWorkflowStub(Class, WorkflowOptions)}.
482+
* @return WorkflowExecution containing only the workflowId
483+
*/
484+
static WorkflowExecution enqueueStart(Functions.Proc workflow) {
485+
return WorkflowClientInternal.enqueueStart(workflow);
486+
}
487+
488+
/**
489+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
490+
* requires that async execution has been enabled for this domain.
491+
*
492+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
493+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
494+
* workflow actually starts.
495+
*
496+
* @param workflow The only supported value is method reference to a proxy created through {@link
497+
* #newWorkflowStub(Class, WorkflowOptions)}.
498+
* @param arg1 first workflow argument
499+
* @return WorkflowExecution containing only the workflowId
500+
*/
501+
static <A1> WorkflowExecution enqueueStart(Functions.Proc1<A1> workflow, A1 arg1) {
502+
return WorkflowClientInternal.enqueueStart(workflow, arg1);
503+
}
504+
505+
/**
506+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
507+
* requires that async execution has been enabled for this domain.
508+
*
509+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
510+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
511+
* workflow actually starts.
512+
*
513+
* @param workflow The only supported value is method reference to a proxy created through {@link
514+
* #newWorkflowStub(Class, WorkflowOptions)}.
515+
* @param arg1 first workflow argument
516+
* @param arg2 second workflow argument
517+
* @return WorkflowExecution containing only the workflowId
518+
*/
519+
static <A1, A2> WorkflowExecution enqueueStart(
520+
Functions.Proc2<A1, A2> workflow, A1 arg1, A2 arg2) {
521+
return WorkflowClientInternal.enqueueStart(workflow, arg1, arg2);
522+
}
523+
524+
/**
525+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
526+
* requires that async execution has been enabled for this domain.
527+
*
528+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
529+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
530+
* workflow actually starts.
531+
*
532+
* @param workflow The only supported value is method reference to a proxy created through {@link
533+
* #newWorkflowStub(Class, WorkflowOptions)}.
534+
* @param arg1 first workflow argument
535+
* @param arg2 second workflow argument
536+
* @param arg3 third workflow argument
537+
* @return WorkflowExecution containing only the workflowId
538+
*/
539+
static <A1, A2, A3> WorkflowExecution enqueueStart(
540+
Functions.Proc3<A1, A2, A3> workflow, A1 arg1, A2 arg2, A3 arg3) {
541+
return WorkflowClientInternal.enqueueStart(workflow, arg1, arg2, arg3);
542+
}
543+
544+
/**
545+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
546+
* requires that async execution has been enabled for this domain.
547+
*
548+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
549+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
550+
* workflow actually starts.
551+
*
552+
* @param workflow The only supported value is method reference to a proxy created through {@link
553+
* #newWorkflowStub(Class, WorkflowOptions)}.
554+
* @param arg1 first workflow function parameter
555+
* @param arg2 second workflow function parameter
556+
* @param arg3 third workflow function parameter
557+
* @param arg4 fourth workflow function parameter
558+
* @return WorkflowExecution containing only the workflowId
559+
*/
560+
static <A1, A2, A3, A4> WorkflowExecution enqueueStart(
561+
Functions.Proc4<A1, A2, A3, A4> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
562+
return WorkflowClientInternal.enqueueStart(workflow, arg1, arg2, arg3, arg4);
563+
}
564+
565+
/**
566+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
567+
* requires that async execution has been enabled for this domain.
568+
*
569+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
570+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
571+
* workflow actually starts.
572+
*
573+
* @param workflow The only supported value is method reference to a proxy created through {@link
574+
* #newWorkflowStub(Class, WorkflowOptions)}.
575+
* @param arg1 first workflow function parameter
576+
* @param arg2 second workflow function parameter
577+
* @param arg3 third workflow function parameter
578+
* @param arg4 fourth workflow function parameter
579+
* @param arg5 fifth workflow function parameter
580+
* @return WorkflowExecution containing only the workflowId
581+
*/
582+
static <A1, A2, A3, A4, A5> WorkflowExecution enqueueStart(
583+
Functions.Proc5<A1, A2, A3, A4, A5> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5) {
584+
return WorkflowClientInternal.enqueueStart(workflow, arg1, arg2, arg3, arg4, arg5);
585+
}
586+
587+
/**
588+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
589+
* requires that async execution has been enabled for this domain.
590+
*
591+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
592+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
593+
* workflow actually starts.
594+
*
595+
* @param workflow The only supported value is method reference to a proxy created through {@link
596+
* #newWorkflowStub(Class, WorkflowOptions)}.
597+
* @param arg1 first workflow function parameter
598+
* @param arg2 second workflow function parameter
599+
* @param arg3 third workflow function parameter
600+
* @param arg4 fourth workflow function parameter
601+
* @param arg5 sixth workflow function parameter
602+
* @param arg6 sixth workflow function parameter
603+
* @return WorkflowExecution containing only the workflowId
604+
*/
605+
static <A1, A2, A3, A4, A5, A6> WorkflowExecution enqueueStart(
606+
Functions.Proc6<A1, A2, A3, A4, A5, A6> workflow,
607+
A1 arg1,
608+
A2 arg2,
609+
A3 arg3,
610+
A4 arg4,
611+
A5 arg5,
612+
A6 arg6) {
613+
return WorkflowClientInternal.enqueueStart(workflow, arg1, arg2, arg3, arg4, arg5, arg6);
614+
}
615+
616+
/**
617+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
618+
* requires that async execution has been enabled for this domain.
619+
*
620+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
621+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
622+
* workflow actually starts.
623+
*
624+
* @param workflow The only supported value is method reference to a proxy created through {@link
625+
* #newWorkflowStub(Class, WorkflowOptions)}.
626+
* @return WorkflowExecution containing only the workflowId
627+
*/
628+
static <R> WorkflowExecution enqueueStart(Functions.Func<R> workflow) {
629+
return WorkflowClientInternal.enqueueStart(workflow);
630+
}
631+
632+
/**
633+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
634+
* requires that async execution has been enabled for this domain.
635+
*
636+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
637+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
638+
* workflow actually starts.
639+
*
640+
* @param workflow The only supported value is method reference to a proxy created through {@link
641+
* #newWorkflowStub(Class, WorkflowOptions)}.
642+
* @param arg1 first workflow function parameter
643+
* @return WorkflowExecution containing only the workflowId
644+
*/
645+
static <A1, R> WorkflowExecution enqueueStart(Functions.Func1<A1, R> workflow, A1 arg1) {
646+
return WorkflowClientInternal.enqueueStart(workflow, arg1);
647+
}
648+
649+
/**
650+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
651+
* requires that async execution has been enabled for this domain.
652+
*
653+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
654+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
655+
* workflow actually starts.
656+
*
657+
* @param workflow The only supported value is method reference to a proxy created through {@link
658+
* #newWorkflowStub(Class, WorkflowOptions)}.
659+
* @param arg1 first workflow function parameter
660+
* @param arg2 second workflow function parameter
661+
* @return WorkflowExecution containing only the workflowId
662+
*/
663+
static <A1, A2, R> WorkflowExecution enqueueStart(
664+
Functions.Func2<A1, A2, R> workflow, A1 arg1, A2 arg2) {
665+
return WorkflowClientInternal.enqueueStart(workflow, arg1, arg2);
666+
}
667+
668+
/**
669+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
670+
* requires that async execution has been enabled for this domain.
671+
*
672+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
673+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
674+
* workflow actually starts.
675+
*
676+
* @param workflow The only supported value is method reference to a proxy created through {@link
677+
* #newWorkflowStub(Class, WorkflowOptions)}.
678+
* @param arg1 first workflow function parameter
679+
* @param arg2 second workflow function parameter
680+
* @param arg3 third workflow function parameter
681+
* @return WorkflowExecution containing only the workflowId
682+
*/
683+
static <A1, A2, A3, R> WorkflowExecution enqueueStart(
684+
Functions.Func3<A1, A2, A3, R> workflow, A1 arg1, A2 arg2, A3 arg3) {
685+
return WorkflowClientInternal.enqueueStart(workflow, arg1, arg2, arg3);
686+
}
687+
688+
/**
689+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
690+
* requires that async execution has been enabled for this domain.
691+
*
692+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
693+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
694+
* workflow actually starts.
695+
*
696+
* @param workflow The only supported value is method reference to a proxy created through {@link
697+
* #newWorkflowStub(Class, WorkflowOptions)}.
698+
* @param arg1 first workflow function parameter
699+
* @param arg2 second workflow function parameter
700+
* @param arg3 third workflow function parameter
701+
* @param arg4 fourth workflow function parameter
702+
* @return WorkflowExecution containing only the workflowId
703+
*/
704+
static <A1, A2, A3, A4, R> WorkflowExecution enqueueStart(
705+
Functions.Func4<A1, A2, A3, A4, R> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
706+
return WorkflowClientInternal.enqueueStart(workflow, arg1, arg2, arg3, arg4);
707+
}
708+
709+
/**
710+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
711+
* requires that async execution has been enabled for this domain.
712+
*
713+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
714+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
715+
* workflow actually starts.
716+
*
717+
* @param workflow The only supported value is method reference to a proxy created through {@link
718+
* #newWorkflowStub(Class, WorkflowOptions)}.
719+
* @param arg1 first workflow function parameter
720+
* @param arg2 second workflow function parameter
721+
* @param arg3 third workflow function parameter
722+
* @param arg4 fourth workflow function parameter
723+
* @param arg5 fifth workflow function parameter
724+
* @return WorkflowExecution containing only the workflowId
725+
*/
726+
static <A1, A2, A3, A4, A5, R> WorkflowExecution enqueueStart(
727+
Functions.Func5<A1, A2, A3, A4, A5, R> workflow,
728+
A1 arg1,
729+
A2 arg2,
730+
A3 arg3,
731+
A4 arg4,
732+
A5 arg5) {
733+
return WorkflowClientInternal.enqueueStart(workflow, arg1, arg2, arg3, arg4, arg5);
734+
}
735+
736+
/**
737+
* Schedules a workflow to be started at a future date via StartWorkflowExecutionAsync. This
738+
* requires that async execution has been enabled for this domain.
739+
*
740+
* <p>Note that the returned WorkflowExecution will <b>NOT</b> contain a {@code runId}, only a
741+
* {@code workflowId}. This is because the {@code runId} is only determined at the time the
742+
* workflow actually starts.
743+
*
744+
* @param workflow The only supported value is method reference to a proxy created through {@link
745+
* #newWorkflowStub(Class, WorkflowOptions)}.
746+
* @param arg1 first workflow function parameter
747+
* @param arg2 second workflow function parameter
748+
* @param arg3 third workflow function parameter
749+
* @param arg4 fourth workflow function parameter
750+
* @param arg5 sixth workflow function parameter
751+
* @param arg6 sixth workflow function parameter
752+
* @return WorkflowExecution containing only the workflowId
753+
*/
754+
static <A1, A2, A3, A4, A5, A6, R> WorkflowExecution enqueueStart(
755+
Functions.Func6<A1, A2, A3, A4, A5, A6, R> workflow,
756+
A1 arg1,
757+
A2 arg2,
758+
A3 arg3,
759+
A4 arg4,
760+
A5 arg5,
761+
A6 arg6) {
762+
return WorkflowClientInternal.enqueueStart(workflow, arg1, arg2, arg3, arg4, arg5, arg6);
763+
}
764+
472765
/**
473766
* Executes zero argument workflow with void return type
474767
*

src/main/java/com/uber/cadence/internal/sync/WorkflowClientInternal.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,98 @@ public static <A1, A2, A3, A4, A5, A6, R> WorkflowExecution start(
311311
return start(() -> workflow.apply(arg1, arg2, arg3, arg4, arg5, arg6));
312312
}
313313

314+
public static WorkflowExecution enqueueStart(Functions.Proc workflow) {
315+
WorkflowInvocationHandler.initAsyncInvocation(InvocationType.ENQUEUE_START);
316+
try {
317+
workflow.apply();
318+
return WorkflowInvocationHandler.getAsyncInvocationResult(WorkflowExecution.class);
319+
} finally {
320+
WorkflowInvocationHandler.closeAsyncInvocation();
321+
}
322+
}
323+
324+
public static <A1> WorkflowExecution enqueueStart(Functions.Proc1<A1> workflow, A1 arg1) {
325+
return enqueueStart(() -> workflow.apply(arg1));
326+
}
327+
328+
public static <A1, A2> WorkflowExecution enqueueStart(
329+
Functions.Proc2<A1, A2> workflow, A1 arg1, A2 arg2) {
330+
return enqueueStart(() -> workflow.apply(arg1, arg2));
331+
}
332+
333+
public static <A1, A2, A3> WorkflowExecution enqueueStart(
334+
Functions.Proc3<A1, A2, A3> workflow, A1 arg1, A2 arg2, A3 arg3) {
335+
return enqueueStart(() -> workflow.apply(arg1, arg2, arg3));
336+
}
337+
338+
public static <A1, A2, A3, A4> WorkflowExecution enqueueStart(
339+
Functions.Proc4<A1, A2, A3, A4> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
340+
return enqueueStart(() -> workflow.apply(arg1, arg2, arg3, arg4));
341+
}
342+
343+
public static <A1, A2, A3, A4, A5> WorkflowExecution enqueueStart(
344+
Functions.Proc5<A1, A2, A3, A4, A5> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5) {
345+
return enqueueStart(() -> workflow.apply(arg1, arg2, arg3, arg4, arg5));
346+
}
347+
348+
public static <A1, A2, A3, A4, A5, A6> WorkflowExecution enqueueStart(
349+
Functions.Proc6<A1, A2, A3, A4, A5, A6> workflow,
350+
A1 arg1,
351+
A2 arg2,
352+
A3 arg3,
353+
A4 arg4,
354+
A5 arg5,
355+
A6 arg6) {
356+
return enqueueStart(() -> workflow.apply(arg1, arg2, arg3, arg4, arg5, arg6));
357+
}
358+
359+
public static <R> WorkflowExecution enqueueStart(Functions.Func<R> workflow) {
360+
return enqueueStart(
361+
() -> {
362+
workflow.apply();
363+
});
364+
}
365+
366+
public static <A1, R> WorkflowExecution enqueueStart(Functions.Func1<A1, R> workflow, A1 arg1) {
367+
return enqueueStart(() -> workflow.apply(arg1));
368+
}
369+
370+
public static <A1, A2, R> WorkflowExecution enqueueStart(
371+
Functions.Func2<A1, A2, R> workflow, A1 arg1, A2 arg2) {
372+
return enqueueStart(() -> workflow.apply(arg1, arg2));
373+
}
374+
375+
public static <A1, A2, A3, R> WorkflowExecution enqueueStart(
376+
Functions.Func3<A1, A2, A3, R> workflow, A1 arg1, A2 arg2, A3 arg3) {
377+
return enqueueStart(() -> workflow.apply(arg1, arg2, arg3));
378+
}
379+
380+
public static <A1, A2, A3, A4, R> WorkflowExecution enqueueStart(
381+
Functions.Func4<A1, A2, A3, A4, R> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
382+
return enqueueStart(() -> workflow.apply(arg1, arg2, arg3, arg4));
383+
}
384+
385+
public static <A1, A2, A3, A4, A5, R> WorkflowExecution enqueueStart(
386+
Functions.Func5<A1, A2, A3, A4, A5, R> workflow,
387+
A1 arg1,
388+
A2 arg2,
389+
A3 arg3,
390+
A4 arg4,
391+
A5 arg5) {
392+
return enqueueStart(() -> workflow.apply(arg1, arg2, arg3, arg4, arg5));
393+
}
394+
395+
public static <A1, A2, A3, A4, A5, A6, R> WorkflowExecution enqueueStart(
396+
Functions.Func6<A1, A2, A3, A4, A5, A6, R> workflow,
397+
A1 arg1,
398+
A2 arg2,
399+
A3 arg3,
400+
A4 arg4,
401+
A5 arg5,
402+
A6 arg6) {
403+
return enqueueStart(() -> workflow.apply(arg1, arg2, arg3, arg4, arg5, arg6));
404+
}
405+
314406
@SuppressWarnings("unchecked")
315407
public static CompletableFuture<Void> execute(Functions.Proc workflow) {
316408
WorkflowInvocationHandler.initAsyncInvocation(InvocationType.EXECUTE);

0 commit comments

Comments
 (0)