use of com.alibaba.android.arouter.facade.template.IInterceptor in project ARouter by alibaba.
the class InterceptorServiceImpl method _excute.
/**
* Excute interceptor
*
* @param index current interceptor index
* @param counter interceptor counter
* @param postcard routeMeta
*/
private static void _excute(final int index, final CancelableCountDownLatch counter, final Postcard postcard) {
if (index < Warehouse.interceptors.size()) {
IInterceptor iInterceptor = Warehouse.interceptors.get(index);
iInterceptor.process(postcard, new InterceptorCallback() {
@Override
public void onContinue(Postcard postcard) {
// Last interceptor excute over with no exception.
counter.countDown();
// When counter is down, it will be execute continue ,but index bigger than interceptors size, then U know.
_excute(index + 1, counter, postcard);
}
@Override
public void onInterrupt(Throwable exception) {
// Last interceptor excute over with fatal exception.
// save the exception message for backup.
postcard.setTag(null == exception ? new HandlerException("No message.") : exception.getMessage());
counter.cancel();
// Be attention, maybe the thread in callback has been changed,
// then the catch block(L207) will be invalid.
// The worst is the thread changed to main thread, then the app will be crash, if you throw this exception!
// if (!Looper.getMainLooper().equals(Looper.myLooper())) { // You shouldn't throw the exception if the thread is main thread.
// throw new HandlerException(exception.getMessage());
// }
}
});
}
}
Aggregations