use of com.shulie.instrument.simulator.api.ProcessControlEntity in project LinkAgent by shulieTech.
the class EventListenerHandler method handleEvent.
/**
* 调用出发事件处理&调用执行流程控制
*
* @param listenerId 处理器ID
* @param processId 调用过程ID
* @param invokeId 调用ID
* @param event 调用事件
* @param processor 事件处理器
* @return 处理返回结果
* @throws Throwable 当出现未知异常时,且事件处理器为中断流程事件时抛出
*/
private final Result handleEvent(final int listenerId, final int processId, final int invokeId, final Class clazz, final Event event, final InvokeProcessor processor) throws Throwable {
final EventListener listener = processor.listener;
/**
* 如果当前事件不在事件监听器处理列表中,则直接返回,不处理事件
*/
if (!ArrayUtils.contains(processor.eventEventTypes, event.getType())) {
return Result.RESULT_NONE;
}
try {
if (isDebugEnabled) {
logger.debug("SIMULATOR: on-event: event -> eventType={}, processId={}, invokeId={}, listenerId={}", event.getType(), processId, invokeId, listenerId);
}
/**
* 调用事件处理
*/
ProcessControlEntity pce = listener.onEvent(event);
int state = pce.getState();
if (state != ProcessControlEntity.NONE_IMMEDIATELY) {
return processInterrupt(listenerId, processId, invokeId, clazz, event, processor, pce);
}
} catch (ProcessControlException pce) {
return processInterrupt(listenerId, processId, invokeId, clazz, event, processor, pce.toEntity());
} catch (Throwable throwable) {
/**
* 如果当前事件处理器是可中断的事件处理器,则对外抛出UnCaughtException
* 中断当前方法
*/
if (ReflectUtils.isInterruptEventHandler(listener)) {
throw throwable;
} else {
/**
* 普通事件处理器则可以打个日志后,直接放行
*/
ExceptionHandler exceptionHandler = getExceptionHandler();
if (exceptionHandler != null) {
exceptionHandler.handleException(throwable, String.format("on-event: event -> eventType=%s, processId=%s, invokeId=%s, listenerId=%s occur an error.", EventType.name(event.getType()), processId, invokeId, listenerId), listener);
} else {
logger.warn("SIMULATOR: on-event: event -> eventType={}, processId={}, invokeId={}, listenerId={} occur an " + "error.", event.getType(), processId, invokeId, listenerId, throwable);
}
}
}
/**
* 默认返回不进行任何流程变更
*/
return Result.RESULT_NONE;
}
Aggregations