Skip to content

Commit 69817e0

Browse files
committed
Sdk new changes
1 parent 99e21db commit 69817e0

File tree

11 files changed

+54
-57
lines changed

11 files changed

+54
-57
lines changed

dapr-spring/dapr-spring-workflows/src/main/java/io/dapr/spring/workflows/config/DaprWorkflowsConfiguration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ private void registerWorkflowsAndActivities(ApplicationContext applicationContex
4646
workflowRuntimeBuilder.registerActivity(activity);
4747
}
4848

49-
try (WorkflowRuntime runtime = workflowRuntimeBuilder.build()) {
50-
LOGGER.info("Starting workflow runtime ... ");
51-
runtime.start(false);
52-
}
49+
WorkflowRuntime runtime = workflowRuntimeBuilder.build();
50+
LOGGER.info("Starting workflow runtime ... ");
51+
runtime.start(false);
5352
}
5453

5554
@Override

examples/src/main/java/io/dapr/examples/workflows/chain/DemoChainWorker.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ public static void main(String[] args) throws Exception {
2929
builder.registerActivity(ToUpperCaseActivity.class);
3030

3131
// Build and then start the workflow runtime pulling and executing tasks
32-
try (WorkflowRuntime runtime = builder.build()) {
33-
System.out.println("Start workflow runtime");
34-
runtime.start();
35-
}
32+
WorkflowRuntime runtime = builder.build();
33+
System.out.println("Start workflow runtime");
34+
runtime.start();
3635
}
3736
}

examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflowWorker.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ public static void main(String[] args) throws Exception {
3131
builder.registerActivity(ReverseActivity.class);
3232

3333
// Build and then start the workflow runtime pulling and executing tasks
34-
try (WorkflowRuntime runtime = builder.build()) {
35-
System.out.println("Start workflow runtime");
36-
runtime.start();
37-
}
34+
WorkflowRuntime runtime = builder.build();
35+
System.out.println("Start workflow runtime");
3836
}
3937
}

examples/src/main/java/io/dapr/examples/workflows/continueasnew/DemoContinueAsNewWorker.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import io.dapr.workflows.runtime.WorkflowRuntime;
1717
import io.dapr.workflows.runtime.WorkflowRuntimeBuilder;
1818

19+
import java.util.concurrent.ExecutorService;
20+
import java.util.concurrent.Executors;
21+
1922
public class DemoContinueAsNewWorker {
2023
/**
2124
* The main method of this app.
@@ -25,13 +28,14 @@ public class DemoContinueAsNewWorker {
2528
*/
2629
public static void main(String[] args) throws Exception {
2730
// Register the Workflow with the builder.
28-
WorkflowRuntimeBuilder builder = new WorkflowRuntimeBuilder().registerWorkflow(DemoContinueAsNewWorkflow.class);
31+
WorkflowRuntimeBuilder builder = new WorkflowRuntimeBuilder().
32+
registerWorkflow(DemoContinueAsNewWorkflow.class)
33+
.withExecutorService(Executors.newFixedThreadPool(3));
2934
builder.registerActivity(CleanUpActivity.class);
3035

3136
// Build and then start the workflow runtime pulling and executing tasks
32-
try (WorkflowRuntime runtime = builder.build()) {
33-
System.out.println("Start workflow runtime");
34-
runtime.start();
35-
}
37+
WorkflowRuntime runtime = builder.build()
38+
System.out.println("Start workflow runtime");
39+
runtime.start();
3640
}
3741
}

examples/src/main/java/io/dapr/examples/workflows/externalevent/DemoExternalEventWorker.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ public static void main(String[] args) throws Exception {
3030
builder.registerActivity(DenyActivity.class);
3131

3232
// Build and then start the workflow runtime pulling and executing tasks
33-
try (WorkflowRuntime runtime = builder.build()) {
34-
System.out.println("Start workflow runtime");
35-
runtime.start();
36-
}
33+
WorkflowRuntime runtime = builder.build();
34+
System.out.println("Start workflow runtime");
35+
runtime.start();
3736
}
3837
}

examples/src/main/java/io/dapr/examples/workflows/faninout/DemoFanInOutWorker.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ public static void main(String[] args) throws Exception {
2929
builder.registerActivity(CountWordsActivity.class);
3030

3131
// Build and then start the workflow runtime pulling and executing tasks
32-
try (WorkflowRuntime runtime = builder.build()) {
33-
System.out.println("Start workflow runtime");
34-
runtime.start();
35-
}
32+
WorkflowRuntime runtime = builder.build();
33+
System.out.println("Start workflow runtime");
34+
runtime.start(false);
3635
}
3736
}

examples/src/main/java/io/dapr/examples/workflows/faninout/DemoFanInOutWorkflow.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ public WorkflowStub create() {
3737
.map(input -> ctx.callActivity(CountWordsActivity.class.getName(), input.toString(), Integer.class))
3838
.collect(Collectors.toList());
3939

40+
List<Task<Integer>> tasks2 = inputs.stream()
41+
.map(input -> ctx.callActivity(CountWordsActivity2.class.getName(), input.toString(), Integer.class))
42+
.collect(Collectors.toList());
43+
4044
// Fan-in to get the total word count from all the individual activity results.
4145
List<Integer> allWordCountResults = ctx.allOf(tasks).await();
46+
List<Integer> allWordCountResults2 = ctx.allOf(tasks2).await();
4247
int totalWordCount = allWordCountResults.stream().mapToInt(Integer::intValue).sum();
4348

4449
ctx.getLogger().info("Workflow finished with result: " + totalWordCount);

sdk-workflows/src/main/java/io/dapr/workflows/runtime/WorkflowRuntime.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* Contains methods to register workflows and activities.
2020
*/
21-
public class WorkflowRuntime implements AutoCloseable {
21+
public class WorkflowRuntime {
2222

2323
private DurableTaskGrpcWorker worker;
2424

@@ -46,15 +46,4 @@ public void start(boolean block) {
4646
this.worker.start();
4747
}
4848
}
49-
50-
/**
51-
* {@inheritDoc}
52-
*/
53-
@Override
54-
public void close() {
55-
if (this.worker != null) {
56-
this.worker.close();
57-
this.worker = null;
58-
}
59-
}
6049
}

sdk-workflows/src/main/java/io/dapr/workflows/runtime/WorkflowRuntimeBuilder.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.Collections;
2727
import java.util.HashSet;
2828
import java.util.Set;
29+
import java.util.concurrent.ExecutorService;
30+
import java.util.concurrent.Executors;
2931

3032
public class WorkflowRuntimeBuilder {
3133
private static final ClientInterceptor WORKFLOW_INTERCEPTOR = new ApiTokenClientInterceptor();
@@ -59,7 +61,9 @@ public WorkflowRuntimeBuilder(Logger logger) {
5961

6062
private WorkflowRuntimeBuilder(Properties properties, Logger logger) {
6163
ManagedChannel managedChannel = NetworkUtils.buildGrpcManagedChannel(properties, WORKFLOW_INTERCEPTOR);
62-
this.builder = new DurableTaskGrpcWorkerBuilder().grpcChannel(managedChannel);
64+
this.builder = new DurableTaskGrpcWorkerBuilder()
65+
.withExecutorService(Executors.newCachedThreadPool())
66+
.grpcChannel(managedChannel);
6367
this.logger = logger;
6468
}
6569

@@ -84,6 +88,17 @@ public WorkflowRuntime build() {
8488
return instance;
8589
}
8690

91+
/**
92+
* Register Executor Service to use with workflow.
93+
*
94+
* @param executorService to be used.
95+
* @return {@link WorkflowRuntimeBuilder}.
96+
*/
97+
public WorkflowRuntimeBuilder withExecutorService(ExecutorService executorService) {
98+
this.builder.withExecutorService(executorService);
99+
return this;
100+
}
101+
87102
/**
88103
* Registers a Workflow object.
89104
*

sdk-workflows/src/test/java/io/dapr/workflows/runtime/WorkflowRuntimeBuilderTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public void registerValidWorkflowActivityInstance() {
6767
@Test
6868
public void buildTest() {
6969
assertDoesNotThrow(() -> {
70-
try (WorkflowRuntime runtime = new WorkflowRuntimeBuilder().build()) {
70+
try {
71+
WorkflowRuntime runtime = new WorkflowRuntimeBuilder().build();
7172
System.out.println("WorkflowRuntime created");
7273
} catch (Exception e) {
7374
throw new RuntimeException(e);
@@ -88,13 +89,11 @@ public void loggingOutputTest() {
8889

8990
WorkflowRuntimeBuilder workflowRuntimeBuilder = new WorkflowRuntimeBuilder();
9091

91-
try (WorkflowRuntime runtime = workflowRuntimeBuilder.build()) {
92-
verify(testLogger, times(1))
93-
.info(eq("Registered Workflow: {}"), eq("TestWorkflow"));
92+
WorkflowRuntime runtime = workflowRuntimeBuilder.build();
93+
verify(testLogger, times(1))
94+
.info(eq("Registered Workflow: {}"), eq("TestWorkflow"));
9495

95-
verify(testLogger, times(1))
96-
.info(eq("Registered Activity: {}"), eq("TestActivity"));
97-
}
96+
verify(testLogger, times(1))
97+
.info(eq("Registered Activity: {}"), eq("TestActivity"));
9898
}
99-
10099
}

0 commit comments

Comments
 (0)