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

temporalio / sdk-java / #169

pending completion
#169

push

github-actions

web-flow
Remove use of deprecated API (#1758)

4 of 4 new or added lines in 1 file covered. (100.0%)

17345 of 21558 relevant lines covered (80.46%)

0.8 hits per line

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

80.28
/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.workflow.*;
28
import io.temporal.workflow.Functions.Func;
29
import java.lang.reflect.Type;
30
import java.time.Duration;
31
import java.util.List;
32
import java.util.Map;
33
import java.util.Random;
34
import java.util.UUID;
35
import java.util.function.BiPredicate;
36
import java.util.function.Supplier;
37
import javax.annotation.Nullable;
38

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

243
  final class ChildWorkflowOutput<R> {
244

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

431
    public String getUpdateName() {
432
      return updateName;
×
433
    }
434

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

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

443
    public Class<?>[] getArgTypes() {
444
      return argTypes;
×
445
    }
446

447
    public Type[] getGenericArgTypes() {
448
      return genericArgTypes;
×
449
    }
450
  }
451

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

456
    public RegisterUpdateHandlersInput(List<UpdateRegistrationRequest> requests) {
×
457
      this.requests = requests;
×
458
    }
×
459

460
    public List<UpdateRegistrationRequest> getRequests() {
461
      return requests;
×
462
    }
463
  }
464

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

542
  Random newRandom();
543

544
  SignalExternalOutput signalExternalWorkflow(SignalExternalInput input);
545

546
  CancelWorkflowOutput cancelWorkflow(CancelWorkflowInput input);
547

548
  void sleep(Duration duration);
549

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

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

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

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

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

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

563
  void continueAsNew(ContinueAsNewInput input);
564

565
  void registerQuery(RegisterQueryInput input);
566

567
  void registerSignalHandlers(RegisterSignalHandlersInput input);
568

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

572
  void registerDynamicSignalHandler(RegisterDynamicSignalHandlerInput handler);
573

574
  void registerDynamicQueryHandler(RegisterDynamicQueryHandlerInput input);
575

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

579
  UUID randomUUID();
580

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

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

596
  long currentTimeMillis();
597
}
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

© 2026 Coveralls, Inc