|
5 | 5 | import io.iworkflow.core.exceptions.WorkflowAlreadyStartedException; |
6 | 6 | import io.iworkflow.core.exceptions.WorkflowNotExistsException; |
7 | 7 | import io.iworkflow.core.persistence.PersistenceOptions; |
8 | | -import io.iworkflow.gen.models.ErrorSubStatus; |
9 | | -import io.iworkflow.gen.models.KeyValue; |
10 | | -import io.iworkflow.gen.models.SearchAttribute; |
11 | | -import io.iworkflow.gen.models.SearchAttributeKeyAndType; |
12 | | -import io.iworkflow.gen.models.SearchAttributeValueType; |
13 | | -import io.iworkflow.gen.models.StateCompletionOutput; |
14 | | -import io.iworkflow.gen.models.WorkflowGetDataObjectsResponse; |
15 | | -import io.iworkflow.gen.models.WorkflowGetResponse; |
16 | | -import io.iworkflow.gen.models.WorkflowGetSearchAttributesResponse; |
17 | | -import io.iworkflow.gen.models.WorkflowSearchRequest; |
18 | | -import io.iworkflow.gen.models.WorkflowSearchResponse; |
| 8 | +import io.iworkflow.gen.models.*; |
19 | 9 | import io.iworkflow.gen.models.WorkflowStateOptions; |
20 | 10 | import net.bytebuddy.ByteBuddy; |
21 | 11 | import net.bytebuddy.implementation.MethodDelegation; |
|
25 | 15 |
|
26 | 16 | import java.lang.reflect.Constructor; |
27 | 17 | import java.lang.reflect.InvocationTargetException; |
28 | | -import java.util.ArrayList; |
29 | | -import java.util.HashMap; |
30 | | -import java.util.List; |
31 | | -import java.util.Map; |
32 | | -import java.util.Optional; |
| 18 | +import java.util.*; |
33 | 19 | import java.util.stream.Collectors; |
34 | 20 |
|
35 | 21 | import static io.iworkflow.core.WorkflowState.shouldSkipWaitUntil; |
@@ -505,6 +491,94 @@ public void signalWorkflow( |
505 | 491 | signalWorkflow(workflowClass, workflowId, "", signalChannelName, signalValue); |
506 | 492 | } |
507 | 493 |
|
| 494 | + /** |
| 495 | + * Send a single empty message to internalChannel |
| 496 | + * |
| 497 | + * @param workflowClass required |
| 498 | + * @param workflowId required |
| 499 | + * @param internalChannelName required |
| 500 | + * @throws NoRunningWorkflowException if the workflow is not existing or not running |
| 501 | + */ |
| 502 | + public void publishToInternalChannel( |
| 503 | + final Class<? extends ObjectWorkflow> workflowClass, |
| 504 | + final String workflowId, |
| 505 | + final String internalChannelName) { |
| 506 | + publishToInternalChannel(workflowClass, workflowId, "", internalChannelName, null); |
| 507 | + } |
| 508 | + |
| 509 | + /** |
| 510 | + * Send a single message to internalChannel |
| 511 | + * |
| 512 | + * @param workflowClass required |
| 513 | + * @param workflowId required |
| 514 | + * @param internalChannelName required |
| 515 | + * @param channelMessage optional, can be null. |
| 516 | + * @throws NoRunningWorkflowException if the workflow is not existing or not running |
| 517 | + */ |
| 518 | + public void publishToInternalChannel( |
| 519 | + final Class<? extends ObjectWorkflow> workflowClass, |
| 520 | + final String workflowId, |
| 521 | + final String internalChannelName, |
| 522 | + final Object channelMessage) { |
| 523 | + publishToInternalChannel(workflowClass, workflowId, "", internalChannelName, channelMessage); |
| 524 | + } |
| 525 | + |
| 526 | + /** |
| 527 | + * Send a single message to internalChannel |
| 528 | + * |
| 529 | + * @param workflowClass required |
| 530 | + * @param workflowId required |
| 531 | + * @param workflowRunId optional, can be empty |
| 532 | + * @param internalChannelName required |
| 533 | + * @param channelMessage optional, can be null. |
| 534 | + * @throws NoRunningWorkflowException if the workflow is not existing or not running |
| 535 | + */ |
| 536 | + public void publishToInternalChannel( |
| 537 | + final Class<? extends ObjectWorkflow> workflowClass, |
| 538 | + final String workflowId, |
| 539 | + final String workflowRunId, |
| 540 | + final String internalChannelName, |
| 541 | + final Object channelMessage) { |
| 542 | + publishToInternalChannelBatch(workflowClass, workflowId, workflowRunId, internalChannelName, Arrays.asList(channelMessage)); |
| 543 | + } |
| 544 | + |
| 545 | + /** |
| 546 | + * Send a batch of messages to internalChannel |
| 547 | + * |
| 548 | + * @param workflowClass required |
| 549 | + * @param workflowId required |
| 550 | + * @param workflowRunId optional, can be empty |
| 551 | + * @param internalChannelName required |
| 552 | + * @param channelMessages messages in batch |
| 553 | + * @throws NoRunningWorkflowException if the workflow is not existing or not running |
| 554 | + */ |
| 555 | + public void publishToInternalChannelBatch( |
| 556 | + final Class<? extends ObjectWorkflow> workflowClass, |
| 557 | + final String workflowId, |
| 558 | + final String workflowRunId, |
| 559 | + final String internalChannelName, |
| 560 | + final List<Object> channelMessages) { |
| 561 | + final String wfType = workflowClass.getSimpleName(); |
| 562 | + |
| 563 | + checkWorkflowTypeExists(wfType); |
| 564 | + |
| 565 | + final Class<?> channelValueType = registry.getInternalChannelTypeStore(wfType).getType(internalChannelName); |
| 566 | + |
| 567 | + List<InterStateChannelPublishing> rawMessages = new ArrayList<>(channelMessages.size()); |
| 568 | + for (Object channelValue : channelMessages) { |
| 569 | + if (channelValue != null && !channelValueType.isInstance(channelValue)) { |
| 570 | + throw new IllegalArgumentException(String.format("message value is not of channel type %s", channelValueType.getName())); |
| 571 | + } |
| 572 | + rawMessages.add( |
| 573 | + new InterStateChannelPublishing() |
| 574 | + .channelName(internalChannelName) |
| 575 | + .value(clientOptions.getObjectEncoder().encode(channelValue)) |
| 576 | + ); |
| 577 | + } |
| 578 | + |
| 579 | + unregisteredClient.publishToInternalChannel(workflowId, workflowRunId, rawMessages); |
| 580 | + } |
| 581 | + |
508 | 582 | /** |
509 | 583 | * @param workflowId required |
510 | 584 | * @param workflowRunId optional, can be empty |
|
0 commit comments