|
1 | | -// // Copyright (c) Microsoft Corporation. All rights reserved. |
2 | | -// // Licensed under the MIT License. |
3 | | -// package io.durabletask.samples; |
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | +package io.durabletask.samples; |
4 | 4 |
|
5 | | -// import com.microsoft.durabletask.*; |
| 5 | +import com.microsoft.durabletask.*; |
6 | 6 |
|
7 | | -// import org.springframework.boot.SpringApplication; |
8 | | -// import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 7 | +import org.springframework.boot.SpringApplication; |
| 8 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
9 | 9 |
|
10 | | -// @SpringBootApplication |
11 | | -// public class WebApplication { |
| 10 | +@SpringBootApplication |
| 11 | +public class WebApplication { |
12 | 12 |
|
13 | | -// public static void main(String[] args) throws InterruptedException { |
14 | | -// DurableTaskGrpcWorker server = createTaskHubServer(); |
15 | | -// server.start(); |
| 13 | + public static void main(String[] args) throws InterruptedException { |
| 14 | + DurableTaskGrpcWorker server = createTaskHubServer(); |
| 15 | + server.start(); |
16 | 16 |
|
17 | | -// System.out.println("Starting up Spring web API..."); |
18 | | -// SpringApplication.run(WebApplication.class, args); |
19 | | -// } |
| 17 | + System.out.println("Starting up Spring web API..."); |
| 18 | + SpringApplication.run(WebApplication.class, args); |
| 19 | + } |
20 | 20 |
|
21 | | -// private static DurableTaskGrpcWorker createTaskHubServer() { |
22 | | -// DurableTaskGrpcWorkerBuilder builder = new DurableTaskGrpcWorkerBuilder(); |
| 21 | + private static DurableTaskGrpcWorker createTaskHubServer() { |
| 22 | + DurableTaskGrpcWorkerBuilder builder = new DurableTaskGrpcWorkerBuilder(); |
23 | 23 |
|
24 | | -// // Orchestrations can be defined inline as anonymous classes or as concrete classes |
25 | | -// builder.addOrchestration(new TaskOrchestrationFactory() { |
26 | | -// @Override |
27 | | -// public String getName() { return "ProcessOrderOrchestration"; } |
| 24 | + // Orchestrations can be defined inline as anonymous classes or as concrete classes |
| 25 | + builder.addOrchestration(new TaskOrchestrationFactory() { |
| 26 | + @Override |
| 27 | + public String getName() { return "ProcessOrderOrchestration"; } |
28 | 28 |
|
29 | | -// @Override |
30 | | -// public TaskOrchestration create() { |
31 | | -// return ctx -> { |
32 | | -// // the input is JSON and can be deserialized into the specified type |
33 | | -// String input = ctx.getInput(String.class); |
| 29 | + @Override |
| 30 | + public TaskOrchestration create() { |
| 31 | + return ctx -> { |
| 32 | + // the input is JSON and can be deserialized into the specified type |
| 33 | + String input = ctx.getInput(String.class); |
34 | 34 |
|
35 | | -// String x = ctx.callActivity("Task1", input, String.class).await(); |
36 | | -// String y = ctx.callActivity("Task2", x, String.class).await(); |
37 | | -// String z = ctx.callActivity("Task3", y, String.class).await(); |
| 35 | + String x = ctx.callActivity("Task1", input, String.class).await(); |
| 36 | + String y = ctx.callActivity("Task2", x, String.class).await(); |
| 37 | + String z = ctx.callActivity("Task3", y, String.class).await(); |
38 | 38 |
|
39 | | -// ctx.complete(z); |
40 | | -// }; |
41 | | -// } |
42 | | -// }); |
| 39 | + ctx.complete(z); |
| 40 | + }; |
| 41 | + } |
| 42 | + }); |
43 | 43 |
|
44 | | -// // Activities can be defined inline as anonymous classes or as concrete classes |
45 | | -// builder.addActivity(new TaskActivityFactory() { |
46 | | -// @Override |
47 | | -// public String getName() { return "Task1"; } |
| 44 | + // Activities can be defined inline as anonymous classes or as concrete classes |
| 45 | + builder.addActivity(new TaskActivityFactory() { |
| 46 | + @Override |
| 47 | + public String getName() { return "Task1"; } |
48 | 48 |
|
49 | | -// @Override |
50 | | -// public TaskActivity create() { |
51 | | -// return ctx -> { |
52 | | -// String input = ctx.getInput(String.class); |
53 | | -// sleep(10000); |
54 | | -// return input + "|" + ctx.getName(); |
55 | | -// }; |
56 | | -// } |
57 | | -// }); |
| 49 | + @Override |
| 50 | + public TaskActivity create() { |
| 51 | + return ctx -> { |
| 52 | + String input = ctx.getInput(String.class); |
| 53 | + sleep(10000); |
| 54 | + return input + "|" + ctx.getName(); |
| 55 | + }; |
| 56 | + } |
| 57 | + }); |
58 | 58 |
|
59 | | -// builder.addActivity(new TaskActivityFactory() { |
60 | | -// @Override |
61 | | -// public String getName() { return "Task2"; } |
| 59 | + builder.addActivity(new TaskActivityFactory() { |
| 60 | + @Override |
| 61 | + public String getName() { return "Task2"; } |
62 | 62 |
|
63 | | -// @Override |
64 | | -// public TaskActivity create() { |
65 | | -// return ctx -> { |
66 | | -// String input = ctx.getInput(String.class); |
67 | | -// sleep(10000); |
68 | | -// return input + "|" + ctx.getName(); |
69 | | -// }; |
70 | | -// } |
71 | | -// }); |
| 63 | + @Override |
| 64 | + public TaskActivity create() { |
| 65 | + return ctx -> { |
| 66 | + String input = ctx.getInput(String.class); |
| 67 | + sleep(10000); |
| 68 | + return input + "|" + ctx.getName(); |
| 69 | + }; |
| 70 | + } |
| 71 | + }); |
72 | 72 |
|
73 | | -// builder.addActivity(new TaskActivityFactory() { |
74 | | -// @Override |
75 | | -// public String getName() { return "Task3"; } |
| 73 | + builder.addActivity(new TaskActivityFactory() { |
| 74 | + @Override |
| 75 | + public String getName() { return "Task3"; } |
76 | 76 |
|
77 | | -// @Override |
78 | | -// public TaskActivity create() { |
79 | | -// return ctx -> { |
80 | | -// String input = ctx.getInput(String.class); |
81 | | -// sleep(10000); |
82 | | -// return input + "|" + ctx.getName(); |
83 | | -// }; |
84 | | -// } |
85 | | -// }); |
| 77 | + @Override |
| 78 | + public TaskActivity create() { |
| 79 | + return ctx -> { |
| 80 | + String input = ctx.getInput(String.class); |
| 81 | + sleep(10000); |
| 82 | + return input + "|" + ctx.getName(); |
| 83 | + }; |
| 84 | + } |
| 85 | + }); |
86 | 86 |
|
87 | | -// return builder.build(); |
88 | | -// } |
| 87 | + return builder.build(); |
| 88 | + } |
89 | 89 |
|
90 | | -// private static void sleep(int millis) { |
91 | | -// try { |
92 | | -// Thread.sleep(millis); |
93 | | -// } catch (InterruptedException e) { |
94 | | -// // ignore |
95 | | -// } |
96 | | -// } |
97 | | -// } |
| 90 | + private static void sleep(int millis) { |
| 91 | + try { |
| 92 | + Thread.sleep(millis); |
| 93 | + } catch (InterruptedException e) { |
| 94 | + // ignore |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments