|
22 | 22 |
|
23 | 23 | import com.google.common.base.Defaults;
|
24 | 24 | import io.nexusrpc.Header;
|
| 25 | +import io.nexusrpc.handler.ServiceImplInstance; |
25 | 26 | import io.temporal.api.common.v1.Callback;
|
26 | 27 | import io.temporal.api.enums.v1.TaskQueueKind;
|
27 | 28 | import io.temporal.api.taskqueue.v1.TaskQueue;
|
28 | 29 | import io.temporal.client.WorkflowOptions;
|
29 | 30 | import io.temporal.client.WorkflowStub;
|
| 31 | +import io.temporal.common.metadata.POJOActivityMethodMetadata; |
| 32 | +import io.temporal.common.metadata.POJOWorkflowMethodMetadata; |
| 33 | +import io.temporal.common.metadata.WorkflowMethodType; |
30 | 34 | import io.temporal.internal.client.NexusStartWorkflowRequest;
|
31 | 35 | import java.util.Arrays;
|
32 | 36 | import java.util.Map;
|
|
37 | 41 |
|
38 | 42 | /** Utility functions shared by the implementation code. */
|
39 | 43 | public final class InternalUtils {
|
| 44 | + public static String TEMPORAL_RESERVED_PREFIX = "__temporal_"; |
| 45 | + |
40 | 46 | private static final Logger log = LoggerFactory.getLogger(InternalUtils.class);
|
| 47 | + private static String QUERY_TYPE_STACK_TRACE = "__stack_trace"; |
| 48 | + private static String ENHANCED_QUERY_TYPE_STACK_TRACE = "__enhanced_stack_trace"; |
41 | 49 |
|
42 | 50 | public static TaskQueue createStickyTaskQueue(
|
43 | 51 | String stickyTaskQueueName, String normalTaskQueueName) {
|
@@ -135,6 +143,57 @@ public static WorkflowStub createNexusBoundStub(
|
135 | 143 | return stub.newInstance(nexusWorkflowOptions.build());
|
136 | 144 | }
|
137 | 145 |
|
| 146 | + /** Check the method name for reserved prefixes or names. */ |
| 147 | + public static void checkMethodName(POJOWorkflowMethodMetadata methodMetadata) { |
| 148 | + if (methodMetadata.getName().startsWith(TEMPORAL_RESERVED_PREFIX)) { |
| 149 | + throw new IllegalArgumentException( |
| 150 | + methodMetadata.getType().toString().toLowerCase() |
| 151 | + + " name \"" |
| 152 | + + methodMetadata.getName() |
| 153 | + + "\" must not start with \"" |
| 154 | + + TEMPORAL_RESERVED_PREFIX |
| 155 | + + "\""); |
| 156 | + } |
| 157 | + if (methodMetadata.getType().equals(WorkflowMethodType.QUERY) |
| 158 | + && (methodMetadata.getName().equals(QUERY_TYPE_STACK_TRACE) |
| 159 | + || methodMetadata.getName().equals(ENHANCED_QUERY_TYPE_STACK_TRACE))) { |
| 160 | + throw new IllegalArgumentException( |
| 161 | + "Query method name \"" + methodMetadata.getName() + "\" is reserved for internal use"); |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + public static void checkMethodName(POJOActivityMethodMetadata methodMetadata) { |
| 166 | + if (methodMetadata.getActivityTypeName().startsWith(TEMPORAL_RESERVED_PREFIX)) { |
| 167 | + throw new IllegalArgumentException( |
| 168 | + "Activity name \"" |
| 169 | + + methodMetadata.getActivityTypeName() |
| 170 | + + "\" must not start with \"" |
| 171 | + + TEMPORAL_RESERVED_PREFIX |
| 172 | + + "\""); |
| 173 | + } |
| 174 | + } |
| 175 | + |
138 | 176 | /** Prohibit instantiation */
|
139 | 177 | private InternalUtils() {}
|
| 178 | + |
| 179 | + public static void checkMethodName(ServiceImplInstance instance) { |
| 180 | + if (instance.getDefinition().getName().startsWith(TEMPORAL_RESERVED_PREFIX)) { |
| 181 | + throw new IllegalArgumentException( |
| 182 | + "Service name \"" |
| 183 | + + instance.getDefinition().getName() |
| 184 | + + "\" must not start with \"" |
| 185 | + + TEMPORAL_RESERVED_PREFIX |
| 186 | + + "\""); |
| 187 | + } |
| 188 | + for (String operationName : instance.getDefinition().getOperations().keySet()) { |
| 189 | + if (operationName.startsWith(TEMPORAL_RESERVED_PREFIX)) { |
| 190 | + throw new IllegalArgumentException( |
| 191 | + "Operation name \"" |
| 192 | + + operationName |
| 193 | + + "\" must not start with \"" |
| 194 | + + TEMPORAL_RESERVED_PREFIX |
| 195 | + + "\""); |
| 196 | + } |
| 197 | + } |
| 198 | + } |
140 | 199 | }
|
0 commit comments