|
| 1 | +/* |
| 2 | + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Modifications copyright (C) 2017 Uber Technologies, Inc. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not |
| 7 | + * use this file except in compliance with the License. A copy of the License is |
| 8 | + * located at |
| 9 | + * |
| 10 | + * http://aws.amazon.com/apache2.0 |
| 11 | + * |
| 12 | + * or in the "license" file accompanying this file. This file is distributed on |
| 13 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 14 | + * express or implied. See the License for the specific language governing |
| 15 | + * permissions and limitations under the License. |
| 16 | + */ |
| 17 | + |
1 | 18 | package com.uber.cadence.samples.shadowing;
|
2 | 19 |
|
| 20 | +import static com.uber.cadence.samples.common.SampleConstants.DOMAIN; |
| 21 | + |
3 | 22 | import com.google.common.collect.Lists;
|
4 | 23 | import com.uber.cadence.client.WorkflowClient;
|
5 | 24 | import com.uber.cadence.client.WorkflowClientOptions;
|
|
12 | 31 | import com.uber.cadence.worker.ShadowingWorker;
|
13 | 32 | import com.uber.cadence.worker.WorkerOptions;
|
14 | 33 | import com.uber.cadence.worker.WorkflowStatus;
|
15 |
| - |
16 | 34 | import java.util.concurrent.CountDownLatch;
|
17 | 35 |
|
18 |
| -import static com.uber.cadence.samples.common.SampleConstants.DOMAIN; |
19 |
| - |
20 | 36 | public class ShadowTraffic {
|
21 |
| - public static void main(String[] args) throws InterruptedException { |
22 |
| - // Get a new client |
23 |
| - // NOTE: to set a different options, you can do like this: |
24 |
| - // ClientOptions.newBuilder().setRpcTimeout(5 * 1000).build(); |
25 |
| - WorkflowClient workflowClient = |
26 |
| - WorkflowClient.newInstance( |
27 |
| - new WorkflowServiceTChannel(ClientOptions.defaultInstance()), |
28 |
| - WorkflowClientOptions.newBuilder().setDomain(DOMAIN).build()); |
29 |
| - ShadowingOptions options = ShadowingOptions |
30 |
| - .newBuilder() |
31 |
| - .setDomain(DOMAIN) |
32 |
| - .setShadowMode(Mode.Normal) |
33 |
| - .setWorkflowTypes(Lists.newArrayList("GreetingWorkflow::getGreeting")) |
34 |
| - .setWorkflowStatuses(Lists.newArrayList(WorkflowStatus.OPEN, WorkflowStatus.CLOSED)) |
35 |
| - .setExitCondition(new ExitCondition().setExpirationIntervalInSeconds(60)) |
36 |
| - .build(); |
| 37 | + public static void main(String[] args) throws InterruptedException { |
| 38 | + // Get a new client |
| 39 | + // NOTE: to set a different options, you can do like this: |
| 40 | + // ClientOptions.newBuilder().setRpcTimeout(5 * 1000).build(); |
| 41 | + WorkflowClient workflowClient = |
| 42 | + WorkflowClient.newInstance( |
| 43 | + new WorkflowServiceTChannel(ClientOptions.defaultInstance()), |
| 44 | + WorkflowClientOptions.newBuilder().setDomain(DOMAIN).build()); |
| 45 | + ShadowingOptions options = |
| 46 | + ShadowingOptions.newBuilder() |
| 47 | + .setDomain(DOMAIN) |
| 48 | + .setShadowMode(Mode.Normal) |
| 49 | + .setWorkflowTypes(Lists.newArrayList("GreetingWorkflow::getGreeting")) |
| 50 | + .setWorkflowStatuses(Lists.newArrayList(WorkflowStatus.OPEN, WorkflowStatus.CLOSED)) |
| 51 | + .setExitCondition(new ExitCondition().setExpirationIntervalInSeconds(60)) |
| 52 | + .build(); |
37 | 53 |
|
38 |
| - ShadowingWorker shadowingWorker = new ShadowingWorker( |
39 |
| - workflowClient, |
40 |
| - "HelloActivity", |
41 |
| - WorkerOptions.defaultInstance(), |
42 |
| - options); |
43 |
| - shadowingWorker.registerWorkflowImplementationTypes(HelloActivity.GreetingWorkflowImpl.class); |
| 54 | + ShadowingWorker shadowingWorker = |
| 55 | + new ShadowingWorker( |
| 56 | + workflowClient, "HelloActivity", WorkerOptions.defaultInstance(), options); |
| 57 | + shadowingWorker.registerWorkflowImplementationTypes(HelloActivity.GreetingWorkflowImpl.class); |
44 | 58 |
|
45 |
| - CountDownLatch latch = new CountDownLatch(1); |
46 |
| - // Execute a workflow waiting for it to complete. |
47 |
| - Runnable runnable = () -> { |
48 |
| - try { |
49 |
| - shadowingWorker.start(); |
50 |
| - } catch (Exception e) { |
51 |
| - System.out.println("Failed to start shadowing workflow"); |
52 |
| - System.out.println(e); |
53 |
| - latch.countDown(); |
54 |
| - } |
| 59 | + CountDownLatch latch = new CountDownLatch(1); |
| 60 | + // Execute a workflow waiting for it to complete. |
| 61 | + Runnable runnable = |
| 62 | + () -> { |
| 63 | + try { |
| 64 | + shadowingWorker.start(); |
| 65 | + } catch (Exception e) { |
| 66 | + System.out.println("Failed to start shadowing workflow"); |
| 67 | + System.out.println(e); |
| 68 | + latch.countDown(); |
| 69 | + } |
55 | 70 | };
|
56 |
| - runnable.run(); |
57 |
| - latch.await(); |
58 |
| - } |
| 71 | + runnable.run(); |
| 72 | + latch.await(); |
| 73 | + } |
59 | 74 | }
|
0 commit comments