|
| 1 | +/* |
| 2 | + * Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved. |
| 3 | + * |
| 4 | + * Copyright 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"). You may not |
| 9 | + * use this file except in compliance with the License. A copy of the License is |
| 10 | + * located at |
| 11 | + * |
| 12 | + * http://aws.amazon.com/apache2.0 |
| 13 | + * |
| 14 | + * or in the "license" file accompanying this file. This file is distributed on |
| 15 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 16 | + * express or implied. See the License for the specific language governing |
| 17 | + * permissions and limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package io.temporal.common.interceptors; |
| 21 | + |
| 22 | +import io.temporal.api.common.v1.WorkflowExecution; |
| 23 | +import io.temporal.api.enums.v1.WorkflowExecutionStatus; |
| 24 | +import io.temporal.client.WorkflowOptions; |
| 25 | +import io.temporal.common.Experimental; |
| 26 | +import java.lang.reflect.Type; |
| 27 | +import java.util.Optional; |
| 28 | +import java.util.concurrent.CompletableFuture; |
| 29 | +import java.util.concurrent.TimeUnit; |
| 30 | +import java.util.concurrent.TimeoutException; |
| 31 | + |
| 32 | +@Experimental |
| 33 | +public interface WorkflowClientCallsInterceptor { |
| 34 | + /** |
| 35 | + * @see #signalWithStart if you implement this method, {@link #signalWithStart} most likely needs |
| 36 | + * to be implemented too |
| 37 | + */ |
| 38 | + WorkflowStartOutput start(WorkflowStartInput input); |
| 39 | + |
| 40 | + /** |
| 41 | + * @see #signalWithStart if you implement this method, {@link #signalWithStart} most likely needs |
| 42 | + * to be implemented too |
| 43 | + */ |
| 44 | + WorkflowSignalOutput signal(WorkflowSignalInput input); |
| 45 | + |
| 46 | + WorkflowSignalWithStartOutput signalWithStart(WorkflowSignalWithStartInput input); |
| 47 | + |
| 48 | + /** |
| 49 | + * @see #getResultAsync if you implement this method, {@link #getResultAsync} most likely needs to |
| 50 | + * be implemented too |
| 51 | + */ |
| 52 | + <R> GetResultOutput<R> getResult(GetResultInput<R> input) throws TimeoutException; |
| 53 | + |
| 54 | + /** |
| 55 | + * @see #getResult if you implement this method, {@link #getResult} most likely needs to be |
| 56 | + * implemented too |
| 57 | + */ |
| 58 | + <R> GetResultAsyncOutput<R> getResultAsync(GetResultInput<R> input); |
| 59 | + |
| 60 | + <R> QueryOutput<R> query(QueryInput<R> input); |
| 61 | + |
| 62 | + CancelOutput cancel(CancelInput input); |
| 63 | + |
| 64 | + TerminateOutput terminate(TerminateInput input); |
| 65 | + |
| 66 | + final class WorkflowStartInput { |
| 67 | + private final String workflowId; |
| 68 | + private final String workflowType; |
| 69 | + private final Header header; |
| 70 | + private final Object[] arguments; |
| 71 | + private final WorkflowOptions options; |
| 72 | + |
| 73 | + public WorkflowStartInput( |
| 74 | + String workflowId, |
| 75 | + String workflowType, |
| 76 | + Header header, |
| 77 | + Object[] arguments, |
| 78 | + WorkflowOptions options) { |
| 79 | + this.workflowId = workflowId; |
| 80 | + this.workflowType = workflowType; |
| 81 | + this.header = header; |
| 82 | + this.arguments = arguments; |
| 83 | + this.options = options; |
| 84 | + } |
| 85 | + |
| 86 | + public String getWorkflowId() { |
| 87 | + return workflowId; |
| 88 | + } |
| 89 | + |
| 90 | + public String getWorkflowType() { |
| 91 | + return workflowType; |
| 92 | + } |
| 93 | + |
| 94 | + public Header getHeader() { |
| 95 | + return header; |
| 96 | + } |
| 97 | + |
| 98 | + public Object[] getArguments() { |
| 99 | + return arguments; |
| 100 | + } |
| 101 | + |
| 102 | + public WorkflowOptions getOptions() { |
| 103 | + return options; |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + final class WorkflowStartOutput { |
| 108 | + private final WorkflowExecution workflowExecution; |
| 109 | + |
| 110 | + public WorkflowStartOutput(WorkflowExecution workflowExecution) { |
| 111 | + this.workflowExecution = workflowExecution; |
| 112 | + } |
| 113 | + |
| 114 | + public WorkflowExecution getWorkflowExecution() { |
| 115 | + return workflowExecution; |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + final class WorkflowSignalInput { |
| 120 | + private final WorkflowExecution workflowExecution; |
| 121 | + private final String signalName; |
| 122 | + private final Object[] arguments; |
| 123 | + |
| 124 | + public WorkflowSignalInput( |
| 125 | + WorkflowExecution workflowExecution, String signalName, Object[] signalArguments) { |
| 126 | + this.workflowExecution = workflowExecution; |
| 127 | + this.signalName = signalName; |
| 128 | + this.arguments = signalArguments; |
| 129 | + } |
| 130 | + |
| 131 | + public WorkflowExecution getWorkflowExecution() { |
| 132 | + return workflowExecution; |
| 133 | + } |
| 134 | + |
| 135 | + public String getSignalName() { |
| 136 | + return signalName; |
| 137 | + } |
| 138 | + |
| 139 | + public Object[] getArguments() { |
| 140 | + return arguments; |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + final class WorkflowSignalOutput {} |
| 145 | + |
| 146 | + final class WorkflowSignalWithStartInput { |
| 147 | + private final WorkflowStartInput workflowStartInput; |
| 148 | + private final String signalName; |
| 149 | + private final Object[] signalArguments; |
| 150 | + |
| 151 | + public WorkflowSignalWithStartInput( |
| 152 | + WorkflowStartInput workflowStartInput, String signalName, Object[] signalArguments) { |
| 153 | + this.workflowStartInput = workflowStartInput; |
| 154 | + this.signalName = signalName; |
| 155 | + this.signalArguments = signalArguments; |
| 156 | + } |
| 157 | + |
| 158 | + public WorkflowStartInput getWorkflowStartInput() { |
| 159 | + return workflowStartInput; |
| 160 | + } |
| 161 | + |
| 162 | + public String getSignalName() { |
| 163 | + return signalName; |
| 164 | + } |
| 165 | + |
| 166 | + public Object[] getSignalArguments() { |
| 167 | + return signalArguments; |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + final class WorkflowSignalWithStartOutput { |
| 172 | + private final WorkflowStartOutput workflowStartOutput; |
| 173 | + |
| 174 | + public WorkflowSignalWithStartOutput(WorkflowStartOutput workflowStartOutput) { |
| 175 | + this.workflowStartOutput = workflowStartOutput; |
| 176 | + } |
| 177 | + |
| 178 | + public WorkflowStartOutput getWorkflowStartOutput() { |
| 179 | + return workflowStartOutput; |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | + final class GetResultInput<R> { |
| 184 | + private final WorkflowExecution workflowExecution; |
| 185 | + private final Optional<String> workflowType; |
| 186 | + private final long timeout; |
| 187 | + private final TimeUnit timeoutUnit; |
| 188 | + private final Class<R> resultClass; |
| 189 | + private final Type resultType; |
| 190 | + |
| 191 | + public GetResultInput( |
| 192 | + WorkflowExecution workflowExecution, |
| 193 | + Optional<String> workflowType, |
| 194 | + long timeout, |
| 195 | + TimeUnit timeoutUnit, |
| 196 | + Class<R> resultClass, |
| 197 | + Type resultType) { |
| 198 | + this.workflowExecution = workflowExecution; |
| 199 | + this.workflowType = workflowType; |
| 200 | + this.timeout = timeout; |
| 201 | + this.timeoutUnit = timeoutUnit; |
| 202 | + this.resultClass = resultClass; |
| 203 | + this.resultType = resultType; |
| 204 | + } |
| 205 | + |
| 206 | + public WorkflowExecution getWorkflowExecution() { |
| 207 | + return workflowExecution; |
| 208 | + } |
| 209 | + |
| 210 | + public Optional<String> getWorkflowType() { |
| 211 | + return workflowType; |
| 212 | + } |
| 213 | + |
| 214 | + public long getTimeout() { |
| 215 | + return timeout; |
| 216 | + } |
| 217 | + |
| 218 | + public TimeUnit getTimeoutUnit() { |
| 219 | + return timeoutUnit; |
| 220 | + } |
| 221 | + |
| 222 | + public Class<R> getResultClass() { |
| 223 | + return resultClass; |
| 224 | + } |
| 225 | + |
| 226 | + public Type getResultType() { |
| 227 | + return resultType; |
| 228 | + } |
| 229 | + } |
| 230 | + |
| 231 | + final class GetResultOutput<R> { |
| 232 | + private final R result; |
| 233 | + |
| 234 | + public GetResultOutput(R result) { |
| 235 | + this.result = result; |
| 236 | + } |
| 237 | + |
| 238 | + public R getResult() { |
| 239 | + return result; |
| 240 | + } |
| 241 | + } |
| 242 | + |
| 243 | + final class GetResultAsyncOutput<R> { |
| 244 | + private final CompletableFuture<R> result; |
| 245 | + |
| 246 | + public GetResultAsyncOutput(CompletableFuture<R> result) { |
| 247 | + this.result = result; |
| 248 | + } |
| 249 | + |
| 250 | + public CompletableFuture<R> getResult() { |
| 251 | + return result; |
| 252 | + } |
| 253 | + } |
| 254 | + |
| 255 | + final class QueryInput<R> { |
| 256 | + private final WorkflowExecution workflowExecution; |
| 257 | + private final String queryType; |
| 258 | + private final Object[] arguments; |
| 259 | + private final Class<R> resultClass; |
| 260 | + private final Type resultType; |
| 261 | + |
| 262 | + public QueryInput( |
| 263 | + WorkflowExecution workflowExecution, |
| 264 | + String queryType, |
| 265 | + Object[] arguments, |
| 266 | + Class<R> resultClass, |
| 267 | + Type resultType) { |
| 268 | + this.workflowExecution = workflowExecution; |
| 269 | + this.queryType = queryType; |
| 270 | + this.arguments = arguments; |
| 271 | + this.resultClass = resultClass; |
| 272 | + this.resultType = resultType; |
| 273 | + } |
| 274 | + |
| 275 | + public WorkflowExecution getWorkflowExecution() { |
| 276 | + return workflowExecution; |
| 277 | + } |
| 278 | + |
| 279 | + public String getQueryType() { |
| 280 | + return queryType; |
| 281 | + } |
| 282 | + |
| 283 | + public Object[] getArguments() { |
| 284 | + return arguments; |
| 285 | + } |
| 286 | + |
| 287 | + public Class<R> getResultClass() { |
| 288 | + return resultClass; |
| 289 | + } |
| 290 | + |
| 291 | + public Type getResultType() { |
| 292 | + return resultType; |
| 293 | + } |
| 294 | + } |
| 295 | + |
| 296 | + final class QueryOutput<R> { |
| 297 | + private final WorkflowExecutionStatus queryRejectedStatus; |
| 298 | + private final R result; |
| 299 | + |
| 300 | + /** |
| 301 | + * @param queryRejectedStatus should be null if query is not rejected |
| 302 | + * @param result converted result value |
| 303 | + */ |
| 304 | + public QueryOutput(WorkflowExecutionStatus queryRejectedStatus, R result) { |
| 305 | + this.queryRejectedStatus = queryRejectedStatus; |
| 306 | + this.result = result; |
| 307 | + } |
| 308 | + |
| 309 | + public boolean isQueryRejected() { |
| 310 | + return queryRejectedStatus != null; |
| 311 | + } |
| 312 | + |
| 313 | + public WorkflowExecutionStatus getQueryRejectedStatus() { |
| 314 | + return queryRejectedStatus; |
| 315 | + } |
| 316 | + |
| 317 | + public R getResult() { |
| 318 | + return result; |
| 319 | + } |
| 320 | + } |
| 321 | + |
| 322 | + final class CancelInput { |
| 323 | + private final WorkflowExecution workflowExecution; |
| 324 | + |
| 325 | + public CancelInput(WorkflowExecution workflowExecution) { |
| 326 | + this.workflowExecution = workflowExecution; |
| 327 | + } |
| 328 | + |
| 329 | + public WorkflowExecution getWorkflowExecution() { |
| 330 | + return workflowExecution; |
| 331 | + } |
| 332 | + } |
| 333 | + |
| 334 | + final class CancelOutput {} |
| 335 | + |
| 336 | + final class TerminateInput { |
| 337 | + private final WorkflowExecution workflowExecution; |
| 338 | + private final String reason; |
| 339 | + private final Object[] details; |
| 340 | + |
| 341 | + public TerminateInput(WorkflowExecution workflowExecution, String reason, Object[] details) { |
| 342 | + this.workflowExecution = workflowExecution; |
| 343 | + this.reason = reason; |
| 344 | + this.details = details; |
| 345 | + } |
| 346 | + |
| 347 | + public WorkflowExecution getWorkflowExecution() { |
| 348 | + return workflowExecution; |
| 349 | + } |
| 350 | + |
| 351 | + public String getReason() { |
| 352 | + return reason; |
| 353 | + } |
| 354 | + |
| 355 | + public Object[] getDetails() { |
| 356 | + return details; |
| 357 | + } |
| 358 | + } |
| 359 | + |
| 360 | + final class TerminateOutput {} |
| 361 | +} |
0 commit comments