• 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

79.31
/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.client.WorkflowOptions;
26
import io.temporal.common.Experimental;
27
import java.lang.reflect.Type;
28
import java.util.Optional;
29
import java.util.concurrent.CompletableFuture;
30
import java.util.concurrent.TimeUnit;
31
import java.util.concurrent.TimeoutException;
32
import javax.annotation.Nonnull;
33
import javax.annotation.Nullable;
34

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

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

60
  WorkflowSignalWithStartOutput signalWithStart(WorkflowSignalWithStartInput input);
61

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

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

76
  <R> QueryOutput<R> query(QueryInput<R> input);
77

78
  <R> UpdateOutput<R> update(UpdateInput<R> input);
79

80
  <R> UpdateAsyncOutput<R> updateAsync(UpdateInput<R> input);
81

82
  CancelOutput cancel(CancelInput input);
83

84
  TerminateOutput terminate(TerminateInput input);
85

86
  final class WorkflowStartInput {
87
    private final String workflowId;
88
    private final String workflowType;
89
    private final Header header;
90
    private final Object[] arguments;
91
    private final WorkflowOptions options;
92

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

114
    public String getWorkflowId() {
115
      return workflowId;
1✔
116
    }
117

118
    public String getWorkflowType() {
119
      return workflowType;
1✔
120
    }
121

122
    public Header getHeader() {
123
      return header;
1✔
124
    }
125

126
    public Object[] getArguments() {
127
      return arguments;
1✔
128
    }
129

130
    public WorkflowOptions getOptions() {
131
      return options;
1✔
132
    }
133
  }
134

135
  final class WorkflowStartOutput {
136
    private final @Nonnull WorkflowExecution workflowExecution;
137

138
    public WorkflowStartOutput(@Nonnull WorkflowExecution workflowExecution) {
1✔
139
      this.workflowExecution = workflowExecution;
1✔
140
    }
1✔
141

142
    @Nonnull
143
    public WorkflowExecution getWorkflowExecution() {
144
      return workflowExecution;
1✔
145
    }
146
  }
147

148
  final class WorkflowSignalInput {
149
    private final WorkflowExecution workflowExecution;
150
    private final String signalName;
151
    private final Object[] arguments;
152

153
    public WorkflowSignalInput(
154
        WorkflowExecution workflowExecution, String signalName, Object[] signalArguments) {
1✔
155
      this.workflowExecution = workflowExecution;
1✔
156
      this.signalName = signalName;
1✔
157
      this.arguments = signalArguments;
1✔
158
    }
1✔
159

160
    public WorkflowExecution getWorkflowExecution() {
161
      return workflowExecution;
1✔
162
    }
163

164
    public String getSignalName() {
165
      return signalName;
1✔
166
    }
167

168
    public Object[] getArguments() {
169
      return arguments;
1✔
170
    }
171
  }
172

173
  final class WorkflowSignalOutput {}
1✔
174

175
  final class WorkflowSignalWithStartInput {
176
    private final WorkflowStartInput workflowStartInput;
177
    private final String signalName;
178
    private final Object[] signalArguments;
179

180
    public WorkflowSignalWithStartInput(
181
        WorkflowStartInput workflowStartInput, String signalName, Object[] signalArguments) {
1✔
182
      this.workflowStartInput = workflowStartInput;
1✔
183
      this.signalName = signalName;
1✔
184
      this.signalArguments = signalArguments;
1✔
185
    }
1✔
186

187
    public WorkflowStartInput getWorkflowStartInput() {
188
      return workflowStartInput;
1✔
189
    }
190

191
    public String getSignalName() {
192
      return signalName;
1✔
193
    }
194

195
    public Object[] getSignalArguments() {
196
      return signalArguments;
1✔
197
    }
198
  }
199

200
  final class WorkflowSignalWithStartOutput {
201
    private final WorkflowStartOutput workflowStartOutput;
202

203
    public WorkflowSignalWithStartOutput(WorkflowStartOutput workflowStartOutput) {
1✔
204
      this.workflowStartOutput = workflowStartOutput;
1✔
205
    }
1✔
206

207
    public WorkflowStartOutput getWorkflowStartOutput() {
208
      return workflowStartOutput;
1✔
209
    }
210
  }
211

212
  final class GetResultInput<R> {
213
    private final WorkflowExecution workflowExecution;
214
    private final Optional<String> workflowType;
215
    private final long timeout;
216
    private final TimeUnit timeoutUnit;
217
    private final Class<R> resultClass;
218
    private final Type resultType;
219

220
    public GetResultInput(
221
        WorkflowExecution workflowExecution,
222
        Optional<String> workflowType,
223
        long timeout,
224
        TimeUnit timeoutUnit,
225
        Class<R> resultClass,
226
        Type resultType) {
1✔
227
      this.workflowExecution = workflowExecution;
1✔
228
      this.workflowType = workflowType;
1✔
229
      this.timeout = timeout;
1✔
230
      this.timeoutUnit = timeoutUnit;
1✔
231
      this.resultClass = resultClass;
1✔
232
      this.resultType = resultType;
1✔
233
    }
1✔
234

235
    public WorkflowExecution getWorkflowExecution() {
236
      return workflowExecution;
1✔
237
    }
238

239
    public Optional<String> getWorkflowType() {
240
      return workflowType;
1✔
241
    }
242

243
    public long getTimeout() {
244
      return timeout;
1✔
245
    }
246

247
    public TimeUnit getTimeoutUnit() {
248
      return timeoutUnit;
1✔
249
    }
250

251
    public Class<R> getResultClass() {
252
      return resultClass;
1✔
253
    }
254

255
    public Type getResultType() {
256
      return resultType;
1✔
257
    }
258
  }
259

260
  final class GetResultOutput<R> {
261
    private final R result;
262

263
    public GetResultOutput(R result) {
1✔
264
      this.result = result;
1✔
265
    }
1✔
266

267
    public R getResult() {
268
      return result;
1✔
269
    }
270
  }
271

272
  final class GetResultAsyncOutput<R> {
273
    private final CompletableFuture<R> result;
274

275
    public GetResultAsyncOutput(CompletableFuture<R> result) {
1✔
276
      this.result = result;
1✔
277
    }
1✔
278

279
    public CompletableFuture<R> getResult() {
280
      return result;
1✔
281
    }
282
  }
283

284
  final class QueryInput<R> {
285
    private final WorkflowExecution workflowExecution;
286
    private final String queryType;
287
    private final Object[] arguments;
288
    private final Class<R> resultClass;
289
    private final Type resultType;
290

291
    public QueryInput(
292
        WorkflowExecution workflowExecution,
293
        String queryType,
294
        Object[] arguments,
295
        Class<R> resultClass,
296
        Type resultType) {
1✔
297
      this.workflowExecution = workflowExecution;
1✔
298
      this.queryType = queryType;
1✔
299
      this.arguments = arguments;
1✔
300
      this.resultClass = resultClass;
1✔
301
      this.resultType = resultType;
1✔
302
    }
1✔
303

304
    public WorkflowExecution getWorkflowExecution() {
305
      return workflowExecution;
1✔
306
    }
307

308
    public String getQueryType() {
309
      return queryType;
1✔
310
    }
311

312
    public Object[] getArguments() {
313
      return arguments;
1✔
314
    }
315

316
    public Class<R> getResultClass() {
317
      return resultClass;
1✔
318
    }
319

320
    public Type getResultType() {
321
      return resultType;
1✔
322
    }
323
  }
324

325
  final class QueryOutput<R> {
326
    private final WorkflowExecutionStatus queryRejectedStatus;
327
    private final R result;
328

329
    /**
330
     * @param queryRejectedStatus should be null if query is not rejected
331
     * @param result converted result value
332
     */
333
    public QueryOutput(WorkflowExecutionStatus queryRejectedStatus, R result) {
1✔
334
      this.queryRejectedStatus = queryRejectedStatus;
1✔
335
      this.result = result;
1✔
336
    }
1✔
337

338
    public boolean isQueryRejected() {
339
      return queryRejectedStatus != null;
1✔
340
    }
341

342
    public WorkflowExecutionStatus getQueryRejectedStatus() {
343
      return queryRejectedStatus;
1✔
344
    }
345

346
    public R getResult() {
347
      return result;
1✔
348
    }
349
  }
350

351
  final class CancelInput {
352
    private final WorkflowExecution workflowExecution;
353

354
    public CancelInput(WorkflowExecution workflowExecution) {
1✔
355
      this.workflowExecution = workflowExecution;
1✔
356
    }
1✔
357

358
    public WorkflowExecution getWorkflowExecution() {
359
      return workflowExecution;
1✔
360
    }
361
  }
362

363
  @Experimental
364
  final class UpdateInput<R> {
365
    private final WorkflowExecution workflowExecution;
366
    private final String updateName;
367
    private final Object[] arguments;
368
    private final Class<R> resultClass;
369
    private final Type resultType;
370
    private final String updateId;
371
    private final String firstExecutionRunId;
372

373
    public UpdateInput(
374
        WorkflowExecution workflowExecution,
375
        String updateName,
376
        String updateId,
377
        Object[] arguments,
378
        Class<R> resultClass,
379
        Type resultType,
380
        String firstExecutionRunId) {
×
381
      this.workflowExecution = workflowExecution;
×
382
      this.updateId = updateId;
×
383
      this.updateName = updateName;
×
384
      this.arguments = arguments;
×
385
      this.resultClass = resultClass;
×
386
      this.resultType = resultType;
×
387
      this.firstExecutionRunId = firstExecutionRunId;
×
388
    }
×
389

390
    public WorkflowExecution getWorkflowExecution() {
391
      return workflowExecution;
×
392
    }
393

394
    public String getUpdateName() {
395
      return updateName;
×
396
    }
397

398
    public String getUpdateId() {
399
      return updateId;
×
400
    }
401

402
    public Object[] getArguments() {
403
      return arguments;
×
404
    }
405

406
    public Class<R> getResultClass() {
407
      return resultClass;
×
408
    }
409

410
    public Type getResultType() {
411
      return resultType;
×
412
    }
413

414
    public String getFirstExecutionRunId() {
415
      return this.firstExecutionRunId;
×
416
    }
417
  }
418

419
  @Experimental
420
  final class UpdateOutput<R> {
421
    private final R result;
422

423
    public UpdateOutput(R result) {
×
424
      this.result = result;
×
425
    }
×
426

427
    public R getResult() {
428
      return result;
×
429
    }
430
  }
431

432
  @Experimental
433
  final class UpdateAsyncOutput<R> {
434
    private final CompletableFuture<R> result;
435

436
    public UpdateAsyncOutput(CompletableFuture<R> result) {
×
437
      this.result = result;
×
438
    }
×
439

440
    public CompletableFuture<R> getResult() {
441
      return result;
×
442
    }
443
  }
444

445
  final class CancelOutput {}
1✔
446

447
  final class TerminateInput {
448
    private final WorkflowExecution workflowExecution;
449
    private final @Nullable String reason;
450
    private final Object[] details;
451

452
    public TerminateInput(
453
        WorkflowExecution workflowExecution, @Nullable String reason, Object[] details) {
1✔
454
      this.workflowExecution = workflowExecution;
1✔
455
      this.reason = reason;
1✔
456
      this.details = details;
1✔
457
    }
1✔
458

459
    public WorkflowExecution getWorkflowExecution() {
460
      return workflowExecution;
1✔
461
    }
462

463
    @Nullable
464
    public String getReason() {
465
      return reason;
1✔
466
    }
467

468
    public Object[] getDetails() {
469
      return details;
1✔
470
    }
471
  }
472

473
  final class TerminateOutput {}
1✔
474
}
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