Skip to content

Commit 61bf7a9

Browse files
authored
25.0 Release (#18)
* Error handling and other proto changes in Java SDK (#17) * Updated temporal-sdk version to 0.25.0
1 parent 143902c commit 61bf7a9

19 files changed

+92
-71
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ repositories {
2727
}
2828

2929
dependencies {
30-
implementation group: 'io.temporal', name: 'temporal-sdk', version: '0.23.1'
30+
implementation group: 'io.temporal', name: 'temporal-sdk', version: '0.25.0'
3131
implementation group: 'commons-configuration', name: 'commons-configuration', version: '1.9'
3232
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
3333

src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflowImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import io.temporal.activity.ActivityOptions;
2323
import io.temporal.common.RetryOptions;
24-
import io.temporal.workflow.ActivityException;
24+
import io.temporal.failure.ActivityFailure;
2525
import io.temporal.workflow.Saga;
2626
import io.temporal.workflow.Workflow;
2727
import java.time.Duration;
@@ -51,7 +51,7 @@ public void bookTrip(String name) {
5151

5252
String flightReservationID = activities.bookFlight(name);
5353
saga.addCompensation(activities::cancelFlight, flightReservationID, name);
54-
} catch (ActivityException e) {
54+
} catch (ActivityFailure e) {
5555
saga.compensate();
5656
throw e;
5757
}

src/main/java/io/temporal/samples/common/QueryWorkflowExecution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import io.temporal.client.WorkflowClient;
2323
import io.temporal.client.WorkflowStub;
24-
import io.temporal.proto.common.WorkflowExecution;
24+
import io.temporal.common.v1.WorkflowExecution;
2525
import io.temporal.serviceclient.WorkflowServiceStubs;
2626
import java.util.Optional;
2727

src/main/java/io/temporal/samples/fileprocessing/StoreActivities.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@
2626
public interface StoreActivities {
2727

2828
final class TaskListFileNamePair {
29-
private final String hostTaskList;
30-
private final String fileName;
29+
private String hostTaskList;
30+
private String fileName;
3131

3232
public TaskListFileNamePair(String hostTaskList, String fileName) {
3333
this.hostTaskList = hostTaskList;
3434
this.fileName = fileName;
3535
}
3636

37+
/** Jackson needs it */
38+
public TaskListFileNamePair() {}
39+
3740
public String getHostTaskList() {
3841
return hostTaskList;
3942
}

src/main/java/io/temporal/samples/hello/HelloActivityRetry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow {
7272
.setRetryOptions(
7373
RetryOptions.newBuilder()
7474
.setInitialInterval(Duration.ofSeconds(1))
75-
.setDoNotRetry(IllegalArgumentException.class)
75+
.setDoNotRetry(IllegalArgumentException.class.getName())
7676
.build())
7777
.build());
7878

src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package io.temporal.samples.hello;
2121

2222
import io.temporal.activity.Activity;
23+
import io.temporal.activity.ActivityExecutionContext;
2324
import io.temporal.activity.ActivityInterface;
2425
import io.temporal.activity.ActivityOptions;
2526
import io.temporal.client.ActivityCompletionClient;
@@ -86,17 +87,18 @@ static class GreetingActivitiesImpl implements GreetingActivities {
8687

8788
/**
8889
* Demonstrates how to implement an activity asynchronously. When {@link
89-
* Activity#doNotCompleteOnReturn()} is called the activity implementation function returning
90-
* doesn't complete the activity.
90+
* io.temporal.activity.ActivityExecutionContext#doNotCompleteOnReturn()} is called the activity
91+
* implementation function returning doesn't complete the activity.
9192
*/
9293
@Override
9394
public String composeGreeting(String greeting, String name) {
9495
// TaskToken is a correlation token used to match an activity task with its completion
95-
byte[] taskToken = Activity.getTaskToken();
96+
ActivityExecutionContext context = Activity.getExecutionContext();
97+
byte[] taskToken = context.getTaskToken();
9698
// In real life this request can be executed anywhere. By a separate service for
9799
// example.
98100
ForkJoinPool.commonPool().execute(() -> composeGreetingAsync(taskToken, greeting, name));
99-
Activity.doNotCompleteOnReturn();
101+
context.doNotCompleteOnReturn();
100102
// When doNotCompleteOnReturn() is invoked the return value is ignored.
101103
return "ignored";
102104
}

src/main/java/io/temporal/samples/hello/HelloCron.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import io.temporal.activity.Activity;
2323
import io.temporal.activity.ActivityInterface;
2424
import io.temporal.activity.ActivityOptions;
25-
import io.temporal.client.DuplicateWorkflowException;
2625
import io.temporal.client.WorkflowClient;
26+
import io.temporal.client.WorkflowExecutionAlreadyStarted;
2727
import io.temporal.client.WorkflowOptions;
28-
import io.temporal.proto.common.WorkflowExecution;
28+
import io.temporal.common.v1.WorkflowExecution;
2929
import io.temporal.serviceclient.WorkflowServiceStubs;
3030
import io.temporal.worker.Worker;
3131
import io.temporal.worker.WorkerFactory;
@@ -82,7 +82,8 @@ public void greet(String name) {
8282
static class GreetingActivitiesImpl implements GreetingActivities {
8383
@Override
8484
public void greet(String greeting) {
85-
System.out.println("From " + Activity.getWorkflowExecution() + ": " + greeting);
85+
System.out.println(
86+
"From " + Activity.getExecutionContext().getInfo().getWorkflowId() + ": " + greeting);
8687
}
8788
}
8889

@@ -114,13 +115,17 @@ public static void main(String[] args) throws InterruptedException {
114115
.setWorkflowId(CRON_WORKFLOW_ID)
115116
.setTaskList(TASK_LIST)
116117
.setCronSchedule("* * * * *")
118+
// Execution timeout limits total time. Cron will stop executing after this timeout.
119+
.setWorkflowExecutionTimeout(Duration.ofMinutes(10))
120+
// Run timeout limits duration of a single workflow invocation.
121+
.setWorkflowRunTimeout(Duration.ofMinutes(1))
117122
.build();
118123
// WorkflowOptions.newBuilder().setCronSchedule("@every 2s").build();
119124
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions);
120125
try {
121126
WorkflowExecution execution = WorkflowClient.start(workflow::greet, "World");
122127
System.out.println("Started " + execution);
123-
} catch (DuplicateWorkflowException e) {
128+
} catch (WorkflowExecutionAlreadyStarted e) {
124129
System.out.println("Already running as " + e.getExecution());
125130
} catch (Throwable e) {
126131
e.printStackTrace();

src/main/java/io/temporal/samples/hello/HelloPeriodic.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
import io.temporal.activity.Activity;
2424
import io.temporal.activity.ActivityInterface;
2525
import io.temporal.activity.ActivityOptions;
26-
import io.temporal.client.DuplicateWorkflowException;
2726
import io.temporal.client.WorkflowClient;
2827
import io.temporal.client.WorkflowException;
28+
import io.temporal.client.WorkflowExecutionAlreadyStarted;
2929
import io.temporal.client.WorkflowOptions;
3030
import io.temporal.client.WorkflowStub;
31-
import io.temporal.proto.common.WorkflowExecution;
31+
import io.temporal.common.v1.WorkflowExecution;
3232
import io.temporal.serviceclient.WorkflowServiceStubs;
3333
import io.temporal.worker.Worker;
3434
import io.temporal.worker.WorkerFactory;
@@ -112,7 +112,8 @@ public void greetPeriodically(String name) {
112112
static class GreetingActivitiesImpl implements GreetingActivities {
113113
@Override
114114
public void greet(String greeting) {
115-
System.out.println("From " + Activity.getWorkflowExecution() + ": " + greeting);
115+
System.out.println(
116+
"From " + Activity.getExecutionContext().getInfo().getWorkflowId() + ": " + greeting);
116117
}
117118
}
118119

@@ -160,7 +161,7 @@ public static void main(String[] args) throws InterruptedException {
160161
try {
161162
execution = WorkflowClient.start(workflow::greetPeriodically, "World");
162163
System.out.println("Started " + execution);
163-
} catch (DuplicateWorkflowException e) {
164+
} catch (WorkflowExecutionAlreadyStarted e) {
164165
System.out.println("Still running as " + e.getExecution());
165166
} catch (Throwable e) {
166167
e.printStackTrace();

src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@
2525
import io.temporal.client.WorkflowClient;
2626
import io.temporal.client.WorkflowOptions;
2727
import io.temporal.common.converter.DataConverter;
28-
import io.temporal.common.converter.GsonJsonDataConverter;
29-
import io.temporal.proto.common.Payload;
30-
import io.temporal.proto.common.SearchAttributes;
31-
import io.temporal.proto.common.WorkflowExecution;
32-
import io.temporal.proto.workflowservice.DescribeWorkflowExecutionRequest;
33-
import io.temporal.proto.workflowservice.DescribeWorkflowExecutionResponse;
28+
import io.temporal.common.v1.Payload;
29+
import io.temporal.common.v1.SearchAttributes;
30+
import io.temporal.common.v1.WorkflowExecution;
3431
import io.temporal.serviceclient.WorkflowServiceStubs;
3532
import io.temporal.worker.Worker;
3633
import io.temporal.worker.WorkerFactory;
3734
import io.temporal.workflow.Workflow;
3835
import io.temporal.workflow.WorkflowInterface;
3936
import io.temporal.workflow.WorkflowMethod;
37+
import io.temporal.workflowservice.v1.DescribeWorkflowExecutionRequest;
38+
import io.temporal.workflowservice.v1.DescribeWorkflowExecutionResponse;
4039
import java.text.SimpleDateFormat;
4140
import java.time.Duration;
4241
import java.util.Date;
@@ -168,7 +167,7 @@ private static String generateDateTimeFieldValue() {
168167
// example for extract value from search attributes
169168
private static String getKeywordFromSearchAttribute(SearchAttributes searchAttributes) {
170169
Payload field = searchAttributes.getIndexedFieldsOrThrow("CustomKeywordField");
171-
DataConverter dataConverter = GsonJsonDataConverter.getInstance();
172-
return dataConverter.getPayloadConverter().fromData(field, String.class, String.class);
170+
DataConverter dataConverter = DataConverter.getDefaultInstance();
171+
return dataConverter.fromPayload(field, String.class, String.class);
173172
}
174173
}

src/main/java/io/temporal/samples/moneytransfer/AccountImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public void withdraw(String accountId, String referenceId, int amountCents) {
2626
System.out.printf(
2727
"Withdraw to %s of %d cents requested. ReferenceId=%s\n",
2828
accountId, amountCents, referenceId);
29-
// throw new RuntimeException("simulated");
3029
}
3130

3231
@Override

0 commit comments

Comments
 (0)