🎈LiteflowResponse object
In the return of the executor, the most used is to return a LiteFlowResponse
object.
This object contains a lot of result data and process data.
# Whether the process was executed successfully
You can determine whether a process is successfully executed by the following methods:
LiteflowResponse response = flowExecutor.execute2Resp("chain1", parameters, CustomContext.class);
boolean isSuccess = response.isSuccess();
# Get exception information
If a process isSuccess is false, there must be exception information. You can get the exception by the following methods:
LiteflowResponse response = flowExecutor.execute2Resp("chain1", parameters, CustomContext.class);
if (!response.isSuccess()){
Exception e = response.getCause();
}
For the explanation of the exception, please refer to the chapter Exceptions.
# Get execution step details
The result information also encapsulates the details of each step of the process execution, you can get it through this method:
LiteflowResponse response = flowExecutor.execute2Resp("chain1", parameter, CustomContext.class);
Map<String, CmpStep> stepMap = response.getExecuteSteps();
You can also get a queue in this way:
LiteflowResponse response = flowExecutor.execute2Resp("chain1", parameter, CustomContext.class);
Queue<CmpStep> stepQueue = response.getExecuteStepQueue();
Please refer to Step Information for the difference between the above two methods and the details of the step information.
# Get data context
The chain reads and writes context data during execution. The return data of a process should also be included in the context.
After you get the LiteFlowResponse
object, you can get the context bean like this:
LiteflowResponse response = flowExecutor.execute2Resp("chain1", parameter, CustomContext.class);
CustomContext context = response.getContextBean(CustomContext.class);
//For a response with only one context, the following sentence is also equivalent
//CustomContext context = response.getFirstContextBean();
The same is true for multiple contexts:
LiteflowResponse response = flowExecutor.execute2Resp("chain1", parameter, OrderContext.class, UserContext.class);
OrderContext orderContext = response.getContextBean(OrderContext.class);
UserContext userContext = response.getContextBean(UserContext.class);
# Get step string info
Get string assembly information for component step:
LiteflowResponse response = flowExecutor.execute2Resp("chain1", parameter, CustomContext.class);
String stepStr = response.getExecuteStepStrWithTime();
This string prints out as follows:
a[CmpA]<201>==>b[CmpB]<300>==>m[CmpM]<1205>
The expression here is component ID[component alias]<time-consuming milliseconds>
. For how to set component aliases, please refer to Component Aliases.
The getExecuteStepStrWithoutTime
method is also provided in the Response object, which is used to return a step string without time-consuming.
tip
In fact, the framework automatically prints this step string after each process execution, so you don't need to get the print yourself.
Here is just how to get it. If you want to persist it, you can get it like this.