• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #175

pending completion
#175

push

github-actions

web-flow
Worker / Build Id versioning (#1786)

Implement new worker build id based versioning feature

236 of 236 new or added lines in 24 files covered. (100.0%)

18343 of 23697 relevant lines covered (77.41%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.55
/temporal-sdk/src/main/java/io/temporal/common/interceptors/WorkflowOutboundCallsInterceptor.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 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");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.common.interceptors;
22

23
import io.temporal.activity.ActivityOptions;
24
import io.temporal.activity.LocalActivityOptions;
25
import io.temporal.api.common.v1.WorkflowExecution;
26
import io.temporal.common.Experimental;
27
import io.temporal.common.SearchAttributeUpdate;
28
import io.temporal.workflow.*;
29
import io.temporal.workflow.Functions.Func;
30
import java.lang.reflect.Type;
31
import java.time.Duration;
32
import java.util.List;
33
import java.util.Map;
34
import java.util.Random;
35
import java.util.UUID;
36
import java.util.function.BiPredicate;
37
import java.util.function.Supplier;
38
import javax.annotation.Nullable;
39

40
/**
41
 * Can be used to intercept calls from to workflow code into the Temporal APIs.
42
 *
43
 * <p>The calls to the interceptor are executed in the context of a workflow and must follow the
44
 * same rules all the other workflow code follows.
45
 *
46
 * <p>Prefer extending {@link WorkflowOutboundCallsInterceptorBase} and overriding only the methods
47
 * you need instead of implementing this interface directly. {@link
48
 * WorkflowOutboundCallsInterceptorBase} provides correct default implementations to all the methods
49
 * of this interface.
50
 *
51
 * <p>An instance may be created in {@link
52
 * WorkflowInboundCallsInterceptor#init(WorkflowOutboundCallsInterceptor)} and set by passing it
53
 * into {@code init} method of the {@code next} {@link WorkflowInboundCallsInterceptor} The
54
 * implementation must forward all the calls to the outbound interceptor passed as a {@code
55
 * outboundCalls} parameter to the {@code init} call.
56
 *
57
 * @see WorkerInterceptor#interceptWorkflow for the definition of "next" {@link
58
 *     WorkflowInboundCallsInterceptor}.
59
 */
60
@Experimental
61
public interface WorkflowOutboundCallsInterceptor {
62

63
  final class ActivityInput<R> {
64
    private final String activityName;
65
    private final Class<R> resultClass;
66
    private final Type resultType;
67
    private final Object[] args;
68
    private final ActivityOptions options;
69
    private final Header header;
70

71
    public ActivityInput(
72
        String activityName,
73
        Class<R> resultClass,
74
        Type resultType,
75
        Object[] args,
76
        ActivityOptions options,
77
        Header header) {
1✔
78
      this.activityName = activityName;
1✔
79
      this.resultClass = resultClass;
1✔
80
      this.resultType = resultType;
1✔
81
      this.args = args;
1✔
82
      this.options = options;
1✔
83
      this.header = header;
1✔
84
    }
1✔
85

86
    public String getActivityName() {
87
      return activityName;
1✔
88
    }
89

90
    public Class<R> getResultClass() {
91
      return resultClass;
1✔
92
    }
93

94
    public Type getResultType() {
95
      return resultType;
1✔
96
    }
97

98
    public Object[] getArgs() {
99
      return args;
1✔
100
    }
101

102
    public ActivityOptions getOptions() {
103
      return options;
1✔
104
    }
105

106
    public Header getHeader() {
107
      return header;
1✔
108
    }
109
  }
110

111
  final class ActivityOutput<R> {
112
    private final String activityId;
113
    private final Promise<R> result;
114

115
    public ActivityOutput(String activityId, Promise<R> result) {
1✔
116
      this.activityId = activityId;
1✔
117
      this.result = result;
1✔
118
    }
1✔
119

120
    public String getActivityId() {
121
      return activityId;
1✔
122
    }
123

124
    public Promise<R> getResult() {
125
      return result;
1✔
126
    }
127
  }
128

129
  final class LocalActivityInput<R> {
130
    private final String activityName;
131
    private final Class<R> resultClass;
132
    private final Type resultType;
133
    private final Object[] args;
134
    private final LocalActivityOptions options;
135
    private final Header header;
136

137
    public LocalActivityInput(
138
        String activityName,
139
        Class<R> resultClass,
140
        Type resultType,
141
        Object[] args,
142
        LocalActivityOptions options,
143
        Header header) {
1✔
144
      this.activityName = activityName;
1✔
145
      this.resultClass = resultClass;
1✔
146
      this.resultType = resultType;
1✔
147
      this.args = args;
1✔
148
      this.options = options;
1✔
149
      this.header = header;
1✔
150
    }
1✔
151

152
    public String getActivityName() {
153
      return activityName;
1✔
154
    }
155

156
    public Class<R> getResultClass() {
157
      return resultClass;
1✔
158
    }
159

160
    public Type getResultType() {
161
      return resultType;
1✔
162
    }
163

164
    public Object[] getArgs() {
165
      return args;
1✔
166
    }
167

168
    public LocalActivityOptions getOptions() {
169
      return options;
1✔
170
    }
171

172
    public Header getHeader() {
173
      return header;
1✔
174
    }
175
  }
176

177
  final class LocalActivityOutput<R> {
178
    private final Promise<R> result;
179

180
    public LocalActivityOutput(Promise<R> result) {
1✔
181
      this.result = result;
1✔
182
    }
1✔
183

184
    public Promise<R> getResult() {
185
      return result;
1✔
186
    }
187
  }
188

189
  final class ChildWorkflowInput<R> {
190
    private final String workflowId;
191
    private final String workflowType;
192
    private final Class<R> resultClass;
193
    private final Type resultType;
194
    private final Object[] args;
195
    private final ChildWorkflowOptions options;
196
    private final Header header;
197

198
    public ChildWorkflowInput(
199
        String workflowId,
200
        String workflowType,
201
        Class<R> resultClass,
202
        Type resultType,
203
        Object[] args,
204
        ChildWorkflowOptions options,
205
        Header header) {
1✔
206
      this.workflowId = workflowId;
1✔
207
      this.workflowType = workflowType;
1✔
208
      this.resultClass = resultClass;
1✔
209
      this.resultType = resultType;
1✔
210
      this.args = args;
1✔
211
      this.options = options;
1✔
212
      this.header = header;
1✔
213
    }
1✔
214

215
    public String getWorkflowId() {
216
      return workflowId;
1✔
217
    }
218

219
    public String getWorkflowType() {
220
      return workflowType;
1✔
221
    }
222

223
    public Class<R> getResultClass() {
224
      return resultClass;
1✔
225
    }
226

227
    public Type getResultType() {
228
      return resultType;
1✔
229
    }
230

231
    public Object[] getArgs() {
232
      return args;
1✔
233
    }
234

235
    public ChildWorkflowOptions getOptions() {
236
      return options;
1✔
237
    }
238

239
    public Header getHeader() {
240
      return header;
1✔
241
    }
242
  }
243

244
  final class ChildWorkflowOutput<R> {
245

246
    private final Promise<R> result;
247
    private final Promise<WorkflowExecution> workflowExecution;
248

249
    public ChildWorkflowOutput(Promise<R> result, Promise<WorkflowExecution> workflowExecution) {
1✔
250
      this.result = result;
1✔
251
      this.workflowExecution = workflowExecution;
1✔
252
    }
1✔
253

254
    public Promise<R> getResult() {
255
      return result;
1✔
256
    }
257

258
    public Promise<WorkflowExecution> getWorkflowExecution() {
259
      return workflowExecution;
1✔
260
    }
261
  }
262

263
  final class SignalExternalInput {
264
    private final WorkflowExecution execution;
265
    private final String signalName;
266
    private final Object[] args;
267

268
    public SignalExternalInput(WorkflowExecution execution, String signalName, Object[] args) {
1✔
269
      this.execution = execution;
1✔
270
      this.signalName = signalName;
1✔
271
      this.args = args;
1✔
272
    }
1✔
273

274
    public WorkflowExecution getExecution() {
275
      return execution;
1✔
276
    }
277

278
    public String getSignalName() {
279
      return signalName;
1✔
280
    }
281

282
    public Object[] getArgs() {
283
      return args;
1✔
284
    }
285
  }
286

287
  final class SignalExternalOutput {
288
    private final Promise<Void> result;
289

290
    public SignalExternalOutput(Promise<Void> result) {
1✔
291
      this.result = result;
1✔
292
    }
1✔
293

294
    public Promise<Void> getResult() {
295
      return result;
1✔
296
    }
297
  }
298

299
  final class CancelWorkflowInput {
300
    private final WorkflowExecution execution;
301

302
    public CancelWorkflowInput(WorkflowExecution execution) {
×
303
      this.execution = execution;
×
304
    }
×
305

306
    public WorkflowExecution getExecution() {
307
      return execution;
×
308
    }
309
  }
310

311
  final class CancelWorkflowOutput {
312
    private final Promise<Void> result;
313

314
    public CancelWorkflowOutput(Promise<Void> result) {
×
315
      this.result = result;
×
316
    }
×
317

318
    public Promise<Void> getResult() {
319
      return result;
×
320
    }
321
  }
322

323
  final class ContinueAsNewInput {
324
    private final @Nullable String workflowType;
325
    private final @Nullable ContinueAsNewOptions options;
326
    private final Object[] args;
327
    private final Header header;
328

329
    public ContinueAsNewInput(
330
        @Nullable String workflowType,
331
        @Nullable ContinueAsNewOptions options,
332
        Object[] args,
333
        Header header) {
1✔
334
      this.workflowType = workflowType;
1✔
335
      this.options = options;
1✔
336
      this.args = args;
1✔
337
      this.header = header;
1✔
338
    }
1✔
339

340
    /**
341
     * @return workflowType for the continue-as-new workflow run. null if continue-as-new should
342
     *     inherit the type of the original workflow run.
343
     */
344
    public @Nullable String getWorkflowType() {
345
      return workflowType;
1✔
346
    }
347

348
    /**
349
     * @return options for the continue-as-new workflow run. Can be null, in that case the values
350
     *     will be taken from the original workflow run.
351
     */
352
    public @Nullable ContinueAsNewOptions getOptions() {
353
      return options;
1✔
354
    }
355

356
    public Object[] getArgs() {
357
      return args;
1✔
358
    }
359

360
    public Header getHeader() {
361
      return header;
1✔
362
    }
363
  }
364

365
  final class SignalRegistrationRequest {
366
    private final String signalType;
367
    private final Class<?>[] argTypes;
368
    private final Type[] genericArgTypes;
369
    private final Functions.Proc1<Object[]> callback;
370

371
    public SignalRegistrationRequest(
372
        String signalType,
373
        Class<?>[] argTypes,
374
        Type[] genericArgTypes,
375
        Functions.Proc1<Object[]> callback) {
1✔
376
      this.signalType = signalType;
1✔
377
      this.argTypes = argTypes;
1✔
378
      this.genericArgTypes = genericArgTypes;
1✔
379
      this.callback = callback;
1✔
380
    }
1✔
381

382
    public String getSignalType() {
383
      return signalType;
1✔
384
    }
385

386
    public Class<?>[] getArgTypes() {
387
      return argTypes;
1✔
388
    }
389

390
    public Type[] getGenericArgTypes() {
391
      return genericArgTypes;
1✔
392
    }
393

394
    public Functions.Proc1<Object[]> getCallback() {
395
      return callback;
1✔
396
    }
397
  }
398

399
  final class RegisterSignalHandlersInput {
400
    private final List<SignalRegistrationRequest> requests;
401

402
    public RegisterSignalHandlersInput(List<SignalRegistrationRequest> requests) {
1✔
403
      this.requests = requests;
1✔
404
    }
1✔
405

406
    public List<SignalRegistrationRequest> getRequests() {
407
      return requests;
1✔
408
    }
409
  }
410

411
  @Experimental
412
  final class UpdateRegistrationRequest {
413
    private final Functions.Func1<Object[], Object> executeCallback;
414
    private final Functions.Proc1<Object[]> validateCallback;
415
    private final String updateName;
416
    private final Class<?>[] argTypes;
417
    private final Type[] genericArgTypes;
418

419
    public UpdateRegistrationRequest(
420
        String updateName,
421
        Class<?>[] argTypes,
422
        Type[] genericArgTypes,
423
        Functions.Proc1<Object[]> validateCallback,
424
        Functions.Func1<Object[], Object> executeCallback) {
1✔
425
      this.updateName = updateName;
1✔
426
      this.argTypes = argTypes;
1✔
427
      this.genericArgTypes = genericArgTypes;
1✔
428
      this.validateCallback = validateCallback;
1✔
429
      this.executeCallback = executeCallback;
1✔
430
    }
1✔
431

432
    public String getUpdateName() {
433
      return updateName;
1✔
434
    }
435

436
    public Functions.Proc1<Object[]> getValidateCallback() {
437
      return validateCallback;
1✔
438
    }
439

440
    public Functions.Func1<Object[], Object> getExecuteCallback() {
441
      return executeCallback;
1✔
442
    }
443

444
    public Class<?>[] getArgTypes() {
445
      return argTypes;
1✔
446
    }
447

448
    public Type[] getGenericArgTypes() {
449
      return genericArgTypes;
1✔
450
    }
451
  }
452

453
  @Experimental
454
  final class RegisterUpdateHandlersInput {
455
    private final List<UpdateRegistrationRequest> requests;
456

457
    public RegisterUpdateHandlersInput(List<UpdateRegistrationRequest> requests) {
1✔
458
      this.requests = requests;
1✔
459
    }
1✔
460

461
    public List<UpdateRegistrationRequest> getRequests() {
462
      return requests;
1✔
463
    }
464
  }
465

466
  final class RegisterQueryInput {
467
    private final String queryType;
468
    private final Class<?>[] argTypes;
469
    private final Type[] genericArgTypes;
470
    private final Functions.Func1<Object[], Object> callback;
471

472
    public RegisterQueryInput(
473
        String queryType,
474
        Class<?>[] argTypes,
475
        Type[] genericArgTypes,
476
        Functions.Func1<Object[], Object> callback) {
1✔
477
      this.queryType = queryType;
1✔
478
      this.argTypes = argTypes;
1✔
479
      this.genericArgTypes = genericArgTypes;
1✔
480
      this.callback = callback;
1✔
481
    }
1✔
482

483
    public String getQueryType() {
484
      return queryType;
1✔
485
    }
486

487
    public Class<?>[] getArgTypes() {
488
      return argTypes;
1✔
489
    }
490

491
    public Type[] getGenericArgTypes() {
492
      return genericArgTypes;
1✔
493
    }
494

495
    public Functions.Func1<Object[], Object> getCallback() {
496
      return callback;
1✔
497
    }
498
  }
499

500
  final class RegisterDynamicQueryHandlerInput {
501
    private final DynamicQueryHandler handler;
502

503
    public RegisterDynamicQueryHandlerInput(DynamicQueryHandler handler) {
1✔
504
      this.handler = handler;
1✔
505
    }
1✔
506

507
    public DynamicQueryHandler getHandler() {
508
      return handler;
1✔
509
    }
510
  }
511

512
  final class RegisterDynamicSignalHandlerInput {
513
    private final DynamicSignalHandler handler;
514

515
    public RegisterDynamicSignalHandlerInput(DynamicSignalHandler handler) {
1✔
516
      this.handler = handler;
1✔
517
    }
1✔
518

519
    public DynamicSignalHandler getHandler() {
520
      return handler;
1✔
521
    }
522
  }
523

524
  @Experimental
525
  final class RegisterDynamicUpdateHandlerInput {
526
    private final DynamicUpdateHandler handler;
527

528
    public RegisterDynamicUpdateHandlerInput(DynamicUpdateHandler handler) {
×
529
      this.handler = handler;
×
530
    }
×
531

532
    public DynamicUpdateHandler getHandler() {
533
      return handler;
×
534
    }
535
  }
536

537
  <R> ActivityOutput<R> executeActivity(ActivityInput<R> input);
538

539
  <R> LocalActivityOutput<R> executeLocalActivity(LocalActivityInput<R> input);
540

541
  <R> ChildWorkflowOutput<R> executeChildWorkflow(ChildWorkflowInput<R> input);
542

543
  Random newRandom();
544

545
  SignalExternalOutput signalExternalWorkflow(SignalExternalInput input);
546

547
  CancelWorkflowOutput cancelWorkflow(CancelWorkflowInput input);
548

549
  void sleep(Duration duration);
550

551
  boolean await(Duration timeout, String reason, Supplier<Boolean> unblockCondition);
552

553
  void await(String reason, Supplier<Boolean> unblockCondition);
554

555
  Promise<Void> newTimer(Duration duration);
556

557
  <R> R sideEffect(Class<R> resultClass, Type resultType, Func<R> func);
558

559
  <R> R mutableSideEffect(
560
      String id, Class<R> resultClass, Type resultType, BiPredicate<R, R> updated, Func<R> func);
561

562
  int getVersion(String changeId, int minSupported, int maxSupported);
563

564
  void continueAsNew(ContinueAsNewInput input);
565

566
  void registerQuery(RegisterQueryInput input);
567

568
  void registerSignalHandlers(RegisterSignalHandlersInput input);
569

570
  @Experimental
571
  void registerUpdateHandlers(RegisterUpdateHandlersInput input);
572

573
  void registerDynamicSignalHandler(RegisterDynamicSignalHandlerInput handler);
574

575
  void registerDynamicQueryHandler(RegisterDynamicQueryHandlerInput input);
576

577
  @Experimental
578
  void registerDynamicUpdateHandler(RegisterDynamicUpdateHandlerInput input);
579

580
  UUID randomUUID();
581

582
  void upsertSearchAttributes(Map<String, ?> searchAttributes);
583

584
  void upsertTypedSearchAttributes(SearchAttributeUpdate<?>... searchAttributeUpdates);
585

586
  /**
587
   * Intercepts creation of a workflow child thread.
588
   *
589
   * <p>Please note, that "workflow child thread" and "child workflow" are different and independent
590
   * concepts.
591
   *
592
   * @param runnable thread function to run
593
   * @param detached if this thread is detached from the parent {@link CancellationScope}
594
   * @param name name of the thread
595
   * @return created WorkflowThread
596
   */
597
  Object newChildThread(Runnable runnable, boolean detached, String name);
598

599
  long currentTimeMillis();
600
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc