• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #157

pending completion
#157

push

github-actions

web-flow
Provide SerializationContext for PayloadConverter and PayloadCodec (#1695)

Issue #1694

497 of 497 new or added lines in 32 files covered. (100.0%)

16942 of 20806 relevant lines covered (81.43%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.59
/temporal-sdk/src/main/java/io/temporal/internal/sync/QueryDispatcher.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.internal.sync;
22

23
import io.temporal.api.common.v1.Payloads;
24
import io.temporal.common.converter.DataConverter;
25
import io.temporal.common.converter.EncodedValues;
26
import io.temporal.common.interceptors.WorkflowInboundCallsInterceptor;
27
import io.temporal.common.interceptors.WorkflowOutboundCallsInterceptor;
28
import io.temporal.workflow.DynamicQueryHandler;
29
import java.util.HashMap;
30
import java.util.Map;
31
import java.util.Optional;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

35
class QueryDispatcher {
36
  private static final Logger log = LoggerFactory.getLogger(QueryDispatcher.class);
1✔
37

38
  private final DataConverter dataConverterWithWorkflowContext;
39
  private final Map<String, WorkflowOutboundCallsInterceptor.RegisterQueryInput> queryCallbacks =
1✔
40
      new HashMap<>();
41

42
  private DynamicQueryHandler dynamicQueryHandler;
43
  private WorkflowInboundCallsInterceptor inboundCallsInterceptor;
44

45
  public QueryDispatcher(DataConverter dataConverterWithWorkflowContext) {
1✔
46
    this.dataConverterWithWorkflowContext = dataConverterWithWorkflowContext;
1✔
47
  }
1✔
48

49
  public void setInboundCallsInterceptor(WorkflowInboundCallsInterceptor inboundCallsInterceptor) {
50
    this.inboundCallsInterceptor = inboundCallsInterceptor;
1✔
51
  }
1✔
52

53
  /** Called from the interceptor tail */
54
  public WorkflowInboundCallsInterceptor.QueryOutput handleInterceptedQuery(
55
      WorkflowInboundCallsInterceptor.QueryInput input) {
56
    String queryName = input.getQueryName();
1✔
57
    Object[] args = input.getArguments();
1✔
58
    WorkflowOutboundCallsInterceptor.RegisterQueryInput handler = queryCallbacks.get(queryName);
1✔
59
    Object result;
60
    if (handler == null) {
1✔
61
      if (dynamicQueryHandler != null) {
1✔
62
        result = dynamicQueryHandler.handle(queryName, (EncodedValues) args[0]);
1✔
63
      } else {
64
        throw new IllegalStateException("Unknown query type: " + queryName);
×
65
      }
66
    } else {
67
      result = handler.getCallback().apply(args);
1✔
68
    }
69
    return new WorkflowInboundCallsInterceptor.QueryOutput(result);
1✔
70
  }
71

72
  public Optional<Payloads> handleQuery(String queryName, Optional<Payloads> input) {
73
    WorkflowOutboundCallsInterceptor.RegisterQueryInput handler = queryCallbacks.get(queryName);
1✔
74
    Object[] args;
75
    if (handler == null) {
1✔
76
      if (dynamicQueryHandler == null) {
1✔
77
        throw new IllegalArgumentException(
1✔
78
            "Unknown query type: " + queryName + ", knownTypes=" + queryCallbacks.keySet());
1✔
79
      }
80
      args = new Object[] {new EncodedValues(input, dataConverterWithWorkflowContext)};
1✔
81
    } else {
82
      args =
1✔
83
          DataConverter.arrayFromPayloads(
1✔
84
              dataConverterWithWorkflowContext,
85
              input,
86
              handler.getArgTypes(),
1✔
87
              handler.getGenericArgTypes());
1✔
88
    }
89
    Object result =
1✔
90
        inboundCallsInterceptor
91
            .handleQuery(new WorkflowInboundCallsInterceptor.QueryInput(queryName, args))
1✔
92
            .getResult();
1✔
93
    return dataConverterWithWorkflowContext.toPayloads(result);
1✔
94
  }
95

96
  public void registerQueryHandlers(WorkflowOutboundCallsInterceptor.RegisterQueryInput request) {
97
    String queryType = request.getQueryType();
1✔
98
    if (queryCallbacks.containsKey(queryType)) {
1✔
99
      throw new IllegalStateException("Query \"" + queryType + "\" is already registered");
×
100
    }
101
    queryCallbacks.put(queryType, request);
1✔
102
  }
1✔
103

104
  public void registerDynamicQueryHandler(
105
      WorkflowOutboundCallsInterceptor.RegisterDynamicQueryHandlerInput input) {
106
    dynamicQueryHandler = input.getHandler();
1✔
107
  }
1✔
108
}
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

© 2026 Coveralls, Inc