flow - 链执行的拦截器
在流引擎身上附加拦截器,可实现计时、异常控制、上下文参数调整等。
1、使用示例
组件注解模式
@Component
public class ChainInterceptorImpl implements ChainInterceptor {
static Logger log = LoggerFactory.getLogger(ChainInterceptorImpl.class);
@Override
public void doIntercept(ChainInvocation inv) throws Throwable {
long start = System.currentTimeMillis();
try {
inv.invoke();
} catch (Throwable ex) {
log.error("Chain eval failure: " + inv.getStartNode().chain().id(), ex);
} finally {
long end = System.currentTimeMillis();
System.out.println(end - start);
}
}
}
原生 java 模式:
flowEngine.addInterceptor(new ChainInterceptorImpl());
2、ChainInterceptor 接口参考
public interface ChainInterceptor {
/**
* 拦截
*
* @param invocation 调用者
*/
void doIntercept(ChainInvocation invocation) throws Throwable;
}