You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sub_state_machine.go 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package state
  18. import (
  19. "github.com/google/uuid"
  20. "github.com/seata/seata-go/pkg/saga/statemachine/constant"
  21. )
  22. type SubStateMachine interface {
  23. TaskState
  24. StateMachineName() string
  25. CompensateStateImpl() TaskState
  26. }
  27. type SubStateMachineImpl struct {
  28. *ServiceTaskStateImpl
  29. stateMachineName string
  30. compensateState TaskState
  31. }
  32. func NewSubStateMachineImpl() *SubStateMachineImpl {
  33. return &SubStateMachineImpl{
  34. ServiceTaskStateImpl: NewServiceTaskStateImpl(),
  35. }
  36. }
  37. func (s *SubStateMachineImpl) StateMachineName() string {
  38. return s.stateMachineName
  39. }
  40. func (s *SubStateMachineImpl) SetStateMachineName(stateMachineName string) {
  41. s.stateMachineName = stateMachineName
  42. }
  43. func (s *SubStateMachineImpl) CompensateStateImpl() TaskState {
  44. return s.compensateState
  45. }
  46. func (s *SubStateMachineImpl) SetCompensateStateImpl(compensateState TaskState) {
  47. s.compensateState = compensateState
  48. }
  49. type CompensateSubStateMachineState interface {
  50. ServiceTaskState
  51. }
  52. type CompensateSubStateMachineStateImpl struct {
  53. *ServiceTaskStateImpl
  54. hashcode string
  55. }
  56. func NewCompensateSubStateMachineStateImpl() *CompensateSubStateMachineStateImpl {
  57. uuid := uuid.New()
  58. c := &CompensateSubStateMachineStateImpl{
  59. ServiceTaskStateImpl: NewServiceTaskStateImpl(),
  60. hashcode: uuid.String(),
  61. }
  62. c.SetType(constant.StateTypeCompensateSubMachine)
  63. return c
  64. }
  65. func (c *CompensateSubStateMachineStateImpl) Hashcode() string {
  66. return c.hashcode
  67. }
  68. func (c *CompensateSubStateMachineStateImpl) SetHashcode(hashcode string) {
  69. c.hashcode = hashcode
  70. }