Skip to content

Commit 300a66b

Browse files
committed
Add WorkflowStubOutboundInterceptor which provides an access to Headers
Partially addresses #373.
1 parent b3fad1d commit 300a66b

File tree

7 files changed

+340
-130
lines changed

7 files changed

+340
-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+
WorkflowStubCallsInterceptor interceptStub(WorkflowStubCallsInterceptor next);
3748
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,10 @@ public WorkflowStub newUntypedWorkflowStub(
4444
public ActivityCompletionClient newActivityCompletionClient(ActivityCompletionClient next) {
4545
return next;
4646
}
47+
48+
@Override
49+
public WorkflowStubCallsInterceptor interceptStub(
50+
WorkflowStubCallsInterceptor next) {
51+
return next;
52+
}
4753
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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 WorkflowStubCallsInterceptor {
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+
private final WorkflowInput workflowInput;
52+
private final String signalName;
53+
private final Object[] signalArguments;
54+
55+
public WorkflowInputWithSignal(
56+
WorkflowInput workflowInput, String signalName, Object[] signalArguments) {
57+
this.workflowInput = workflowInput;
58+
this.signalName = signalName;
59+
this.signalArguments = signalArguments;
60+
}
61+
62+
public WorkflowInput getWorkflowInput() {
63+
return workflowInput;
64+
}
65+
66+
public String getSignalName() {
67+
return signalName;
68+
}
69+
70+
public Object[] getSignalArguments() {
71+
return signalArguments;
72+
}
73+
}
74+
75+
final class WorkflowOutput {
76+
private final WorkflowExecution workflowExecution;
77+
78+
public WorkflowOutput(WorkflowExecution workflowExecution) {
79+
this.workflowExecution = workflowExecution;
80+
}
81+
82+
public WorkflowExecution getWorkflowExecution() {
83+
return workflowExecution;
84+
}
85+
}
86+
87+
WorkflowOutput start(WorkflowInput input);
88+
89+
WorkflowOutput signalWithStart(WorkflowInputWithSignal input);
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
/** Convenience base class for {@link WorkflowStubCallsInterceptor} implementations. */
23+
public class WorkflowStubCallsInterceptorBase implements WorkflowStubCallsInterceptor {
24+
25+
private final WorkflowStubCallsInterceptor next;
26+
27+
public WorkflowStubCallsInterceptorBase(WorkflowStubCallsInterceptor next) {
28+
this.next = next;
29+
}
30+
31+
@Override
32+
public WorkflowOutput start(WorkflowInput input) {
33+
return next.start(input);
34+
}
35+
36+
@Override
37+
public WorkflowOutput signalWithStart(WorkflowInputWithSignal input) {
38+
return next.signalWithStart(input);
39+
}
40+
}

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)