/'
    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
  '/
/` java -jar plantuml.jar participant-state-model.txt `/
@startuml
[*] --> NotEnlisted

state "NotEnlisted" as NotEnlisted
NotEnlisted : "The participant is not\n associated with any LRA"

state NotEnlisted {
  NotEnlisted --> Enlisted : joinLRA
  Enlisted --> NotEnlisted : completed
  Enlisted --> NotEnlisted : compensated
  Enlisted --> NotEnlisted : forget
  Enlisted --> NotEnlisted : leave
}

state Enlisted {
  [*] --> Active : join
  Active : "The participant has joined the LRA and has not yet been asked to compensate or complete"
  note left of Active : initial state
  Active --> Compensating : compensate
  state "FailedToCompensate" as FailedToCompensate
  FailedToCompensate : "Must wait for the\n forget message"
  state "FailedToComplete" as CannotComplete
  CannotComplete : "Must wait for the\n forget message"
  state "Compensating" as Compensating
  Compensating : "The participant was\nnotified that the\nLRA was cancelled"
  state "Completing" as Completing
  Completing : "The participant was\nnotified that the\nLRA was closed"
  state "Completed" as Completed
  Completed : "Participant can now clean up and forget\nthe LRA or must wait for forget message\nif enlisted in nested LRA"
  state "Compensated" as Compensated
  Compensated : "Participant can now clean up\nand forget the LRA"

  Compensating --> Compensated
  Compensating --> FailedToCompensate

  Active --> Completing : complete
  Completing --> Completed
  Completing --> CannotComplete
  
  Completed --> Compensating : compensate (transition is only allowed \nif the participant is enlisted in nested LRA)
}
@enduml