diff --git a/src/main/java/com/uber/cadence/activity/ActivityInterface.java b/src/main/java/com/uber/cadence/activity/ActivityInterface.java
new file mode 100644
index 000000000..81b6cc6f8
--- /dev/null
+++ b/src/main/java/com/uber/cadence/activity/ActivityInterface.java
@@ -0,0 +1,76 @@
+/*
+ * Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
+ * Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
+ * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not
+ * use this file except in compliance with the License. A copy of the License is
+ * located at
+ *
+ * http://aws.amazon.com/apache2.0
+ *
+ * or in the "license" file accompanying this file. This file is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package com.uber.cadence.activity;
+
+import com.uber.cadence.workflow.Workflow;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Indicates that the interface is an activity interface. Only interfaces annotated with this
+ * annotation can be used as parameters to {@link Workflow#newActivityStub(Class)} methods.
+ *
+ *
Each method of the interface annotated with ActivityInterface including inherited
+ * from interfaces is a separate activity. By default the name of an activity type is "short
+ * interface name"_"method name".
+ *
+ *
Example:
+ *
+ *
+ * public interface A {
+ * a();
+ * }
+ *
+ * {@literal @}ActivityInterface
+ * public interface B extends A {
+ * b();
+ * }
+ *
+ * {@literal @}ActivityInterface
+ * public interface C extends B {
+ * c();
+ * }
+ *
+ * public class CImpl implements C {
+ * public void a() {}
+ * public void b() {}
+ * public void c() {}
+ * }
+ *
+ *
+ * When CImpl instance is registered with the {@link com.uber.cadence.worker.Worker}
+ * the following activities are registered:
+ *
+ *
+ *
+ *
+ *
B_a
+ *
B_b
+ *
C_c
+ *
+ *
+ * Note that method a() is registered as "B_a" because interface A lacks
+ * ActivityInterface annotation. The workflow code can call activities through stubs to B
+ * and C interfaces. A call to crate stub to A interface will fail
+ * as A is not annotated with ActivityInterface.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface ActivityInterface {}
diff --git a/src/main/java/com/uber/cadence/activity/ActivityMethod.java b/src/main/java/com/uber/cadence/activity/ActivityMethod.java
index 239492a45..00118830a 100644
--- a/src/main/java/com/uber/cadence/activity/ActivityMethod.java
+++ b/src/main/java/com/uber/cadence/activity/ActivityMethod.java
@@ -1,8 +1,8 @@
/*
+ * Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
+ * Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
- * Modifications copyright (C) 2017 Uber Technologies, Inc.
- *
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
@@ -21,12 +21,11 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import java.time.Duration;
/**
* Indicates that the method is an activity method. This annotation applies only to activity
- * interface methods. Not required. Use it to override default activity type name or other options.
- * When both {@link ActivityOptions} and {@link ActivityMethod} have non default value for some
- * parameter the {@link ActivityOptions} one takes precedence.
+ * interface methods. Not required. Use it to override default activity type name.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@@ -40,30 +39,40 @@
* task list (use {@link #scheduleToStartTimeoutSeconds()} to limit it) plus activity execution
* time (use {@link #startToCloseTimeoutSeconds()} to limit it). Either this option or both
* schedule to start and start to close are required.
+ *
+ * @deprecated use {@link ActivityOptions.Builder#setScheduleToCloseTimeout(Duration)} instead.
*/
int scheduleToCloseTimeoutSeconds() default 0;
/**
* Time activity can stay in task list before it is picked up by a worker. If schedule to close is
* not provided then both this and start to close are required.
+ *
+ * @deprecated use {@link ActivityOptions.Builder#setScheduleToStartTimeout(Duration)} instead.
*/
int scheduleToStartTimeoutSeconds() default 0;
/**
* Maximum activity execution time after it was sent to a worker. If schedule to close is not
* provided then both this and schedule to start are required.
+ *
+ * @deprecated use {@link ActivityOptions.Builder#setStartToCloseTimeout(Duration)} instead.
*/
int startToCloseTimeoutSeconds() default 0;
/**
* Heartbeat interval. Activity must heartbeat before this interval passes after a last heartbeat
* or activity start.
+ *
+ * @deprecated use {@link ActivityOptions.Builder#setHeartbeatTimeout(Duration)} instead.
*/
int heartbeatTimeoutSeconds() default 0;
/**
* Task list to use when dispatching activity task to a worker. By default it is the same task
* list name the workflow was started with.
+ *
+ * @deprecated use {@link ActivityOptions.Builder#setTaskList(String)} instead.
*/
String taskList() default "";
}
diff --git a/src/main/java/com/uber/cadence/activity/ActivityOptions.java b/src/main/java/com/uber/cadence/activity/ActivityOptions.java
index da3062c18..d0b6016a4 100644
--- a/src/main/java/com/uber/cadence/activity/ActivityOptions.java
+++ b/src/main/java/com/uber/cadence/activity/ActivityOptions.java
@@ -1,8 +1,8 @@
/*
+ * Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
+ * Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
- * Modifications copyright (C) 2017 Uber Technologies, Inc.
- *
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
@@ -29,36 +29,22 @@
/** Options used to configure how an activity is invoked. */
public final class ActivityOptions {
- /**
- * Used to merge annotation and options. Options takes precedence. Returns options with all
- * defaults filled in.
- */
- public static ActivityOptions merge(ActivityMethod a, MethodRetry r, ActivityOptions o) {
- if (a == null) {
- if (r == null) {
- return new ActivityOptions.Builder(o).validateAndBuildWithDefaults();
- }
- RetryOptions mergedR = RetryOptions.merge(r, o.getRetryOptions());
- return new ActivityOptions.Builder().setRetryOptions(mergedR).validateAndBuildWithDefaults();
- }
- if (o == null) {
- o = new ActivityOptions.Builder().build();
- }
- return new ActivityOptions.Builder()
- .setScheduleToCloseTimeout(
- mergeDuration(a.scheduleToCloseTimeoutSeconds(), o.getScheduleToCloseTimeout()))
- .setScheduleToStartTimeout(
- mergeDuration(a.scheduleToStartTimeoutSeconds(), o.getScheduleToStartTimeout()))
- .setStartToCloseTimeout(
- mergeDuration(a.startToCloseTimeoutSeconds(), o.getStartToCloseTimeout()))
- .setHeartbeatTimeout(mergeDuration(a.heartbeatTimeoutSeconds(), o.getHeartbeatTimeout()))
- .setTaskList(
- o.getTaskList() != null
- ? o.getTaskList()
- : (a.taskList().isEmpty() ? null : a.taskList()))
- .setRetryOptions(RetryOptions.merge(r, o.getRetryOptions()))
- .setContextPropagators(o.getContextPropagators())
- .validateAndBuildWithDefaults();
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ public static Builder newBuilder(ActivityOptions options) {
+ return new Builder(options);
+ }
+
+ public static ActivityOptions getDefaultInstance() {
+ return DEFAULT_INSTANCE;
+ }
+
+ private static final ActivityOptions DEFAULT_INSTANCE;
+
+ static {
+ DEFAULT_INSTANCE = ActivityOptions.newBuilder().build();
}
public static final class Builder {
@@ -155,6 +141,14 @@ public Builder setContextPropagators(List contextPropagators)
return this;
}
+ /**
+ * Properties that are set on this builder take precedence over ones found in the annotation.
+ */
+ public Builder setMethodRetry(MethodRetry r) {
+ retryOptions = RetryOptions.merge(r, retryOptions);
+ return this;
+ }
+
public ActivityOptions build() {
return new ActivityOptions(
heartbeatTimeout,
@@ -324,15 +318,4 @@ public int hashCode() {
retryOptions,
contextPropagators);
}
-
- static Duration mergeDuration(int annotationSeconds, Duration options) {
- if (options == null) {
- if (annotationSeconds == 0) {
- return null;
- }
- return Duration.ofSeconds(annotationSeconds);
- } else {
- return options;
- }
- }
}
diff --git a/src/main/java/com/uber/cadence/activity/LocalActivityOptions.java b/src/main/java/com/uber/cadence/activity/LocalActivityOptions.java
index 9534af9a2..dde8334b8 100644
--- a/src/main/java/com/uber/cadence/activity/LocalActivityOptions.java
+++ b/src/main/java/com/uber/cadence/activity/LocalActivityOptions.java
@@ -1,8 +1,8 @@
/*
+ * Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
+ * Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
- * Modifications copyright (C) 2017 Uber Technologies, Inc.
- *
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
@@ -29,31 +29,23 @@
/** Options used to configure how an local activity is invoked. */
public final class LocalActivityOptions {
- /**
- * Used to merge annotation and options. Options takes precedence. Returns options with all
- * defaults filled in.
- */
- public static LocalActivityOptions merge(
- ActivityMethod a, MethodRetry r, LocalActivityOptions o) {
- if (a == null) {
- if (r == null) {
- return new LocalActivityOptions.Builder(o).validateAndBuildWithDefaults();
- }
- RetryOptions mergedR = RetryOptions.merge(r, o.getRetryOptions());
- return new LocalActivityOptions.Builder()
- .setRetryOptions(mergedR)
- .validateAndBuildWithDefaults();
- }
- if (o == null) {
- o = new LocalActivityOptions.Builder().build();
- }
- return new LocalActivityOptions.Builder()
- .setScheduleToCloseTimeout(
- ActivityOptions.mergeDuration(
- a.scheduleToCloseTimeoutSeconds(), o.getScheduleToCloseTimeout()))
- .setRetryOptions(RetryOptions.merge(r, o.getRetryOptions()))
- .setContextPropagators(o.getContextPropagators())
- .validateAndBuildWithDefaults();
+ public static Builder newBuilder() {
+ return new Builder(null);
+ }
+
+ /** @param o null is allowed */
+ public static Builder newBuilder(LocalActivityOptions o) {
+ return new Builder(o);
+ }
+
+ public static LocalActivityOptions getDefaultInstance() {
+ return DEFAULT_INSTANCE;
+ }
+
+ private static final LocalActivityOptions DEFAULT_INSTANCE;
+
+ static {
+ DEFAULT_INSTANCE = LocalActivityOptions.newBuilder().build();
}
public static final class Builder {
@@ -92,6 +84,17 @@ public Builder setContextPropagators(List contextPropagators)
return this;
}
+ /**
+ * Merges MethodRetry annotation. The values of this builder take precedence over annotation
+ * ones.
+ */
+ public Builder setMethodRetry(MethodRetry r) {
+ if (r != null) {
+ this.retryOptions = RetryOptions.merge(r, retryOptions);
+ }
+ return this;
+ }
+
public LocalActivityOptions build() {
return new LocalActivityOptions(scheduleToCloseTimeout, retryOptions, contextPropagators);
}
diff --git a/src/main/java/com/uber/cadence/client/WorkflowClientOptions.java b/src/main/java/com/uber/cadence/client/WorkflowClientOptions.java
index d47ef8528..df59f25eb 100644
--- a/src/main/java/com/uber/cadence/client/WorkflowClientOptions.java
+++ b/src/main/java/com/uber/cadence/client/WorkflowClientOptions.java
@@ -1,8 +1,8 @@
/*
+ * Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
+ * Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
- * Modifications copyright (C) 2017 Uber Technologies, Inc.
- *
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
diff --git a/src/main/java/com/uber/cadence/internal/common/InternalUtils.java b/src/main/java/com/uber/cadence/internal/common/InternalUtils.java
index 73498885a..5b1d0a1c5 100644
--- a/src/main/java/com/uber/cadence/internal/common/InternalUtils.java
+++ b/src/main/java/com/uber/cadence/internal/common/InternalUtils.java
@@ -1,8 +1,8 @@
/*
+ * Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
+ * Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
- * Modifications copyright (C) 2017 Uber Technologies, Inc.
- *
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
@@ -51,7 +51,11 @@ public final class InternalUtils {
* @return "Simple class name"::"methodName"
*/
public static String getSimpleName(Method method) {
- return method.getDeclaringClass().getSimpleName() + "::" + method.getName();
+ return getSimpleName(method.getDeclaringClass(), method);
+ }
+
+ public static String getSimpleName(Class> type, Method method) {
+ return type.getSimpleName() + "::" + method.getName();
}
public static String getWorkflowType(Method method, WorkflowMethod workflowMethod) {
diff --git a/src/main/java/com/uber/cadence/internal/common/Retryer.java b/src/main/java/com/uber/cadence/internal/common/RpcRetryer.java
similarity index 91%
rename from src/main/java/com/uber/cadence/internal/common/Retryer.java
rename to src/main/java/com/uber/cadence/internal/common/RpcRetryer.java
index a2d7e0a9a..4f27f6f87 100644
--- a/src/main/java/com/uber/cadence/internal/common/Retryer.java
+++ b/src/main/java/com/uber/cadence/internal/common/RpcRetryer.java
@@ -1,8 +1,8 @@
/*
- * Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
- * Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
+ * Modifications copyright (C) 2017 Uber Technologies, Inc.
+ *
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
@@ -19,7 +19,13 @@
import static com.uber.cadence.internal.common.CheckedExceptionWrapper.unwrap;
-import com.uber.cadence.*;
+import com.uber.cadence.BadRequestError;
+import com.uber.cadence.CancellationAlreadyRequestedError;
+import com.uber.cadence.DomainAlreadyExistsError;
+import com.uber.cadence.DomainNotActiveError;
+import com.uber.cadence.EntityNotExistsError;
+import com.uber.cadence.QueryFailedError;
+import com.uber.cadence.WorkflowExecutionAlreadyStartedError;
import com.uber.cadence.common.RetryOptions;
import java.time.Duration;
import java.util.concurrent.CancellationException;
@@ -31,8 +37,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class Retryer {
- public static final RetryOptions DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS;
+public final class RpcRetryer {
+ public static final RetryOptions DEFAULT_RPC_RETRY_OPTIONS;
private static final Duration RETRY_SERVICE_OPERATION_INITIAL_INTERVAL = Duration.ofMillis(20);
private static final Duration RETRY_SERVICE_OPERATION_EXPIRATION_INTERVAL = Duration.ofMinutes(1);
@@ -58,7 +64,7 @@ public final class Retryer {
QueryFailedError.class,
DomainNotActiveError.class,
CancellationAlreadyRequestedError.class);
- DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS = roBuilder.validateBuildWithDefaults();
+ DEFAULT_RPC_RETRY_OPTIONS = roBuilder.validateBuildWithDefaults();
}
public interface RetryableProc {
@@ -81,7 +87,7 @@ private static class ValueExceptionPair {
private final CompletableFuture value;
private final Throwable exception;
- public ValueExceptionPair(CompletableFuture value, Throwable exception) {
+ ValueExceptionPair(CompletableFuture value, Throwable exception) {
this.value = value;
this.exception = exception;
}
@@ -95,7 +101,7 @@ public Throwable getException() {
}
}
- private static final Logger log = LoggerFactory.getLogger(Retryer.class);
+ private static final Logger log = LoggerFactory.getLogger(RpcRetryer.class);
public static void retry(RetryOptions options, RetryableProc r)
throws T {
@@ -107,6 +113,10 @@ public static void retry(RetryOptions options, RetryablePr
});
}
+ public static void retry(RetryableProc r) throws T {
+ retry(DEFAULT_RPC_RETRY_OPTIONS, r);
+ }
+
public static R retryWithResult(
RetryOptions options, RetryableFunc r) throws T {
int attempt = 0;
@@ -266,5 +276,5 @@ private static void rethrow(Exception e) throws T {
}
/** Prohibits instantiation. */
- private Retryer() {}
+ private RpcRetryer() {}
}
diff --git a/src/main/java/com/uber/cadence/internal/common/WorkflowExecutionUtils.java b/src/main/java/com/uber/cadence/internal/common/WorkflowExecutionUtils.java
index 02bf2cc24..5f37a16df 100644
--- a/src/main/java/com/uber/cadence/internal/common/WorkflowExecutionUtils.java
+++ b/src/main/java/com/uber/cadence/internal/common/WorkflowExecutionUtils.java
@@ -27,7 +27,6 @@
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.uber.cadence.ActivityType;
-import com.uber.cadence.BadRequestError;
import com.uber.cadence.Decision;
import com.uber.cadence.DecisionType;
import com.uber.cadence.DescribeWorkflowExecutionRequest;
@@ -91,15 +90,6 @@ public class WorkflowExecutionUtils {
*/
private static final String INDENTATION = " ";
- private static RetryOptions retryParameters =
- new RetryOptions.Builder()
- .setBackoffCoefficient(2)
- .setInitialInterval(Duration.ofMillis(500))
- .setMaximumInterval(Duration.ofSeconds(30))
- .setMaximumAttempts(Integer.MAX_VALUE)
- .setDoNotRetry(BadRequestError.class, EntityNotExistsError.class)
- .build();
-
// Wait period for passive cluster to retry getting workflow result in case of replication delay.
private static final long ENTITY_NOT_EXIST_RETRY_WAIT_MILLIS = 500;
@@ -216,7 +206,7 @@ private static HistoryEvent getInstanceCloseEvent(
RetryOptions retryOptions = getRetryOptionWithTimeout(timeout, unit);
try {
response =
- Retryer.retryWithResult(
+ RpcRetryer.retryWithResult(
retryOptions,
() -> service.GetWorkflowExecutionHistoryWithTimeout(r, unit.toMillis(timeout)));
} catch (EntityNotExistsError e) {
@@ -343,7 +333,7 @@ private static CompletableFuture getInstanceCloseEventAsync(
}
private static RetryOptions getRetryOptionWithTimeout(long timeout, TimeUnit unit) {
- return new RetryOptions.Builder(retryParameters)
+ return new RetryOptions.Builder(RpcRetryer.DEFAULT_RPC_RETRY_OPTIONS)
.setExpiration(Duration.ofSeconds(unit.toSeconds(timeout)))
.build();
}
@@ -355,7 +345,7 @@ private static RetryOptions getRetryOptionWithTimeout(long timeout, TimeUnit uni
long timeout,
TimeUnit unit) {
RetryOptions retryOptions = getRetryOptionWithTimeout(timeout, unit);
- return Retryer.retryWithResultAsync(
+ return RpcRetryer.retryWithResultAsync(
retryOptions,
() -> {
CompletableFuture result = new CompletableFuture<>();
diff --git a/src/main/java/com/uber/cadence/internal/external/GenericWorkflowClientExternalImpl.java b/src/main/java/com/uber/cadence/internal/external/GenericWorkflowClientExternalImpl.java
index 6d86d186a..ebcfc67da 100644
--- a/src/main/java/com/uber/cadence/internal/external/GenericWorkflowClientExternalImpl.java
+++ b/src/main/java/com/uber/cadence/internal/external/GenericWorkflowClientExternalImpl.java
@@ -118,9 +118,8 @@ private WorkflowExecution startWorkflowInternal(StartWorkflowExecutionParameters
StartWorkflowExecutionResponse result;
try {
result =
- Retryer.retryWithResult(
- Retryer.DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS,
- () -> service.StartWorkflowExecution(request));
+ RpcRetryer.retryWithResult(
+ RpcRetryer.DEFAULT_RPC_RETRY_OPTIONS, () -> service.StartWorkflowExecution(request));
} catch (WorkflowExecutionAlreadyStartedError e) {
throw e;
} catch (TException e) {
@@ -137,7 +136,7 @@ private RetryOptions getRetryOptionsWithExpiration(RetryOptions o, Long timeoutI
if (timeoutInMillis == null || timeoutInMillis <= 0 || timeoutInMillis == Long.MAX_VALUE) {
return o;
}
- return new RetryOptions.Builder(Retryer.DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS)
+ return new RetryOptions.Builder(RpcRetryer.DEFAULT_RPC_RETRY_OPTIONS)
.setExpiration(Duration.ofMillis((timeoutInMillis)))
.build();
}
@@ -146,9 +145,8 @@ private CompletableFuture startWorkflowAsyncInternal(
StartWorkflowExecutionParameters startParameters, Long timeoutInMillis) {
StartWorkflowExecutionRequest request = getStartRequest(startParameters);
- return Retryer.retryWithResultAsync(
- getRetryOptionsWithExpiration(
- Retryer.DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS, timeoutInMillis),
+ return RpcRetryer.retryWithResultAsync(
+ getRetryOptionsWithExpiration(RpcRetryer.DEFAULT_RPC_RETRY_OPTIONS, timeoutInMillis),
() -> {
CompletableFuture result = new CompletableFuture<>();
try {
@@ -272,9 +270,7 @@ public void signalWorkflowExecution(SignalExternalWorkflowParameters signalParam
SignalWorkflowExecutionRequest request = getSignalRequest(signalParameters);
try {
- Retryer.retry(
- Retryer.DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS,
- () -> service.SignalWorkflowExecution(request));
+ RpcRetryer.retry(() -> service.SignalWorkflowExecution(request));
} catch (TException e) {
throw CheckedExceptionWrapper.wrap(e);
}
@@ -290,9 +286,8 @@ public CompletableFuture signalWorkflowExecutionAsync(
public CompletableFuture signalWorkflowExecutionAsync(
SignalExternalWorkflowParameters signalParameters, Long timeoutInMillis) {
SignalWorkflowExecutionRequest request = getSignalRequest(signalParameters);
- return Retryer.retryWithResultAsync(
- getRetryOptionsWithExpiration(
- Retryer.DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS, timeoutInMillis),
+ return RpcRetryer.retryWithResultAsync(
+ getRetryOptionsWithExpiration(RpcRetryer.DEFAULT_RPC_RETRY_OPTIONS, timeoutInMillis),
() -> {
CompletableFuture result = new CompletableFuture<>();
try {
@@ -387,8 +382,8 @@ private WorkflowExecution signalWithStartWorkflowInternal(
StartWorkflowExecutionResponse result;
try {
result =
- Retryer.retryWithResult(
- Retryer.DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS,
+ RpcRetryer.retryWithResult(
+ RpcRetryer.DEFAULT_RPC_RETRY_OPTIONS,
() -> service.SignalWithStartWorkflowExecution(request));
} catch (TException e) {
throw CheckedExceptionWrapper.wrap(e);
@@ -405,9 +400,7 @@ public void requestCancelWorkflowExecution(WorkflowExecution execution) {
request.setDomain(domain);
request.setWorkflowExecution(execution);
try {
- Retryer.retry(
- Retryer.DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS,
- () -> service.RequestCancelWorkflowExecution(request));
+ RpcRetryer.retry(() -> service.RequestCancelWorkflowExecution(request));
} catch (TException e) {
throw CheckedExceptionWrapper.wrap(e);
}
@@ -427,9 +420,8 @@ public QueryWorkflowResponse queryWorkflow(QueryWorkflowParameters queryParamete
request.setQueryRejectCondition(queryParameters.getQueryRejectCondition());
try {
QueryWorkflowResponse response =
- Retryer.retryWithResult(
- Retryer.DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS,
- () -> service.QueryWorkflow(request));
+ RpcRetryer.retryWithResult(
+ RpcRetryer.DEFAULT_RPC_RETRY_OPTIONS, () -> service.QueryWorkflow(request));
return response;
} catch (TException e) {
throw CheckedExceptionWrapper.wrap(e);
@@ -451,9 +443,7 @@ public void terminateWorkflowExecution(TerminateWorkflowExecutionParameters term
request.setReason(terminateParameters.getReason());
// request.setChildPolicy(terminateParameters.getChildPolicy());
try {
- Retryer.retry(
- Retryer.DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS,
- () -> service.TerminateWorkflowExecution(request));
+ RpcRetryer.retry(() -> service.TerminateWorkflowExecution(request));
} catch (TException e) {
throw CheckedExceptionWrapper.wrap(e);
}
diff --git a/src/main/java/com/uber/cadence/internal/external/ManualActivityCompletionClientImpl.java b/src/main/java/com/uber/cadence/internal/external/ManualActivityCompletionClientImpl.java
index ab30159bc..3367e705a 100644
--- a/src/main/java/com/uber/cadence/internal/external/ManualActivityCompletionClientImpl.java
+++ b/src/main/java/com/uber/cadence/internal/external/ManualActivityCompletionClientImpl.java
@@ -31,7 +31,7 @@
import com.uber.cadence.client.ActivityCompletionFailureException;
import com.uber.cadence.client.ActivityNotExistsException;
import com.uber.cadence.converter.DataConverter;
-import com.uber.cadence.internal.common.Retryer;
+import com.uber.cadence.internal.common.RpcRetryer;
import com.uber.cadence.internal.metrics.MetricsType;
import com.uber.cadence.serviceclient.IWorkflowService;
import com.uber.m3.tally.Scope;
@@ -95,9 +95,7 @@ public void complete(Object result) {
request.setResult(convertedResult);
request.setTaskToken(taskToken);
try {
- Retryer.retry(
- Retryer.DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS,
- () -> service.RespondActivityTaskCompleted(request));
+ RpcRetryer.retry(() -> service.RespondActivityTaskCompleted(request));
metricsScope.counter(MetricsType.ACTIVITY_TASK_COMPLETED_COUNTER).inc(1);
} catch (EntityNotExistsError e) {
throw new ActivityNotExistsException(e);
@@ -139,9 +137,7 @@ public void fail(Throwable failure) {
request.setDetails(dataConverter.toData(failure));
request.setTaskToken(taskToken);
try {
- Retryer.retry(
- Retryer.DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS,
- () -> service.RespondActivityTaskFailed(request));
+ RpcRetryer.retry(() -> service.RespondActivityTaskFailed(request));
metricsScope.counter(MetricsType.ACTIVITY_TASK_FAILED_COUNTER).inc(1);
} catch (EntityNotExistsError e) {
throw new ActivityNotExistsException(e);
@@ -156,9 +152,7 @@ public void fail(Throwable failure) {
request.setWorkflowID(execution.getWorkflowId());
request.setRunID(execution.getRunId());
try {
- Retryer.retry(
- Retryer.DEFAULT_SERVICE_OPERATION_RETRY_OPTIONS,
- () -> service.RespondActivityTaskFailedByID(request));
+ RpcRetryer.retry(() -> service.RespondActivityTaskFailedByID(request));
metricsScope.counter(MetricsType.ACTIVITY_TASK_FAILED_BY_ID_COUNTER).inc(1);
} catch (EntityNotExistsError e) {
throw new ActivityNotExistsException(e);
diff --git a/src/main/java/com/uber/cadence/internal/replay/ReplayDecider.java b/src/main/java/com/uber/cadence/internal/replay/ReplayDecider.java
index d019005e0..b3ddcf760 100644
--- a/src/main/java/com/uber/cadence/internal/replay/ReplayDecider.java
+++ b/src/main/java/com/uber/cadence/internal/replay/ReplayDecider.java
@@ -32,7 +32,7 @@
import com.uber.cadence.WorkflowType;
import com.uber.cadence.common.RetryOptions;
import com.uber.cadence.internal.common.OptionsUtils;
-import com.uber.cadence.internal.common.Retryer;
+import com.uber.cadence.internal.common.RpcRetryer;
import com.uber.cadence.internal.metrics.MetricsTag;
import com.uber.cadence.internal.metrics.MetricsType;
import com.uber.cadence.internal.replay.HistoryHelper.DecisionEvents;
@@ -667,7 +667,7 @@ public HistoryEvent next() {
try {
GetWorkflowExecutionHistoryResponse r =
- Retryer.retryWithResult(
+ RpcRetryer.retryWithResult(
retryOptions, () -> service.GetWorkflowExecutionHistory(request));
current = r.getHistory().getEventsIterator();
nextPageToken = r.getNextPageToken();
diff --git a/src/main/java/com/uber/cadence/internal/replay/ReplayDecisionTaskHandler.java b/src/main/java/com/uber/cadence/internal/replay/ReplayDecisionTaskHandler.java
index d06a0c01b..c1c6d9b05 100644
--- a/src/main/java/com/uber/cadence/internal/replay/ReplayDecisionTaskHandler.java
+++ b/src/main/java/com/uber/cadence/internal/replay/ReplayDecisionTaskHandler.java
@@ -113,7 +113,7 @@ public DecisionTaskHandler.Result handleDecisionTask(PollForDecisionTaskResponse
e.printStackTrace(pw);
String stackTrace = sw.toString();
failedRequest.setDetails(stackTrace.getBytes(StandardCharsets.UTF_8));
- return new DecisionTaskHandler.Result(null, failedRequest, null, null);
+ return new DecisionTaskHandler.Result(null, failedRequest, null);
}
}
@@ -236,7 +236,7 @@ private Result processQuery(PollForDecisionTaskResponse decisionTask) {
cache.markProcessingDone(decisionTask);
}
}
- return new Result(null, null, queryCompletedRequest, null);
+ return new Result(null, null, queryCompletedRequest);
}
private Result createCompletedRequest(
@@ -254,7 +254,7 @@ private Result createCompletedRequest(
(int) stickyTaskListScheduleToStartTimeout.getSeconds());
completedRequest.setStickyAttributes(attributes);
}
- return new Result(completedRequest, null, null, null);
+ return new Result(completedRequest, null, null);
}
@Override
diff --git a/src/main/java/com/uber/cadence/internal/sync/ActivityInvocationHandler.java b/src/main/java/com/uber/cadence/internal/sync/ActivityInvocationHandler.java
index 17836bb5f..2bf87603e 100644
--- a/src/main/java/com/uber/cadence/internal/sync/ActivityInvocationHandler.java
+++ b/src/main/java/com/uber/cadence/internal/sync/ActivityInvocationHandler.java
@@ -1,8 +1,8 @@
/*
+ * Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
+ * Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
- * Modifications copyright (C) 2017 Uber Technologies, Inc.
- *
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
@@ -17,6 +17,7 @@
package com.uber.cadence.internal.sync;
+import com.google.common.base.Strings;
import com.uber.cadence.activity.ActivityMethod;
import com.uber.cadence.activity.ActivityOptions;
import com.uber.cadence.common.MethodRetry;
@@ -24,6 +25,7 @@
import com.uber.cadence.workflow.WorkflowInterceptor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import java.time.Duration;
import java.util.function.Function;
class ActivityInvocationHandler extends ActivityInvocationHandlerBase {
@@ -31,20 +33,48 @@ class ActivityInvocationHandler extends ActivityInvocationHandlerBase {
private final WorkflowInterceptor activityExecutor;
static InvocationHandler newInstance(
- ActivityOptions options, WorkflowInterceptor activityExecutor) {
- return new ActivityInvocationHandler(options, activityExecutor);
+ Class> activityInterface, ActivityOptions options, WorkflowInterceptor activityExecutor) {
+ return new ActivityInvocationHandler(activityInterface, activityExecutor, options);
}
- private ActivityInvocationHandler(ActivityOptions options, WorkflowInterceptor activityExecutor) {
+ private ActivityInvocationHandler(
+ Class> activityInterface, WorkflowInterceptor activityExecutor, ActivityOptions options) {
this.options = options;
this.activityExecutor = activityExecutor;
+ init(activityInterface);
}
+ @SuppressWarnings("deprecation")
@Override
protected Function