Flowable源码地址:https://github.com/flowable/flowable-engine
Flowable-6.7.2 源码注释地址:https://github.com/solojin/flowable-6.7.2-annotated
事务监听器,包路径:org.flowable.common.engine.impl.cfg
TransactionListener 事务监听器
/**
* 事务监听器
*
* @author Tom Baeyens
*/
public interface TransactionListener {
void execute(CommandContext commandContext);
}
ExecuteExecutionListenerTransactionListener 执行监听器事务监听器
/**
* 执行监听器事务监听器
* 调用执行监听器{@link ExecutionListener}的事务监听器{@link TransactionListener}。
*
* @author Joram Barrez
*/
public class ExecuteExecutionListenerTransactionListener implements TransactionListener {
protected TransactionDependentExecutionListener listener;
protected TransactionDependentExecutionListenerExecutionScope scope;
protected CommandExecutor commandExecutor;
public ExecuteExecutionListenerTransactionListener(TransactionDependentExecutionListener listener,
TransactionDependentExecutionListenerExecutionScope scope, CommandExecutor commandExecutor) {
this.listener = listener;
this.scope = scope;
this.commandExecutor = commandExecutor;
}
@Override
public void execute(CommandContext commandContext) {
CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
commandExecutor.execute(commandConfig, new Command<Void>() {
@Override
public Void execute(CommandContext commandContext) {
listener.notify(scope.getProcessInstanceId(), scope.getExecutionId(), scope.getFlowElement(),
scope.getExecutionVariables(), scope.getCustomPropertiesMap());
return null;
}
});
}
}
ExecuteEventListenerTransactionListener 执行事件监听器事务监听器
/**
* 执行事件监听器事务监听器
*/
public class ExecuteEventListenerTransactionListener implements TransactionListener {
private static final Logger LOGGER = LoggerFactory.getLogger(ExecuteEventListenerTransactionListener.class);
protected FlowableEventListener listener;
protected FlowableEvent flowableEvent;
public ExecuteEventListenerTransactionListener(FlowableEventListener listener, FlowableEvent flowableEvent) {
this.listener = listener;
this.flowableEvent = flowableEvent;
}
@Override
public void execute(CommandContext commandContext) {
try {
listener.onEvent(flowableEvent);
} catch (Throwable t) {
if (listener.isFailOnException()) {
throw t;
} else {
// Ignore the exception and continue notifying remaining listeners. The listener
// explicitly states that the exception should not bubble up
LOGGER.warn("Exception while executing event-listener, which was ignored", t);
}
}
}
}
ExecuteTaskListenerTransactionListener 执行任务监听器事务监听器
/**
* 执行任务监听器事务监听器
* 调用执行监听器{@link ExecutionListener}的事务监听器{@link TransactionListener}。
*
* @author Joram Barrez
*/
public class ExecuteTaskListenerTransactionListener implements TransactionListener {
protected TransactionDependentTaskListener listener;
protected TransactionDependentTaskListenerExecutionScope scope;
protected CommandExecutor commandExecutor;
public ExecuteTaskListenerTransactionListener(TransactionDependentTaskListener listener,
TransactionDependentTaskListenerExecutionScope scope, CommandExecutor commandExecutor) {
this.listener = listener;
this.scope = scope;
this.commandExecutor = commandExecutor;
}
@Override
public void execute(CommandContext commandContext) {
CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
commandExecutor.execute(commandConfig, new Command<Void>() {
@Override
public Void execute(CommandContext commandContext) {
listener.notify(scope.getProcessInstanceId(), scope.getExecutionId(), scope.getTask(),
scope.getExecutionVariables(), scope.getCustomPropertiesMap());
return null;
}
});
}
}