/'
    Copyright (c) 2018 Contributors to the Eclipse Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
 
        http://www.apache.org/licenses/LICENSE-2.0
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

   Source for this PlantUML state diagram
   see plantuml.com
  '/
@startuml

@startuml
[*] --> NoLRAContext

state "NoLRAContext" as NoLRAContext
NoLRAContext : "There is no active LRA context"

state NoLRAContext {
  NoLRAContext --> LRAContext : startLRA
  LRAContext --> NoLRAContext : cancel failed
  LRAContext --> NoLRAContext : cancelled
  LRAContext --> NoLRAContext : close failed
  LRAContext --> NoLRAContext : closed
}

state LRAContext {
  [*] --> ActiveLRA : startLRA
  ActiveLRA : "LRA exists and has not yet been asked to close or cancel"
  note left of ActiveLRA : initial state
  ActiveLRA --> Cancelling : cancel
  state "FailedToCancel" as FailedToCancel
  FailedToCancel : "One or more participants\ndid not compensate"
  state "Cancelling" as Cancelling
  Cancelling : "One or more participants\nare still compensating"
  state "Closing" as Closing
  Closing : "One or more participants\nare still completing"
  state "Closed" as Closed
  Closed : "All participants\nhave completed"
  state "FailedToClose" as FailedToClose
  FailedToClose : "One or more participants\ndid not complete"
  state "Cancelled" as Cancelled
  Cancelled : "All participants\nhave compensated"

  Cancelling --> Cancelled
  Cancelling --> FailedToCancel

  ActiveLRA --> Closing : close
  Closing --> Closed
  Closing --> FailedToClose

  Closed --> Cancelling : cancel (transition is only allowed if LRA is nested)
}
@enduml