Skip to content

Commit fe24ae8

Browse files
refactor
1 parent 178ce4a commit fe24ae8

6 files changed

Lines changed: 8 additions & 35 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ See the README.md file in each main sample directory for cut/paste Gradle comman
105105

106106
- [**Safe Message Passing**](/core/src/main/java/io/temporal/samples/safemessagepassing): Safely handling concurrent updates and signals messages.
107107

108+
- [**Custom Annotation**](/core/src/main/java/io/temporal/samples/customannotation): Demonstrates how to create a custom annotation using an interceptor.
109+
108110
#### API demonstrations
109111

110112
- [**Async Untyped Child Workflow**](/core/src/main/java/io/temporal/samples/asyncuntypedchild): Demonstrates how to invoke an untyped child workflow async, that can complete after parent workflow is already completed.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ subprojects {
2626
ext {
2727
otelVersion = '1.30.1'
2828
otelVersionAlpha = "${otelVersion}-alpha"
29-
javaSDKVersion = '1.30.0'
29+
javaSDKVersion = '1.30.1'
3030
camelVersion = '3.22.1'
3131
jarVersion = '1.0.0'
3232
}

core/src/main/java/io/temporal/samples/customannotation/BenignExceptionTypes.java

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

55
/**
66
* BenignExceptionTypes is an annotation that can be used to specify an exception type is benign and
7-
* not a issue worth logging.
7+
* not an issue worth logging.
88
*
99
* <p>For this annotation to work, {@link BenignExceptionTypesAnnotationInterceptor} must be passed
1010
* as a worker interceptor to the worker factory.

core/src/main/java/io/temporal/samples/customannotation/BenignExceptionTypesAnnotationInterceptor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public void init(ActivityExecutionContext context) {
5959
List<POJOActivityMethodMetadata> activityMethods =
6060
POJOActivityImplMetadata.newInstance(context.getInstance().getClass())
6161
.getActivityMethods();
62-
// TODO: handle dynamic activity types
6362
POJOActivityMethodMetadata currentActivityMethod =
6463
activityMethods.stream()
6564
.filter(x -> x.getActivityTypeName().equals(context.getInfo().getActivityType()))

core/src/main/java/io/temporal/samples/customannotation/CustomAnnotation.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import io.temporal.activity.ActivityOptions;
2525
import io.temporal.client.WorkflowClient;
2626
import io.temporal.client.WorkflowOptions;
27-
import io.temporal.common.RetryOptions;
2827
import io.temporal.serviceclient.WorkflowServiceStubs;
2928
import io.temporal.worker.Worker;
3029
import io.temporal.worker.WorkerFactory;
@@ -88,29 +87,11 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow {
8887
* are executed outside of the workflow thread on the activity worker, that can be on a
8988
* different host. Temporal is going to dispatch the activity results back to the workflow and
9089
* unblock the stub as soon as activity is completed on the activity worker.
91-
*
92-
* <p>In the {@link ActivityOptions} definition the "setStartToCloseTimeout" option sets the
93-
* maximum time of a single Activity execution attempt. For this example it is set to 10
94-
* seconds.
95-
*
96-
* <p>In the {@link ActivityOptions} definition the "setInitialInterval" option sets the
97-
* interval of the first retry. It is set to 1 second. The "setDoNotRetry" option is a list of
98-
* application failures for which retries should not be performed.
99-
*
100-
* <p>By default the maximum number of retry attempts is set to "unlimited" however you can
101-
* change it by adding the "setMaximumAttempts" option to the retry options.
10290
*/
10391
private final GreetingActivities activities =
10492
Workflow.newActivityStub(
10593
GreetingActivities.class,
106-
ActivityOptions.newBuilder()
107-
.setStartToCloseTimeout(Duration.ofSeconds(10))
108-
.setRetryOptions(
109-
RetryOptions.newBuilder()
110-
.setInitialInterval(Duration.ofSeconds(1))
111-
.setDoNotRetry(IllegalArgumentException.class.getName())
112-
.build())
113-
.build());
94+
ActivityOptions.newBuilder().setStartToCloseTimeout(Duration.ofSeconds(10)).build());
11495

11596
@Override
11697
public String getGreeting(String name) {
@@ -125,7 +106,6 @@ public String getGreeting(String name) {
125106
*/
126107
static class GreetingActivitiesImpl implements GreetingActivities {
127108
private int callCount;
128-
private long lastInvocationTime;
129109

130110
/**
131111
* Our activity implementation simulates a failure 3 times. Given our previously set
@@ -134,18 +114,8 @@ static class GreetingActivitiesImpl implements GreetingActivities {
134114
@Override
135115
@BenignExceptionTypes({IllegalStateException.class})
136116
public synchronized String composeGreeting(String greeting, String name) {
137-
if (lastInvocationTime != 0) {
138-
long timeSinceLastInvocation = System.currentTimeMillis() - lastInvocationTime;
139-
System.out.print(timeSinceLastInvocation + " milliseconds since last invocation. ");
140-
}
141-
lastInvocationTime = System.currentTimeMillis();
142117
if (++callCount < 4) {
143118
System.out.println("composeGreeting activity is going to fail");
144-
145-
/*
146-
* We throw IllegalStateException here. It is not in the list of "do not retry" exceptions
147-
* set in our RetryOptions, so a workflow retry is going to be issued
148-
*/
149119
throw new IllegalStateException("not yet");
150120
}
151121

core/src/main/java/io/temporal/samples/customannotation/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Custom annotation
22

3-
The sample demonstrates how to create a custom annotation using an interceptor. In this case the annotation allows specifying a fixed next retry delay for a certain failure type.
3+
The sample demonstrates how to create a custom annotation using an interceptor. In this case the annotation allows specifying an exception of a certain type is benign.
4+
5+
This samples shows a custom annotation on an activity method, but the same approach can be used for workflow methods or Nexus operations.
46

57
```bash
68
./gradlew -q execute -PmainClass=io.temporal.samples.customannotation.CustomAnnotation

0 commit comments

Comments
 (0)