• 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

75.0
/temporal-sdk/src/main/java/io/temporal/client/WorkflowStub.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.client;
22

23
import io.temporal.api.common.v1.WorkflowExecution;
24
import io.temporal.api.enums.v1.QueryRejectCondition;
25
import io.temporal.common.Experimental;
26
import io.temporal.failure.CanceledFailure;
27
import io.temporal.failure.TerminatedFailure;
28
import io.temporal.failure.TimeoutFailure;
29
import io.temporal.internal.sync.StubMarker;
30
import java.lang.reflect.Type;
31
import java.util.Optional;
32
import java.util.concurrent.CompletableFuture;
33
import java.util.concurrent.ExecutionException;
34
import java.util.concurrent.TimeUnit;
35
import java.util.concurrent.TimeoutException;
36
import javax.annotation.Nullable;
37

38
/**
39
 * WorkflowStub is a client side stub to a single workflow instance. It can be used to start,
40
 * signal, query, update, wait for completion and cancel a workflow execution. Created through
41
 * {@link WorkflowClient#newUntypedWorkflowStub(String, WorkflowOptions)} or {@link
42
 * WorkflowClient#newUntypedWorkflowStub(WorkflowExecution, Optional)}.
43
 */
44
public interface WorkflowStub {
45

46
  /**
47
   * Extracts untyped WorkflowStub from a typed workflow stub created through {@link
48
   * WorkflowClient#newWorkflowStub(Class, WorkflowOptions)}.
49
   *
50
   * @param typed typed workflow stub
51
   * @param <T> type of the workflow stub interface
52
   * @return untyped workflow stub for the same workflow instance
53
   */
54
  static <T> WorkflowStub fromTyped(T typed) {
55
    if (!(typed instanceof StubMarker)) {
1✔
56
      throw new IllegalArgumentException(
×
57
          "arguments must be created through WorkflowClient.newWorkflowStub");
58
    }
59
    @SuppressWarnings("unchecked")
60
    StubMarker supplier = (StubMarker) typed;
1✔
61
    return (WorkflowStub) supplier.__getUntypedStub();
1✔
62
  }
63

64
  /**
65
   * Synchronously signals a workflow by invoking its signal handler. Usually a signal handler is a
66
   * method annotated with {@link io.temporal.workflow.SignalMethod}.
67
   *
68
   * @param signalName name of the signal handler. Usually it is a method name.
69
   * @param args signal method arguments
70
   * @throws WorkflowNotFoundException if the workflow execution doesn't exist or completed and
71
   *     can't be signalled
72
   * @throws WorkflowServiceException for all other failures including networking and service
73
   *     availability issues
74
   */
75
  void signal(String signalName, Object... args);
76

77
  /**
78
   * Synchronously update a workflow execution by invoking its update handler. Usually a update
79
   * handler is a method annotated with {@link io.temporal.workflow.UpdateMethod}.
80
   *
81
   * @param updateName name of the update handler. Usually it is a method name.
82
   * @param resultClass class of the update return value
83
   * @param <R> type of the update return value
84
   * @param args update method arguments
85
   * @return update result
86
   * @throws WorkflowNotFoundException if the workflow execution doesn't exist or completed and
87
   *     can't be signalled
88
   * @throws WorkflowServiceException for all other failures including networking and service
89
   *     availability issues
90
   */
91
  @Experimental
92
  <R> R update(String updateName, Class<R> resultClass, Object... args);
93

94
  /**
95
   * Synchronously update a workflow execution by invoking its update handler. Usually a update
96
   * handler is a method annotated with {@link io.temporal.workflow.UpdateMethod}.
97
   *
98
   * @param updateName name of the update handler. Usually it is a method name.
99
   * @param updateId is an application-layer identifier for the requested update. It must be unique
100
   *     within the scope of a workflow execution.
101
   * @param firstExecutionRunId specifies the RunID expected to identify the first run in the
102
   *     workflow execution chain. If this expectation does not match then the server will reject
103
   *     the update request with an error.
104
   * @param resultClass class of the update return value.
105
   * @param <R> type of the update return value.
106
   * @param resultType type of the workflow return value. Differs from resultClass for generic
107
   *     types.
108
   * @param args update method arguments
109
   * @return update result
110
   * @throws WorkflowNotFoundException if the workflow execution doesn't exist or completed and
111
   *     can't be sent an update request
112
   * @throws WorkflowServiceException for all other failures including networking and service
113
   *     availability issues
114
   */
115
  @Experimental
116
  <R> R update(
117
      String updateName,
118
      String updateId,
119
      String firstExecutionRunId,
120
      Class<R> resultClass,
121
      Type resultType,
122
      Object... args);
123

124
  /**
125
   * Asynchronously update a workflow execution by invoking its update handler and returning a
126
   * handle to the update request. Usually a update handler is a method annotated with {@link
127
   * io.temporal.workflow.UpdateMethod}.
128
   *
129
   * @param updateName name of the update handler. Usually it is a method name.
130
   * @param resultClass class of the update return value
131
   * @param <R> type of the update return value
132
   * @param args update method arguments
133
   * @return update reference that can be used to get the result of the update.
134
   */
135
  @Experimental
136
  <R> UpdateHandle<R> startUpdate(String updateName, Class<R> resultClass, Object... args);
137

138
  /**
139
   * Asynchronously update a workflow execution by invoking its update handler and returning a
140
   * handle to the update request.
141
   *
142
   * @param updateName name of the update handler. Usually it is a method name.
143
   * @param updateId is an application-layer identifier for the requested update. It must be unique
144
   *     within the scope of a workflow execution.
145
   * @param firstExecutionRunId specifies the RunID expected to identify the first run in the
146
   *     workflow execution chain. If this expectation does not match then the server will reject
147
   *     the update request with an error.
148
   * @param resultClass class of the update return value.
149
   * @param <R> type of the update return value.
150
   * @param resultType type of the workflow return value. Differs from resultClass for generic
151
   *     types.
152
   * @param args update method arguments
153
   * @return update reference that can be used to get the result of the update.
154
   */
155
  @Experimental
156
  <R> UpdateHandle<R> startUpdate(
157
      String updateName,
158
      String updateId,
159
      String firstExecutionRunId,
160
      Class<R> resultClass,
161
      Type resultType,
162
      Object... args);
163

164
  WorkflowExecution start(Object... args);
165

166
  WorkflowExecution signalWithStart(String signalName, Object[] signalArgs, Object[] startArgs);
167

168
  Optional<String> getWorkflowType();
169

170
  WorkflowExecution getExecution();
171

172
  /**
173
   * Returns workflow result potentially waiting for workflow to complete. Behind the scene this
174
   * call performs long poll on Temporal service waiting for workflow completion notification.
175
   *
176
   * @param resultClass class of the workflow return value
177
   * @param <R> type of the workflow return value
178
   * @return workflow return value
179
   * @throws WorkflowNotFoundException if the workflow execution doesn't exist
180
   * @throws WorkflowException if workflow failed with an exception
181
   * @throws WorkflowFailedException if workflow failed. {@link WorkflowFailedException#getCause()}
182
   *     will be {@link TimeoutFailure}, {@link TerminatedFailure}, {@link CanceledFailure} if the
183
   *     workflow execution timed out, was cancelled or terminated. Or the original {@link
184
   *     io.temporal.failure.TemporalFailure} from the workflow that caused the failure otherwise.
185
   * @throws WorkflowServiceException for all other failures including networking and service
186
   *     availability issues.
187
   */
188
  <R> R getResult(Class<R> resultClass);
189

190
  /**
191
   * Returns workflow result potentially waiting for workflow to complete. Behind the scene this
192
   * call performs long poll on Temporal service waiting for workflow completion notification.
193
   *
194
   * @param resultClass class of the workflow return value
195
   * @param resultType type of the workflow return value. Differs from resultClass for generic
196
   *     types.
197
   * @param <R> type of the workflow return value
198
   * @return workflow return value
199
   * @throws WorkflowNotFoundException if the workflow execution doesn't exist
200
   * @throws WorkflowException if workflow failed with an exception
201
   * @throws WorkflowFailedException if workflow failed. {@link WorkflowFailedException#getCause()}
202
   *     will be {@link TimeoutFailure}, {@link TerminatedFailure}, {@link CanceledFailure} if the
203
   *     workflow execution timed out, was cancelled or terminated. Or the original {@link
204
   *     io.temporal.failure.TemporalFailure} from the workflow that caused the failure otherwise.
205
   * @throws WorkflowServiceException for all other failures including networking and service
206
   *     availability issues
207
   */
208
  <R> R getResult(Class<R> resultClass, Type resultType);
209

210
  /**
211
   * Returns workflow result potentially waiting for workflow to complete. Behind the scene this
212
   * call performs long poll on Temporal service waiting for workflow completion notification.
213
   *
214
   * @param timeout maximum time to wait
215
   * @param unit unit of timeout
216
   * @param resultClass class of the workflow return value
217
   * @param <R> type of the workflow return value
218
   * @return workflow return value
219
   * @throws TimeoutException if workflow is not completed after the timeout time
220
   * @throws WorkflowNotFoundException if the workflow execution doesn't exist
221
   * @throws WorkflowException if workflow failed with an exception
222
   * @throws WorkflowFailedException if workflow failed. {@link WorkflowFailedException#getCause()}
223
   *     will be {@link TimeoutFailure}, {@link TerminatedFailure}, {@link CanceledFailure} if the
224
   *     workflow execution timed out, was cancelled or terminated. Or the original {@link
225
   *     io.temporal.failure.TemporalFailure} from the workflow that caused the failure otherwise.
226
   * @throws WorkflowServiceException for all other failures including networking and service
227
   *     availability issues
228
   */
229
  <R> R getResult(long timeout, TimeUnit unit, Class<R> resultClass) throws TimeoutException;
230

231
  /**
232
   * Returns workflow result potentially waiting for workflow to complete. Behind the scene this
233
   * call is polling Temporal Server waiting for workflow completion.
234
   *
235
   * @param timeout maximum time to wait
236
   * @param unit unit of timeout
237
   * @param resultClass class of the workflow return value
238
   * @param resultType type of the workflow return value. Differs from {@code resultClass} for
239
   *     generic
240
   * @param <R> type of the workflow return value
241
   * @return workflow return value
242
   * @throws TimeoutException if workflow is not completed after the timeout time
243
   * @throws WorkflowNotFoundException if the workflow execution doesn't exist
244
   * @throws WorkflowException if workflow failed with an exception
245
   * @throws WorkflowFailedException if workflow failed. {@link WorkflowFailedException#getCause()}
246
   *     will be {@link TimeoutFailure}, {@link TerminatedFailure}, {@link CanceledFailure} if the
247
   *     workflow execution timed out, was cancelled or terminated. Or the original {@link
248
   *     io.temporal.failure.TemporalFailure} from the workflow that caused the failure otherwise.
249
   * @throws WorkflowServiceException for all other failures including networking and service
250
   *     availability issues
251
   */
252
  <R> R getResult(long timeout, TimeUnit unit, Class<R> resultClass, Type resultType)
253
      throws TimeoutException;
254

255
  /**
256
   * Returns a {@link CompletableFuture} with the workflow result potentially waiting for workflow
257
   * to complete. Behind the scenes this call performs long polls the Temporal Server waiting for
258
   * workflow completion.
259
   *
260
   * @param resultClass class of the workflow return value
261
   * @param <R> type of the workflow return value
262
   * @return future completed with workflow return value or an exception
263
   * @see #getResult(Class) as a sync version of this method for detailed information about
264
   *     exceptions that may be thrown from {@link CompletableFuture#get()} wrapped by {@link
265
   *     ExecutionException}
266
   */
267
  <R> CompletableFuture<R> getResultAsync(Class<R> resultClass);
268

269
  /**
270
   * Returns a {@link CompletableFuture} with the workflow result potentially waiting for workflow
271
   * to complete. Behind the scene this call performs long poll on Temporal service waiting for
272
   * workflow completion notification.
273
   *
274
   * @param resultClass class of the workflow return value
275
   * @param resultType type of the workflow return value. Differs from {@code resultClass} for
276
   *     generic types.
277
   * @param <R> type of the workflow return value
278
   * @return future completed with workflow return value or an exception
279
   * @see #getResult(Class, Type) as a sync version of this method for detailed information about
280
   *     exceptions that may be thrown from {@link CompletableFuture#get()} wrapped by {@link
281
   *     ExecutionException}
282
   */
283
  <R> CompletableFuture<R> getResultAsync(Class<R> resultClass, Type resultType);
284

285
  /**
286
   * Returns a {@link CompletableFuture} with the workflow result potentially waiting for workflow
287
   * to complete. Behind the scene this call performs long poll on Temporal service waiting for
288
   * workflow completion notification.
289
   *
290
   * @param timeout maximum time to wait and perform a background long poll
291
   * @param unit unit of timeout
292
   * @param resultClass class of the workflow return value
293
   * @param <R> type of the workflow return value
294
   * @return future completed with workflow return value or an exception
295
   * @see #getResult(long, TimeUnit, Class) as a sync version of this method for detailed
296
   *     information about exceptions that may be thrown from {@link CompletableFuture#get()}
297
   *     wrapped by {@link ExecutionException}
298
   */
299
  <R> CompletableFuture<R> getResultAsync(long timeout, TimeUnit unit, Class<R> resultClass);
300

301
  /**
302
   * Returns a {@link CompletableFuture} with the workflow result potentially waiting for workflow
303
   * to complete. Behind the scene this call performs long poll on Temporal service waiting for
304
   * workflow completion notification.
305
   *
306
   * @param timeout maximum time to wait and perform a background long poll
307
   * @param unit unit of timeout
308
   * @param resultClass class of the workflow return value
309
   * @param resultType type of the workflow return value. Differs from {@code resultClass} for
310
   *     generic types.
311
   * @param <R> type of the workflow return value
312
   * @return future completed with workflow return value or an exception
313
   * @see #getResult(long, TimeUnit, Class, Type) as a sync version of this method for detailed
314
   *     information about exceptions that may be thrown from {@link CompletableFuture#get()}
315
   *     wrapped by {@link ExecutionException}
316
   */
317
  <R> CompletableFuture<R> getResultAsync(
318
      long timeout, TimeUnit unit, Class<R> resultClass, Type resultType);
319

320
  /**
321
   * Synchronously queries workflow by invoking its query handler. Usually a query handler is a
322
   * method annotated with {@link io.temporal.workflow.QueryMethod}.
323
   *
324
   * @see WorkflowClientOptions.Builder#setQueryRejectCondition(QueryRejectCondition)
325
   * @param queryType name of the query handler. Usually it is a method name.
326
   * @param resultClass class of the query result type
327
   * @param args optional query arguments
328
   * @param <R> type of the query result
329
   * @return query result
330
   * @throws WorkflowNotFoundException if the workflow execution doesn't exist
331
   * @throws WorkflowQueryException if the query failed during it's execution by the workflow worker
332
   * @throws WorkflowQueryRejectedException if query is rejected by the server
333
   * @throws WorkflowServiceException for all other failures including networking and service
334
   *     availability issues
335
   */
336
  <R> R query(String queryType, Class<R> resultClass, Object... args);
337

338
  /**
339
   * Synchronously queries workflow by invoking its query handler. Usually a query handler is a
340
   * method annotated with {@link io.temporal.workflow.QueryMethod}.
341
   *
342
   * @see WorkflowClientOptions.Builder#setQueryRejectCondition(QueryRejectCondition)
343
   * @param queryType name of the query handler. Usually it is a method name.
344
   * @param resultClass class of the query result type
345
   * @param resultType type of the workflow return value. Differs from {@code resultClass} for
346
   *     generic types.
347
   * @param args optional query arguments
348
   * @param <R> type of the query result
349
   * @return query result
350
   * @throws WorkflowNotFoundException if the workflow execution doesn't exist
351
   * @throws WorkflowQueryException if the query failed during it's execution by the workflow worker
352
   *     or was rejected on any stage
353
   * @throws WorkflowServiceException for all other failures including networking and service
354
   *     availability issues
355
   */
356
  <R> R query(String queryType, Class<R> resultClass, Type resultType, Object... args);
357

358
  /**
359
   * Request cancellation of a workflow execution.
360
   *
361
   * <p>Cancellation cancels {@link io.temporal.workflow.CancellationScope} that wraps the main
362
   * workflow method. Note that workflow can take long time to get canceled or even completely
363
   * ignore the cancellation request.
364
   *
365
   * @throws WorkflowNotFoundException if the workflow execution doesn't exist or is already
366
   *     completed
367
   * @throws WorkflowServiceException for all other failures including networking and service
368
   *     availability issues
369
   */
370
  void cancel();
371

372
  /**
373
   * Terminates a workflow execution.
374
   *
375
   * <p>Termination is a hard stop of a workflow execution which doesn't give workflow code any
376
   * chance to perform cleanup.
377
   *
378
   * @param reason optional reason for the termination request
379
   * @param details additional details about the termination reason
380
   * @throws WorkflowNotFoundException if the workflow execution doesn't exist or is already
381
   *     completed
382
   * @throws WorkflowServiceException for all other failures including networking and service
383
   *     availability issues
384
   */
385
  void terminate(@Nullable String reason, Object... details);
386

387
  Optional<WorkflowOptions> getOptions();
388
}
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