|
| 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 com.google.common.base.Preconditions; |
| 24 | +import io.temporal.common.Experimental; |
| 25 | +import java.util.Objects; |
| 26 | + |
| 27 | +/** |
| 28 | + * OnConflictOptions specifies the actions to be taken when using the {@link |
| 29 | + * io.temporal.api.enums.v1.WorkflowIdConflictPolicy#WORKFLOW_ID_CONFLICT_POLICY_USE_EXISTING} |
| 30 | + */ |
| 31 | +@Experimental |
| 32 | +public class OnConflictOptions { |
| 33 | + public static OnConflictOptions.Builder newBuilder() { |
| 34 | + return new OnConflictOptions.Builder(); |
| 35 | + } |
| 36 | + |
| 37 | + public static OnConflictOptions.Builder newBuilder(OnConflictOptions options) { |
| 38 | + return new OnConflictOptions.Builder(options); |
| 39 | + } |
| 40 | + |
| 41 | + public static OnConflictOptions getDefaultInstance() { |
| 42 | + return DEFAULT_INSTANCE; |
| 43 | + } |
| 44 | + |
| 45 | + private static final OnConflictOptions DEFAULT_INSTANCE; |
| 46 | + |
| 47 | + static { |
| 48 | + DEFAULT_INSTANCE = OnConflictOptions.newBuilder().build(); |
| 49 | + } |
| 50 | + |
| 51 | + private final boolean attachRequestId; |
| 52 | + private final boolean attachCompletionCallbacks; |
| 53 | + private final boolean attachLinks; |
| 54 | + |
| 55 | + private OnConflictOptions( |
| 56 | + boolean attachRequestId, boolean attachCompletionCallbacks, boolean attachLinks) { |
| 57 | + this.attachRequestId = attachRequestId; |
| 58 | + this.attachCompletionCallbacks = attachCompletionCallbacks; |
| 59 | + this.attachLinks = attachLinks; |
| 60 | + } |
| 61 | + |
| 62 | + public boolean isAttachRequestId() { |
| 63 | + return attachRequestId; |
| 64 | + } |
| 65 | + |
| 66 | + public boolean isAttachCompletionCallbacks() { |
| 67 | + return attachCompletionCallbacks; |
| 68 | + } |
| 69 | + |
| 70 | + public boolean isAttachLinks() { |
| 71 | + return attachLinks; |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public boolean equals(Object o) { |
| 76 | + if (this == o) return true; |
| 77 | + if (o == null || getClass() != o.getClass()) return false; |
| 78 | + OnConflictOptions that = (OnConflictOptions) o; |
| 79 | + return attachRequestId == that.attachRequestId |
| 80 | + && attachCompletionCallbacks == that.attachCompletionCallbacks |
| 81 | + && attachLinks == that.attachLinks; |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public int hashCode() { |
| 86 | + return Objects.hash(attachRequestId, attachCompletionCallbacks, attachLinks); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public String toString() { |
| 91 | + return "OnConflictOptions{" |
| 92 | + + "attachRequestId=" |
| 93 | + + attachRequestId |
| 94 | + + ", attachCompletionCallbacks=" |
| 95 | + + attachCompletionCallbacks |
| 96 | + + ", attachLinks=" |
| 97 | + + attachLinks |
| 98 | + + '}'; |
| 99 | + } |
| 100 | + |
| 101 | + public static final class Builder { |
| 102 | + private boolean attachRequestId; |
| 103 | + private boolean attachCompletionCallbacks; |
| 104 | + private boolean attachLinks; |
| 105 | + |
| 106 | + public Builder(OnConflictOptions options) { |
| 107 | + this.attachRequestId = options.attachRequestId; |
| 108 | + this.attachCompletionCallbacks = options.attachCompletionCallbacks; |
| 109 | + this.attachLinks = options.attachLinks; |
| 110 | + } |
| 111 | + |
| 112 | + public Builder() {} |
| 113 | + |
| 114 | + /** Attaches the request ID to the running workflow. */ |
| 115 | + public Builder setAttachRequestId(boolean attachRequestId) { |
| 116 | + this.attachRequestId = attachRequestId; |
| 117 | + return this; |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * Attaches the completion callbacks to the running workflow. If true, AttachRequestId must be |
| 122 | + * true. |
| 123 | + */ |
| 124 | + public Builder setAttachCompletionCallbacks(boolean attachCompletionCallbacks) { |
| 125 | + this.attachCompletionCallbacks = attachCompletionCallbacks; |
| 126 | + return this; |
| 127 | + } |
| 128 | + |
| 129 | + /** Attaches the links to the WorkflowExecutionOptionsUpdatedEvent history event. */ |
| 130 | + public Builder setAttachLinks(boolean attachLinks) { |
| 131 | + this.attachLinks = attachLinks; |
| 132 | + return this; |
| 133 | + } |
| 134 | + |
| 135 | + public OnConflictOptions build() { |
| 136 | + if (attachCompletionCallbacks) { |
| 137 | + Preconditions.checkState( |
| 138 | + attachRequestId, "AttachRequestId must be true if AttachCompletionCallbacks is true"); |
| 139 | + } |
| 140 | + return new OnConflictOptions(attachRequestId, attachCompletionCallbacks, attachLinks); |
| 141 | + } |
| 142 | + } |
| 143 | +} |
0 commit comments