-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
467 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package io.xdb.core.state; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import io.xdb.core.utils.ProcessUtil; | ||
import io.xdb.gen.models.ThreadCloseDecision; | ||
import io.xdb.gen.models.ThreadCloseType; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
public class StateDecision { | ||
|
||
// directly return stateDecision if it presents | ||
private final io.xdb.gen.models.StateDecision stateDecision; | ||
private final List<StateMovement> nextStates; | ||
|
||
public static StateDecision deadEnd() { | ||
return StateDecision | ||
.builder() | ||
.stateDecision( | ||
new io.xdb.gen.models.StateDecision() | ||
.threadCloseDecision(new ThreadCloseDecision().closeType(ThreadCloseType.DEAD_END)) | ||
) | ||
.build(); | ||
} | ||
|
||
public static StateDecision gracefulCompleteProcess() { | ||
return StateDecision | ||
.builder() | ||
.stateDecision( | ||
new io.xdb.gen.models.StateDecision() | ||
.threadCloseDecision(new ThreadCloseDecision().closeType(ThreadCloseType.GRACEFUL_COMPLETE_PROCESS)) | ||
) | ||
.build(); | ||
} | ||
|
||
public static StateDecision forceCompleteProcess() { | ||
return StateDecision | ||
.builder() | ||
.stateDecision( | ||
new io.xdb.gen.models.StateDecision() | ||
.threadCloseDecision(new ThreadCloseDecision().closeType(ThreadCloseType.FORCE_COMPLETE_PROCESS)) | ||
) | ||
.build(); | ||
} | ||
|
||
public static StateDecision forceFailProcess() { | ||
return StateDecision | ||
.builder() | ||
.stateDecision( | ||
new io.xdb.gen.models.StateDecision() | ||
.threadCloseDecision(new ThreadCloseDecision().closeType(ThreadCloseType.FORCE_FAIL_PROCESS)) | ||
) | ||
.build(); | ||
} | ||
|
||
// TODO: option override | ||
public static StateDecision singleNextState(final Class<? extends AsyncState> stateClass, final Object stateInput) { | ||
final StateMovement stateMovement = StateMovement | ||
.builder() | ||
.stateId(ProcessUtil.getStateId(stateClass)) | ||
.stateInput(stateInput) | ||
.build(); | ||
return StateDecision.builder().nextStates(ImmutableList.of(stateMovement)).build(); | ||
} | ||
|
||
public static StateDecision singleNextState(final String stateId, final Object stateInput) { | ||
final StateMovement stateMovement = StateMovement.builder().stateId(stateId).stateInput(stateInput).build(); | ||
return StateDecision.builder().nextStates(ImmutableList.of(stateMovement)).build(); | ||
} | ||
|
||
public static StateDecision multipleNextStates(final Class<? extends AsyncState>... stateClasses) { | ||
final ArrayList<StateMovement> stateMovements = new ArrayList<>(); | ||
for (final Class<? extends AsyncState> stateClass : stateClasses) { | ||
stateMovements.add(StateMovement.builder().stateId(ProcessUtil.getStateId(stateClass)).build()); | ||
} | ||
return StateDecision.builder().nextStates(stateMovements).build(); | ||
} | ||
|
||
public static StateDecision multipleNextStates(final String... stateIds) { | ||
final ArrayList<StateMovement> stateMovements = new ArrayList<>(); | ||
for (final String stateId : stateIds) { | ||
stateMovements.add(StateMovement.builder().stateId(stateId).build()); | ||
} | ||
return StateDecision.builder().nextStates(stateMovements).build(); | ||
} | ||
|
||
public static StateDecision multipleNextStates(final StateMovement... stateMovements) { | ||
return StateDecision.builder().nextStates(Arrays.stream(stateMovements).collect(Collectors.toList())).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.xdb.core.state; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
public class StateMovement { | ||
|
||
private final String stateId; | ||
private final Object stateInput; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
package io.xdb.core.utils; | ||
|
||
// mainly to return default values for null cases | ||
import io.xdb.core.process.Process; | ||
import io.xdb.core.state.AsyncState; | ||
import io.xdb.gen.models.AsyncStateConfig; | ||
|
||
public class ProcessUtil { | ||
|
||
public static String getClassSimpleName(final Class<?> obejctClass) { | ||
return obejctClass.getSimpleName(); | ||
public static final String DEFAULT_NAMESPACE = "default"; | ||
|
||
public static String getProcessType(final Class<? extends Process> processClass) { | ||
return processClass.getSimpleName(); | ||
} | ||
|
||
public static String getStateId(final Class<? extends AsyncState> stateClass) { | ||
return stateClass.getSimpleName(); | ||
} | ||
|
||
public static AsyncStateConfig getAsyncStateConfig(final AsyncState state) { | ||
return new AsyncStateConfig().skipWaitUntil(AsyncState.shouldSkipWaitUntil(state)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.