|
| 1 | +/* |
| 2 | + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved |
| 3 | + * |
| 4 | + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 5 | + * |
| 6 | + * Modifications copyright (C) 2017 Uber Technologies, Inc. |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not |
| 9 | + * use this file except in compliance with the License. A copy of the License is |
| 10 | + * located at |
| 11 | + * |
| 12 | + * http://aws.amazon.com/apache2.0 |
| 13 | + * |
| 14 | + * or in the "license" file accompanying this file. This file is distributed on |
| 15 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 16 | + * express or implied. See the License for the specific language governing |
| 17 | + * permissions and limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package io.temporal.samples.moneybatch; |
| 21 | + |
| 22 | +import io.temporal.client.BatchRequest; |
| 23 | +import io.temporal.client.WorkflowClient; |
| 24 | +import io.temporal.client.WorkflowOptions; |
| 25 | +import io.temporal.serviceclient.WorkflowServiceStubs; |
| 26 | +import java.util.Random; |
| 27 | +import java.util.UUID; |
| 28 | + |
| 29 | +public class TransferRequester { |
| 30 | + |
| 31 | + /** Number of withdrawals to batch */ |
| 32 | + public static final int BATCH_SIZE = 3; |
| 33 | + |
| 34 | + @SuppressWarnings("CatchAndPrintStackTrace") |
| 35 | + public static void main(String[] args) { |
| 36 | + String reference = UUID.randomUUID().toString(); |
| 37 | + int amountCents = (new Random().nextInt(5) + 1) * 25; |
| 38 | + WorkflowServiceStubs service = WorkflowServiceStubs.newInstance(); |
| 39 | + WorkflowClient workflowClient = WorkflowClient.newInstance(service); |
| 40 | + |
| 41 | + String from = "account1"; |
| 42 | + String to = "account2"; |
| 43 | + WorkflowOptions options = |
| 44 | + WorkflowOptions.newBuilder() |
| 45 | + .setTaskList(AccountActivityWorker.TASK_LIST) |
| 46 | + .setWorkflowId(to) |
| 47 | + .build(); |
| 48 | + AccountTransferWorkflow transferWorkflow = |
| 49 | + workflowClient.newWorkflowStub(AccountTransferWorkflow.class, options); |
| 50 | + // Signal with start sends a signal to a workflow starting it if not yet running |
| 51 | + BatchRequest request = workflowClient.newSignalWithStartRequest(); |
| 52 | + request.add(transferWorkflow::deposit, to, BATCH_SIZE); |
| 53 | + request.add(transferWorkflow::withdraw, from, reference, amountCents); |
| 54 | + workflowClient.signalWithStart(request); |
| 55 | + |
| 56 | + System.out.printf("Transfer of %d cents from %s to %s requested", amountCents, from, to); |
| 57 | + System.exit(0); |
| 58 | + } |
| 59 | +} |
0 commit comments