• 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

96.0
/temporal-sdk/src/main/java/io/temporal/internal/statemachines/EntityStateMachineBase.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.statemachines;
22

23
import io.temporal.api.enums.v1.CommandType;
24
import io.temporal.api.history.v1.HistoryEvent;
25
import io.temporal.api.protocol.v1.Message;
26
import io.temporal.internal.common.ProtocolType;
27
import io.temporal.internal.common.ProtocolUtils;
28
import io.temporal.workflow.Functions;
29
import javax.annotation.Nullable;
30

31
class EntityStateMachineBase<State, ExplicitEvent, Data> implements EntityStateMachine {
32
  protected final StateMachine<State, ExplicitEvent, Data> stateMachine;
33
  protected final Functions.Proc1<CancellableCommand> commandSink;
34

35
  protected HistoryEvent currentEvent;
36
  protected boolean hasNextEvent;
37

38
  protected Message currentMessage;
39

40
  /**
41
   * @param entityName name or id of the entity this state machine represents. For debug purposes
42
   *     only. Can be null.
43
   */
44
  public EntityStateMachineBase(
45
      StateMachineDefinition<State, ExplicitEvent, Data> stateMachineDefinition,
46
      Functions.Proc1<CancellableCommand> commandSink,
47
      Functions.Proc1<StateMachine> stateMachineSink,
48
      @Nullable String entityName) {
1✔
49
    this.stateMachine = StateMachine.newInstance(stateMachineDefinition, entityName);
1✔
50
    this.commandSink = commandSink;
1✔
51
    stateMachineSink.apply(this.stateMachine);
1✔
52
  }
1✔
53

54
  /**
55
   * Notifies that command is included into the workflow task completion result.
56
   *
57
   * <p>Is not called for commands generated during replay.
58
   */
59
  @Override
60
  public void handleCommand(CommandType commandType) {
61
    stateMachine.handleCommand(commandType, (Data) this);
1✔
62
  }
1✔
63

64
  @Override
65
  public void handleMessage(Message message) {
66
    this.currentMessage = message;
1✔
67
    try {
68
      stateMachine.handleMessage(
1✔
69
          ProtocolType.get(ProtocolUtils.getProtocol(message)).get(), (Data) this);
1✔
70
    } finally {
71
      this.currentMessage = null;
1✔
72
    }
73
  }
1✔
74

75
  @Override
76
  public WorkflowStateMachines.HandleEventStatus handleEvent(
77
      HistoryEvent event, boolean hasNextEvent) {
78
    if (!stateMachine.getValidEventTypes().contains(event.getEventType())) {
1✔
79
      return WorkflowStateMachines.HandleEventStatus.NON_MATCHING_EVENT;
1✔
80
    }
81
    this.currentEvent = event;
1✔
82
    this.hasNextEvent = hasNextEvent;
1✔
83
    try {
84
      stateMachine.handleHistoryEvent(event.getEventType(), (Data) this);
1✔
85
    } finally {
86
      this.currentEvent = null;
1✔
87
    }
88
    return WorkflowStateMachines.HandleEventStatus.OK;
1✔
89
  }
90

91
  @Override
92
  public void handleWorkflowTaskStarted() {}
1✔
93

94
  protected final void explicitEvent(ExplicitEvent explicitEvent) {
95
    stateMachine.handleExplicitEvent(explicitEvent, (Data) this);
1✔
96
  }
1✔
97

98
  @Override
99
  public boolean isFinalState() {
100
    return stateMachine.isFinalState();
1✔
101
  }
102

103
  protected State getState() {
104
    return stateMachine.getState();
1✔
105
  }
106

107
  @Override
108
  public String toString() {
109
    return this.getClass().getSimpleName()
×
110
        + "{"
111
        + "stateMachine="
112
        + stateMachine
113
        + ", hasNextEvent="
114
        + hasNextEvent
115
        + ", currentEvent="
116
        + currentEvent
117
        + '}';
118
  }
119
}
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