|
9 | 9 | import java.util.function.Function; |
10 | 10 | import java.util.function.Supplier; |
11 | 11 | import software.amazon.lambda.durable.config.CallbackConfig; |
| 12 | +import software.amazon.lambda.durable.config.DistributedMapConfig; |
| 13 | +import software.amazon.lambda.durable.config.DistributedMapProcessor; |
| 14 | +import software.amazon.lambda.durable.config.DistributedMapSource; |
12 | 15 | import software.amazon.lambda.durable.config.InvokeConfig; |
13 | 16 | import software.amazon.lambda.durable.config.MapConfig; |
14 | 17 | import software.amazon.lambda.durable.config.ParallelConfig; |
|
19 | 22 | import software.amazon.lambda.durable.config.WithRetryConfig; |
20 | 23 | import software.amazon.lambda.durable.context.BaseContext; |
21 | 24 | import software.amazon.lambda.durable.exception.ChildContextFailedException; |
| 25 | +import software.amazon.lambda.durable.model.DistributedMapResult; |
| 26 | +import software.amazon.lambda.durable.model.DistributedMapSummary; |
22 | 27 | import software.amazon.lambda.durable.model.MapResult; |
23 | 28 | import software.amazon.lambda.durable.model.WaitForConditionResult; |
24 | 29 |
|
@@ -544,6 +549,212 @@ default ParallelDurableFuture parallel(String name) { |
544 | 549 | */ |
545 | 550 | ParallelDurableFuture parallel(String name, ParallelConfig config); |
546 | 551 |
|
| 552 | + // =============== distributedMap ================ |
| 553 | + |
| 554 | + /** |
| 555 | + * Runs a distributed map with default config, blocking until the run reaches a terminal state. |
| 556 | + * |
| 557 | + * @param maxConcurrency the maximum number of items processed concurrently. Required, with no service default. |
| 558 | + */ |
| 559 | + default <I> DistributedMapSummary distributedMap( |
| 560 | + String name, DistributedMapSource<I> source, DistributedMapProcessor processor, int maxConcurrency) { |
| 561 | + return distributedMapAsync( |
| 562 | + name, |
| 563 | + source, |
| 564 | + processor, |
| 565 | + maxConcurrency, |
| 566 | + DistributedMapConfig.builder().build()) |
| 567 | + .get(); |
| 568 | + } |
| 569 | + |
| 570 | + /** |
| 571 | + * Runs a distributed map, blocking until the run reaches a terminal state. |
| 572 | + * |
| 573 | + * @param maxConcurrency the maximum number of items processed concurrently. Required, with no service default. |
| 574 | + */ |
| 575 | + default <I> DistributedMapSummary distributedMap( |
| 576 | + String name, |
| 577 | + DistributedMapSource<I> source, |
| 578 | + DistributedMapProcessor processor, |
| 579 | + int maxConcurrency, |
| 580 | + DistributedMapConfig config) { |
| 581 | + return distributedMapAsync(name, source, processor, maxConcurrency, config) |
| 582 | + .get(); |
| 583 | + } |
| 584 | + |
| 585 | + /** |
| 586 | + * Runs a distributed map that collects per-item results with a TypeToken, blocking until the run reaches a terminal |
| 587 | + * state. |
| 588 | + * |
| 589 | + * @param maxConcurrency the maximum number of items processed concurrently. Required, with no service default. |
| 590 | + */ |
| 591 | + default <I, O> DistributedMapResult<O> distributedMap( |
| 592 | + String name, |
| 593 | + DistributedMapSource<I> source, |
| 594 | + DistributedMapProcessor processor, |
| 595 | + int maxConcurrency, |
| 596 | + TypeToken<O> resultType, |
| 597 | + DistributedMapConfig config) { |
| 598 | + return distributedMapAsync(name, source, processor, maxConcurrency, resultType, config) |
| 599 | + .get(); |
| 600 | + } |
| 601 | + |
| 602 | + /** |
| 603 | + * Runs a distributed map that collects per-item results with a result Class, blocking until the run reaches a |
| 604 | + * terminal state. |
| 605 | + * |
| 606 | + * @param maxConcurrency the maximum number of items processed concurrently. Required, with no service default. |
| 607 | + */ |
| 608 | + default <I, O> DistributedMapResult<O> distributedMap( |
| 609 | + String name, |
| 610 | + DistributedMapSource<I> source, |
| 611 | + DistributedMapProcessor processor, |
| 612 | + int maxConcurrency, |
| 613 | + Class<O> resultType, |
| 614 | + DistributedMapConfig config) { |
| 615 | + return distributedMapAsync(name, source, processor, maxConcurrency, TypeToken.get(resultType), config) |
| 616 | + .get(); |
| 617 | + } |
| 618 | + |
| 619 | + /** |
| 620 | + * Runs a distributed map that collects per-item results with a result Class and default config, blocking until the |
| 621 | + * run reaches a terminal state. |
| 622 | + * |
| 623 | + * @param maxConcurrency the maximum number of items processed concurrently. Required, with no service default. |
| 624 | + */ |
| 625 | + default <I, O> DistributedMapResult<O> distributedMap( |
| 626 | + String name, |
| 627 | + DistributedMapSource<I> source, |
| 628 | + DistributedMapProcessor processor, |
| 629 | + int maxConcurrency, |
| 630 | + Class<O> resultType) { |
| 631 | + return distributedMapAsync( |
| 632 | + name, |
| 633 | + source, |
| 634 | + processor, |
| 635 | + maxConcurrency, |
| 636 | + TypeToken.get(resultType), |
| 637 | + DistributedMapConfig.builder().build()) |
| 638 | + .get(); |
| 639 | + } |
| 640 | + |
| 641 | + /** |
| 642 | + * Runs a distributed map that collects per-item results with a TypeToken and default config, blocking until the run |
| 643 | + * reaches a terminal state. |
| 644 | + * |
| 645 | + * @param maxConcurrency the maximum number of items processed concurrently. Required, with no service default. |
| 646 | + */ |
| 647 | + default <I, O> DistributedMapResult<O> distributedMap( |
| 648 | + String name, |
| 649 | + DistributedMapSource<I> source, |
| 650 | + DistributedMapProcessor processor, |
| 651 | + int maxConcurrency, |
| 652 | + TypeToken<O> resultType) { |
| 653 | + return distributedMapAsync( |
| 654 | + name, |
| 655 | + source, |
| 656 | + processor, |
| 657 | + maxConcurrency, |
| 658 | + resultType, |
| 659 | + DistributedMapConfig.builder().build()) |
| 660 | + .get(); |
| 661 | + } |
| 662 | + |
| 663 | + /** |
| 664 | + * Asynchronously runs a distributed map with default config. |
| 665 | + * |
| 666 | + * @param maxConcurrency the maximum number of items processed concurrently. Required, with no service default. |
| 667 | + */ |
| 668 | + default <I> DurableFuture<DistributedMapSummary> distributedMapAsync( |
| 669 | + String name, DistributedMapSource<I> source, DistributedMapProcessor processor, int maxConcurrency) { |
| 670 | + return distributedMapAsync( |
| 671 | + name, |
| 672 | + source, |
| 673 | + processor, |
| 674 | + maxConcurrency, |
| 675 | + DistributedMapConfig.builder().build()); |
| 676 | + } |
| 677 | + |
| 678 | + /** |
| 679 | + * Asynchronously runs a distributed map. |
| 680 | + * |
| 681 | + * @param maxConcurrency the maximum number of items processed concurrently. Required, with no service default. |
| 682 | + */ |
| 683 | + <I> DurableFuture<DistributedMapSummary> distributedMapAsync( |
| 684 | + String name, |
| 685 | + DistributedMapSource<I> source, |
| 686 | + DistributedMapProcessor processor, |
| 687 | + int maxConcurrency, |
| 688 | + DistributedMapConfig config); |
| 689 | + |
| 690 | + /** |
| 691 | + * Asynchronously runs a distributed map that collects per-item results with a TypeToken. |
| 692 | + * |
| 693 | + * @param maxConcurrency the maximum number of items processed concurrently. Required, with no service default. |
| 694 | + */ |
| 695 | + <I, O> DurableFuture<DistributedMapResult<O>> distributedMapAsync( |
| 696 | + String name, |
| 697 | + DistributedMapSource<I> source, |
| 698 | + DistributedMapProcessor processor, |
| 699 | + int maxConcurrency, |
| 700 | + TypeToken<O> resultType, |
| 701 | + DistributedMapConfig config); |
| 702 | + |
| 703 | + /** |
| 704 | + * Asynchronously runs a distributed map that collects per-item results with a result Class. |
| 705 | + * |
| 706 | + * @param maxConcurrency the maximum number of items processed concurrently. Required, with no service default. |
| 707 | + */ |
| 708 | + default <I, O> DurableFuture<DistributedMapResult<O>> distributedMapAsync( |
| 709 | + String name, |
| 710 | + DistributedMapSource<I> source, |
| 711 | + DistributedMapProcessor processor, |
| 712 | + int maxConcurrency, |
| 713 | + Class<O> resultType, |
| 714 | + DistributedMapConfig config) { |
| 715 | + return distributedMapAsync(name, source, processor, maxConcurrency, TypeToken.get(resultType), config); |
| 716 | + } |
| 717 | + |
| 718 | + /** |
| 719 | + * Asynchronously runs a distributed map that collects per-item results with a result Class and default config. |
| 720 | + * |
| 721 | + * @param maxConcurrency the maximum number of items processed concurrently. Required, with no service default. |
| 722 | + */ |
| 723 | + default <I, O> DurableFuture<DistributedMapResult<O>> distributedMapAsync( |
| 724 | + String name, |
| 725 | + DistributedMapSource<I> source, |
| 726 | + DistributedMapProcessor processor, |
| 727 | + int maxConcurrency, |
| 728 | + Class<O> resultType) { |
| 729 | + return distributedMapAsync( |
| 730 | + name, |
| 731 | + source, |
| 732 | + processor, |
| 733 | + maxConcurrency, |
| 734 | + TypeToken.get(resultType), |
| 735 | + DistributedMapConfig.builder().build()); |
| 736 | + } |
| 737 | + |
| 738 | + /** |
| 739 | + * Asynchronously runs a distributed map that collects per-item results with a TypeToken and default config. |
| 740 | + * |
| 741 | + * @param maxConcurrency the maximum number of items processed concurrently. Required, with no service default. |
| 742 | + */ |
| 743 | + default <I, O> DurableFuture<DistributedMapResult<O>> distributedMapAsync( |
| 744 | + String name, |
| 745 | + DistributedMapSource<I> source, |
| 746 | + DistributedMapProcessor processor, |
| 747 | + int maxConcurrency, |
| 748 | + TypeToken<O> resultType) { |
| 749 | + return distributedMapAsync( |
| 750 | + name, |
| 751 | + source, |
| 752 | + processor, |
| 753 | + maxConcurrency, |
| 754 | + resultType, |
| 755 | + DistributedMapConfig.builder().build()); |
| 756 | + } |
| 757 | + |
547 | 758 | /** |
548 | 759 | * Executes a submitter function and waits for an external callback, blocking until the callback completes. |
549 | 760 | * |
|
0 commit comments