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

temporalio / sdk-java / #188

25 Sep 2023 04:42PM UTC coverage: 77.369% (-0.3%) from 77.663%
#188

push

github-actions

web-flow
Fix null pointer on trigger immediately (#1865)

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

18670 of 24131 relevant lines covered (77.37%)

0.77 hits per line

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

96.62
/temporal-sdk/src/main/java/io/temporal/common/interceptors/WorkflowClientCallsInterceptor.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.api.common.v1.WorkflowExecution;
24
import io.temporal.api.enums.v1.WorkflowExecutionStatus;
25
import io.temporal.api.update.v1.UpdateRef;
26
import io.temporal.api.update.v1.WaitPolicy;
27
import io.temporal.client.WorkflowOptions;
28
import io.temporal.common.Experimental;
29
import java.lang.reflect.Type;
30
import java.util.Optional;
31
import java.util.concurrent.CompletableFuture;
32
import java.util.concurrent.TimeUnit;
33
import java.util.concurrent.TimeoutException;
34
import javax.annotation.Nonnull;
35
import javax.annotation.Nullable;
36

37
/**
38
 * Intercepts calls to the {@link io.temporal.client.WorkflowClient} related to the lifecycle of a
39
 * Workflow.
40
 *
41
 * <p>Prefer extending {@link WorkflowClientCallsInterceptorBase} and overriding only the methods
42
 * you need instead of implementing this interface directly. {@link
43
 * WorkflowClientCallsInterceptorBase} provides correct default implementations to all the methods
44
 * of this interface.
45
 */
46
@Experimental
47
public interface WorkflowClientCallsInterceptor {
48
  /**
49
   * If you implement this method, {@link #signalWithStart} most likely needs to be implemented too.
50
   *
51
   * @see #signalWithStart
52
   */
53
  WorkflowStartOutput start(WorkflowStartInput input);
54

55
  /**
56
   * If you implement this method, {@link #signalWithStart} most likely needs to be implemented too.
57
   *
58
   * @see #signalWithStart
59
   */
60
  WorkflowSignalOutput signal(WorkflowSignalInput input);
61

62
  WorkflowSignalWithStartOutput signalWithStart(WorkflowSignalWithStartInput input);
63

64
  /**
65
   * If you implement this method, {@link #getResultAsync} most likely needs to be implemented too.
66
   *
67
   * @see #getResultAsync
68
   */
69
  <R> GetResultOutput<R> getResult(GetResultInput<R> input) throws TimeoutException;
70

71
  /**
72
   * If you implement this method, {@link #getResult} most likely needs to be implemented too.
73
   *
74
   * @see #getResult
75
   */
76
  <R> GetResultAsyncOutput<R> getResultAsync(GetResultInput<R> input);
77

78
  <R> QueryOutput<R> query(QueryInput<R> input);
79

80
  @Experimental
81
  <R> StartUpdateOutput<R> startUpdate(StartUpdateInput<R> input);
82

83
  @Experimental
84
  <R> PollWorkflowUpdateOutput<R> pollWorkflowUpdate(PollWorkflowUpdateInput<R> input);
85

86
  CancelOutput cancel(CancelInput input);
87

88
  TerminateOutput terminate(TerminateInput input);
89

90
  final class WorkflowStartInput {
91
    private final String workflowId;
92
    private final String workflowType;
93
    private final Header header;
94
    private final Object[] arguments;
95
    private final WorkflowOptions options;
96

97
    /**
98
     * @param workflowId id of the workflow to be started
99
     * @param workflowType workflow type name
100
     * @param header internal Temporal header that is used to pass context between different
101
     *     abstractions and actors
102
     * @param arguments input arguments for the workflow
103
     * @param options workflow options
104
     */
105
    public WorkflowStartInput(
106
        @Nonnull String workflowId,
107
        @Nonnull String workflowType,
108
        @Nonnull Header header,
109
        @Nonnull Object[] arguments,
110
        @Nonnull WorkflowOptions options) {
1✔
111
      this.workflowId = workflowId;
1✔
112
      this.workflowType = workflowType;
1✔
113
      this.header = header;
1✔
114
      this.arguments = arguments;
1✔
115
      this.options = options;
1✔
116
    }
1✔
117

118
    public String getWorkflowId() {
119
      return workflowId;
1✔
120
    }
121

122
    public String getWorkflowType() {
123
      return workflowType;
1✔
124
    }
125

126
    public Header getHeader() {
127
      return header;
1✔
128
    }
129

130
    public Object[] getArguments() {
131
      return arguments;
1✔
132
    }
133

134
    public WorkflowOptions getOptions() {
135
      return options;
1✔
136
    }
137
  }
138

139
  final class WorkflowStartOutput {
140
    private final @Nonnull WorkflowExecution workflowExecution;
141

142
    public WorkflowStartOutput(@Nonnull WorkflowExecution workflowExecution) {
1✔
143
      this.workflowExecution = workflowExecution;
1✔
144
    }
1✔
145

146
    @Nonnull
147
    public WorkflowExecution getWorkflowExecution() {
148
      return workflowExecution;
1✔
149
    }
150
  }
151

152
  final class WorkflowSignalInput {
153
    private final WorkflowExecution workflowExecution;
154
    private final String signalName;
155
    private final Header header;
156
    private final Object[] arguments;
157

158
    public WorkflowSignalInput(
159
        WorkflowExecution workflowExecution,
160
        String signalName,
161
        Header header,
162
        Object[] signalArguments) {
1✔
163
      this.workflowExecution = workflowExecution;
1✔
164
      this.signalName = signalName;
1✔
165
      this.header = header;
1✔
166
      this.arguments = signalArguments;
1✔
167
    }
1✔
168

169
    public WorkflowExecution getWorkflowExecution() {
170
      return workflowExecution;
1✔
171
    }
172

173
    public String getSignalName() {
174
      return signalName;
1✔
175
    }
176

177
    public Header getHeader() {
178
      return header;
1✔
179
    }
180

181
    public Object[] getArguments() {
182
      return arguments;
1✔
183
    }
184
  }
185

186
  final class WorkflowSignalOutput {}
1✔
187

188
  final class WorkflowSignalWithStartInput {
189
    private final WorkflowStartInput workflowStartInput;
190
    private final String signalName;
191
    private final Object[] signalArguments;
192

193
    public WorkflowSignalWithStartInput(
194
        WorkflowStartInput workflowStartInput, String signalName, Object[] signalArguments) {
1✔
195
      this.workflowStartInput = workflowStartInput;
1✔
196
      this.signalName = signalName;
1✔
197
      this.signalArguments = signalArguments;
1✔
198
    }
1✔
199

200
    public WorkflowStartInput getWorkflowStartInput() {
201
      return workflowStartInput;
1✔
202
    }
203

204
    public String getSignalName() {
205
      return signalName;
1✔
206
    }
207

208
    public Object[] getSignalArguments() {
209
      return signalArguments;
1✔
210
    }
211
  }
212

213
  final class WorkflowSignalWithStartOutput {
214
    private final WorkflowStartOutput workflowStartOutput;
215

216
    public WorkflowSignalWithStartOutput(WorkflowStartOutput workflowStartOutput) {
1✔
217
      this.workflowStartOutput = workflowStartOutput;
1✔
218
    }
1✔
219

220
    public WorkflowStartOutput getWorkflowStartOutput() {
221
      return workflowStartOutput;
1✔
222
    }
223
  }
224

225
  final class GetResultInput<R> {
226
    private final WorkflowExecution workflowExecution;
227
    private final Optional<String> workflowType;
228
    private final long timeout;
229
    private final TimeUnit timeoutUnit;
230
    private final Class<R> resultClass;
231
    private final Type resultType;
232

233
    public GetResultInput(
234
        WorkflowExecution workflowExecution,
235
        Optional<String> workflowType,
236
        long timeout,
237
        TimeUnit timeoutUnit,
238
        Class<R> resultClass,
239
        Type resultType) {
1✔
240
      this.workflowExecution = workflowExecution;
1✔
241
      this.workflowType = workflowType;
1✔
242
      this.timeout = timeout;
1✔
243
      this.timeoutUnit = timeoutUnit;
1✔
244
      this.resultClass = resultClass;
1✔
245
      this.resultType = resultType;
1✔
246
    }
1✔
247

248
    public WorkflowExecution getWorkflowExecution() {
249
      return workflowExecution;
1✔
250
    }
251

252
    public Optional<String> getWorkflowType() {
253
      return workflowType;
1✔
254
    }
255

256
    public long getTimeout() {
257
      return timeout;
1✔
258
    }
259

260
    public TimeUnit getTimeoutUnit() {
261
      return timeoutUnit;
1✔
262
    }
263

264
    public Class<R> getResultClass() {
265
      return resultClass;
1✔
266
    }
267

268
    public Type getResultType() {
269
      return resultType;
1✔
270
    }
271
  }
272

273
  final class GetResultOutput<R> {
274
    private final R result;
275

276
    public GetResultOutput(R result) {
1✔
277
      this.result = result;
1✔
278
    }
1✔
279

280
    public R getResult() {
281
      return result;
1✔
282
    }
283
  }
284

285
  final class GetResultAsyncOutput<R> {
286
    private final CompletableFuture<R> result;
287

288
    public GetResultAsyncOutput(CompletableFuture<R> result) {
1✔
289
      this.result = result;
1✔
290
    }
1✔
291

292
    public CompletableFuture<R> getResult() {
293
      return result;
1✔
294
    }
295
  }
296

297
  final class QueryInput<R> {
298
    private final WorkflowExecution workflowExecution;
299
    private final String queryType;
300
    private final Header header;
301
    private final Object[] arguments;
302
    private final Class<R> resultClass;
303
    private final Type resultType;
304

305
    public QueryInput(
306
        WorkflowExecution workflowExecution,
307
        String queryType,
308
        Header header,
309
        Object[] arguments,
310
        Class<R> resultClass,
311
        Type resultType) {
1✔
312
      this.workflowExecution = workflowExecution;
1✔
313
      this.queryType = queryType;
1✔
314
      this.header = header;
1✔
315
      this.arguments = arguments;
1✔
316
      this.resultClass = resultClass;
1✔
317
      this.resultType = resultType;
1✔
318
    }
1✔
319

320
    public WorkflowExecution getWorkflowExecution() {
321
      return workflowExecution;
1✔
322
    }
323

324
    public String getQueryType() {
325
      return queryType;
1✔
326
    }
327

328
    public Header getHeader() {
329
      return header;
1✔
330
    }
331

332
    public Object[] getArguments() {
333
      return arguments;
1✔
334
    }
335

336
    public Class<R> getResultClass() {
337
      return resultClass;
1✔
338
    }
339

340
    public Type getResultType() {
341
      return resultType;
1✔
342
    }
343
  }
344

345
  final class QueryOutput<R> {
346
    private final WorkflowExecutionStatus queryRejectedStatus;
347
    private final R result;
348

349
    /**
350
     * @param queryRejectedStatus should be null if query is not rejected
351
     * @param result converted result value
352
     */
353
    public QueryOutput(WorkflowExecutionStatus queryRejectedStatus, R result) {
1✔
354
      this.queryRejectedStatus = queryRejectedStatus;
1✔
355
      this.result = result;
1✔
356
    }
1✔
357

358
    public boolean isQueryRejected() {
359
      return queryRejectedStatus != null;
1✔
360
    }
361

362
    public WorkflowExecutionStatus getQueryRejectedStatus() {
363
      return queryRejectedStatus;
1✔
364
    }
365

366
    public R getResult() {
367
      return result;
1✔
368
    }
369
  }
370

371
  final class CancelInput {
372
    private final WorkflowExecution workflowExecution;
373

374
    public CancelInput(WorkflowExecution workflowExecution) {
1✔
375
      this.workflowExecution = workflowExecution;
1✔
376
    }
1✔
377

378
    public WorkflowExecution getWorkflowExecution() {
379
      return workflowExecution;
1✔
380
    }
381
  }
382

383
  @Experimental
384
  final class StartUpdateInput<R> {
385
    private final WorkflowExecution workflowExecution;
386
    private final String updateName;
387
    private final Header header;
388
    private final Object[] arguments;
389
    private final Class<R> resultClass;
390
    private final Type resultType;
391
    private final String updateId;
392
    private final String firstExecutionRunId;
393
    private final WaitPolicy waitPolicy;
394

395
    public StartUpdateInput(
396
        WorkflowExecution workflowExecution,
397
        String updateName,
398
        Header header,
399
        String updateId,
400
        Object[] arguments,
401
        Class<R> resultClass,
402
        Type resultType,
403
        String firstExecutionRunId,
404
        WaitPolicy waitPolicy) {
1✔
405
      this.workflowExecution = workflowExecution;
1✔
406
      this.header = header;
1✔
407
      this.updateId = updateId;
1✔
408
      this.updateName = updateName;
1✔
409
      this.arguments = arguments;
1✔
410
      this.resultClass = resultClass;
1✔
411
      this.resultType = resultType;
1✔
412
      this.firstExecutionRunId = firstExecutionRunId;
1✔
413
      this.waitPolicy = waitPolicy;
1✔
414
    }
1✔
415

416
    public WorkflowExecution getWorkflowExecution() {
417
      return workflowExecution;
1✔
418
    }
419

420
    public String getUpdateName() {
421
      return updateName;
1✔
422
    }
423

424
    public Header getHeader() {
425
      return header;
1✔
426
    }
427

428
    public String getUpdateId() {
429
      return updateId;
1✔
430
    }
431

432
    public Object[] getArguments() {
433
      return arguments;
1✔
434
    }
435

436
    public Class<R> getResultClass() {
437
      return resultClass;
1✔
438
    }
439

440
    public Type getResultType() {
441
      return resultType;
1✔
442
    }
443

444
    public String getFirstExecutionRunId() {
445
      return firstExecutionRunId;
1✔
446
    }
447

448
    public WaitPolicy getWaitPolicy() {
449
      return waitPolicy;
1✔
450
    }
451
  }
452

453
  @Experimental
454
  final class UpdateOutput<R> {
455
    private final R result;
456

457
    public UpdateOutput(R result) {
×
458
      this.result = result;
×
459
    }
×
460

461
    public R getResult() {
462
      return result;
×
463
    }
464
  }
465

466
  @Experimental
467
  final class StartUpdateOutput<R> {
468
    private final UpdateRef reference;
469
    private final R result;
470
    private final boolean hasResult;
471

472
    public StartUpdateOutput(UpdateRef reference, boolean hasResult, R result) {
1✔
473
      this.reference = reference;
1✔
474
      this.result = result;
1✔
475
      this.hasResult = hasResult;
1✔
476
    }
1✔
477

478
    public UpdateRef getReference() {
479
      return reference;
1✔
480
    }
481

482
    public boolean hasResult() {
483
      return hasResult;
1✔
484
    }
485

486
    public R getResult() {
487
      return result;
1✔
488
    }
489
  }
490

491
  @Experimental
492
  final class PollWorkflowUpdateInput<R> {
493
    private final WorkflowExecution workflowExecution;
494
    private long timeout;
495
    private TimeUnit timeoutUnit;
496
    private final Class<R> resultClass;
497
    private final Type resultType;
498
    private final String updateName;
499
    private final String updateId;
500

501
    public PollWorkflowUpdateInput(
502
        WorkflowExecution workflowExecution,
503
        String updateName,
504
        String updateId,
505
        Class<R> resultClass,
506
        Type resultType,
507
        long timeout,
508
        TimeUnit timeoutUnit) {
1✔
509
      this.workflowExecution = workflowExecution;
1✔
510
      this.updateName = updateName;
1✔
511
      this.updateId = updateId;
1✔
512
      this.resultClass = resultClass;
1✔
513
      this.resultType = resultType;
1✔
514
      this.timeout = timeout;
1✔
515
      this.timeoutUnit = timeoutUnit;
1✔
516
    }
1✔
517

518
    public WorkflowExecution getWorkflowExecution() {
519
      return workflowExecution;
1✔
520
    }
521

522
    public long getTimeout() {
523
      return timeout;
1✔
524
    }
525

526
    public TimeUnit getTimeoutUnit() {
527
      return timeoutUnit;
1✔
528
    }
529

530
    public Class<R> getResultClass() {
531
      return resultClass;
1✔
532
    }
533

534
    public Type getResultType() {
535
      return resultType;
1✔
536
    }
537

538
    public String getUpdateName() {
539
      return updateName;
×
540
    }
541

542
    public String getUpdateId() {
543
      return updateId;
1✔
544
    }
545
  }
546

547
  @Experimental
548
  final class PollWorkflowUpdateOutput<R> {
549
    private final CompletableFuture<R> result;
550

551
    public PollWorkflowUpdateOutput(CompletableFuture<R> result) {
1✔
552
      this.result = result;
1✔
553
    }
1✔
554

555
    public CompletableFuture<R> getResult() {
556
      return result;
1✔
557
    }
558
  }
559

560
  final class CancelOutput {}
1✔
561

562
  final class TerminateInput {
563
    private final WorkflowExecution workflowExecution;
564
    private final @Nullable String reason;
565
    private final Object[] details;
566

567
    public TerminateInput(
568
        WorkflowExecution workflowExecution, @Nullable String reason, Object[] details) {
1✔
569
      this.workflowExecution = workflowExecution;
1✔
570
      this.reason = reason;
1✔
571
      this.details = details;
1✔
572
    }
1✔
573

574
    public WorkflowExecution getWorkflowExecution() {
575
      return workflowExecution;
1✔
576
    }
577

578
    @Nullable
579
    public String getReason() {
580
      return reason;
1✔
581
    }
582

583
    public Object[] getDetails() {
584
      return details;
1✔
585
    }
586
  }
587

588
  final class TerminateOutput {}
1✔
589
}
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