Jira |
---|
server | ONAP Jira |
---|
serverId | 425b2b0a-557c-3c0c-b515-579789cceedb |
---|
key | CPS-875 |
---|
|
State Machine
State Machines are a model used in computing to define the current state of the system, and the possible next state which it may transition to.
...
Code Block |
---|
language | java |
---|
title | State Machine Transition |
---|
linenumbers | true |
---|
|
public enum CmHandleState {
Advised {
@Override
public CmHandleState nextState() {
return Locked;
}
@Override
public String cmHandleState() {
return "ADVISED";
}
},
Locked {
@Override
public CmHandleState nextState() {
return Ready;
}
@Override
public String cmHandleState() {
return "LOCKED";
}
},
Ready {
@Override
public CmHandleState nextState() {
return this;
}
@Override
public String cmHandleState() {
return "LOCKEDREADY";
}
};
public abstract CmHandleState nextState();
public abstract String cmHandleState(); |
...
- Easy to Implement
- Can provide the logic for the transition implementation without having to explicitly state it.
- Cleaner and Easier to read which states can be transitioned to other states.
- Easily extendable if future states are to be added.
Disadvantages
- Due to how state machine works, transitions are pre defined between states, based on the diagram here (CPS-799 Spike: Define states and state handling for CM handle), "LOCKED" and "DELETED" states can be accessed from multiple previous states. Meaning they may have to be defined explicitly to jump between these states. Defeating the main purpose of implementing the state machine.