Skip to content

Commit b4b89bd

Browse files
committed
Add WorkflowStubOutboundInterceptor which provides and access to Headers
Partially addresses #373.
1 parent b3fad1d commit b4b89bd

File tree

6 files changed

+297
-130
lines changed

6 files changed

+297
-130
lines changed

temporal-sdk/src/main/java/io/temporal/common/interceptors/WorkflowClientInterceptor.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,23 @@
2626
import java.util.Optional;
2727

2828
public interface WorkflowClientInterceptor {
29-
29+
/**
30+
* Called when workflow stub is created during creation of new workflow.
31+
*
32+
* @return decorated stub
33+
*/
3034
WorkflowStub newUntypedWorkflowStub(
3135
String workflowType, WorkflowOptions options, WorkflowStub next);
3236

37+
/**
38+
* Called when workflow stub is created for a known existing execution
39+
*
40+
* @return decorated stub
41+
*/
3342
WorkflowStub newUntypedWorkflowStub(
3443
WorkflowExecution execution, Optional<String> workflowType, WorkflowStub next);
3544

3645
ActivityCompletionClient newActivityCompletionClient(ActivityCompletionClient next);
46+
47+
WorkflowStubOutboundInterceptor interceptStub(WorkflowStubOutboundInterceptor next);
3748
}

temporal-sdk/src/main/java/io/temporal/common/interceptors/WorkflowClientInterceptorBase.java

+5
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@ public WorkflowStub newUntypedWorkflowStub(
4444
public ActivityCompletionClient newActivityCompletionClient(ActivityCompletionClient next) {
4545
return next;
4646
}
47+
48+
@Override
49+
public WorkflowStubOutboundInterceptor interceptStub(WorkflowStubOutboundInterceptor next) {
50+
return next;
51+
}
4752
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved.
3+
*
4+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
9+
* use this file except in compliance with the License. A copy of the License is
10+
* located at
11+
*
12+
* http://aws.amazon.com/apache2.0
13+
*
14+
* or in the "license" file accompanying this file. This file is distributed on
15+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
16+
* express or implied. See the License for the specific language governing
17+
* permissions and limitations under the License.
18+
*/
19+
20+
package io.temporal.common.interceptors;
21+
22+
import io.temporal.api.common.v1.WorkflowExecution;
23+
import io.temporal.client.WorkflowOptions;
24+
25+
public interface WorkflowStubOutboundInterceptor {
26+
final class WorkflowInput {
27+
private final Header header;
28+
private final Object[] arguments;
29+
private final WorkflowOptions options;
30+
31+
public WorkflowInput(Header header, Object[] arguments, WorkflowOptions options) {
32+
this.header = header;
33+
this.arguments = arguments;
34+
this.options = options;
35+
}
36+
37+
public Header getHeader() {
38+
return header;
39+
}
40+
41+
public Object[] getArguments() {
42+
return arguments;
43+
}
44+
45+
public WorkflowOptions getOptions() {
46+
return options;
47+
}
48+
}
49+
50+
final class WorkflowInputWithSignal {
51+
52+
private final WorkflowInput workflowInput;
53+
private final String signalName;
54+
private final Object[] signalArguments;
55+
56+
public WorkflowInputWithSignal(
57+
WorkflowInput workflowInput, String signalName, Object[] signalArguments) {
58+
this.workflowInput = workflowInput;
59+
this.signalName = signalName;
60+
this.signalArguments = signalArguments;
61+
}
62+
63+
public WorkflowInput getWorkflowInput() {
64+
return workflowInput;
65+
}
66+
67+
public String getSignalName() {
68+
return signalName;
69+
}
70+
71+
public Object[] getSignalArguments() {
72+
return signalArguments;
73+
}
74+
}
75+
76+
final class WorkflowOutput {
77+
private final WorkflowExecution workflowExecution;
78+
79+
public WorkflowOutput(WorkflowExecution workflowExecution) {
80+
this.workflowExecution = workflowExecution;
81+
}
82+
83+
public WorkflowExecution getWorkflowExecution() {
84+
return workflowExecution;
85+
}
86+
}
87+
88+
WorkflowOutput startWithOptions(WorkflowInput input);
89+
90+
WorkflowOutput signalWithStartWithOptions(WorkflowInputWithSignal input);
91+
}

temporal-sdk/src/main/java/io/temporal/internal/sync/SyncWorkflowContext.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,7 @@ private Promise<Optional<Payloads>> executeChildWorkflow(
409409
attributes.setCronSchedule(OptionsUtils.safeGet(options.getCronSchedule()));
410410
io.temporal.api.common.v1.Header grpcHeader =
411411
toHeaderGrpc(header, extractContextsAndConvertToBytes(propagators));
412-
if (grpcHeader != null) {
413-
attributes.setHeader(grpcHeader);
414-
}
412+
attributes.setHeader(grpcHeader);
415413
ParentClosePolicy parentClosePolicy = options.getParentClosePolicy();
416414
if (parentClosePolicy != null) {
417415
attributes.setParentClosePolicy(parentClosePolicy);

0 commit comments

Comments
 (0)