|
38 | 38 | import io.temporal.common.metadata.POJOWorkflowImplMetadata;
|
39 | 39 | import io.temporal.common.metadata.POJOWorkflowInterfaceMetadata;
|
40 | 40 | import io.temporal.common.metadata.POJOWorkflowMethodMetadata;
|
| 41 | +import io.temporal.internal.WorkflowThreadMarker; |
41 | 42 | import io.temporal.internal.common.ActivityOptionUtils;
|
| 43 | +import io.temporal.internal.common.NonIdempotentHandle; |
42 | 44 | import io.temporal.internal.common.SearchAttributesUtil;
|
43 | 45 | import io.temporal.internal.logging.ReplayAwareLogger;
|
44 | 46 | import io.temporal.serviceclient.CheckedExceptionWrapper;
|
@@ -395,14 +397,6 @@ public static <R> R executeActivity(
|
395 | 397 | return result.get();
|
396 | 398 | }
|
397 | 399 |
|
398 |
| - private static WorkflowOutboundCallsInterceptor getWorkflowOutboundInterceptor() { |
399 |
| - return getRootWorkflowContext().getWorkflowOutboundInterceptor(); |
400 |
| - } |
401 |
| - |
402 |
| - static SyncWorkflowContext getRootWorkflowContext() { |
403 |
| - return DeterministicRunnerImpl.currentThreadInternal().getWorkflowContext(); |
404 |
| - } |
405 |
| - |
406 | 400 | public static void await(String reason, Supplier<Boolean> unblockCondition)
|
407 | 401 | throws DestroyWorkflowThreadError {
|
408 | 402 | getWorkflowOutboundInterceptor().await(reason, unblockCondition);
|
@@ -464,19 +458,12 @@ public static Throwable unwrap(Throwable e) {
|
464 | 458 | return CheckedExceptionWrapper.unwrap(e);
|
465 | 459 | }
|
466 | 460 |
|
467 |
| - /** Prohibit instantiation */ |
468 |
| - private WorkflowInternal() {} |
469 |
| - |
470 | 461 | /** Returns false if not under workflow code. */
|
471 | 462 | public static boolean isReplaying() {
|
472 | 463 | Optional<WorkflowThread> thread = DeterministicRunnerImpl.currentThreadInternalIfPresent();
|
473 | 464 | return thread.isPresent() && getRootWorkflowContext().isReplaying();
|
474 | 465 | }
|
475 | 466 |
|
476 |
| - public static WorkflowInfo getWorkflowInfo() { |
477 |
| - return new WorkflowInfoImpl(getRootWorkflowContext().getReplayContext()); |
478 |
| - } |
479 |
| - |
480 | 467 | public static <T> T getMemo(String key, Class<T> valueClass, Type genericType) {
|
481 | 468 | Payload memo = getRootWorkflowContext().getReplayContext().getMemo(key);
|
482 | 469 | if (memo == null) {
|
@@ -520,6 +507,24 @@ public static void sleep(Duration duration) {
|
520 | 507 | getWorkflowOutboundInterceptor().sleep(duration);
|
521 | 508 | }
|
522 | 509 |
|
| 510 | + public static boolean isWorkflowThread() { |
| 511 | + return WorkflowThreadMarker.isWorkflowThread(); |
| 512 | + } |
| 513 | + |
| 514 | + public static <T> T deadlockDetectorOff(Functions.Func<T> func) { |
| 515 | + if (isWorkflowThread()) { |
| 516 | + try (NonIdempotentHandle ignored = getWorkflowThread().lockDeadlockDetector()) { |
| 517 | + return func.apply(); |
| 518 | + } |
| 519 | + } else { |
| 520 | + return func.apply(); |
| 521 | + } |
| 522 | + } |
| 523 | + |
| 524 | + public static WorkflowInfo getWorkflowInfo() { |
| 525 | + return new WorkflowInfoImpl(getRootWorkflowContext().getReplayContext()); |
| 526 | + } |
| 527 | + |
523 | 528 | public static Scope getMetricsScope() {
|
524 | 529 | return getRootWorkflowContext().getMetricsScope();
|
525 | 530 | }
|
@@ -614,4 +619,19 @@ public static Optional<Exception> getPreviousRunFailure() {
|
614 | 619 | // converter
|
615 | 620 | .map(f -> getDataConverter().failureToException(f));
|
616 | 621 | }
|
| 622 | + |
| 623 | + private static WorkflowOutboundCallsInterceptor getWorkflowOutboundInterceptor() { |
| 624 | + return getRootWorkflowContext().getWorkflowOutboundInterceptor(); |
| 625 | + } |
| 626 | + |
| 627 | + static SyncWorkflowContext getRootWorkflowContext() { |
| 628 | + return DeterministicRunnerImpl.currentThreadInternal().getWorkflowContext(); |
| 629 | + } |
| 630 | + |
| 631 | + private static WorkflowThread getWorkflowThread() { |
| 632 | + return DeterministicRunnerImpl.currentThreadInternal(); |
| 633 | + } |
| 634 | + |
| 635 | + /** Prohibit instantiation */ |
| 636 | + private WorkflowInternal() {} |
617 | 637 | }
|
0 commit comments