Skip to content

Commit

Permalink
fix 拦截器点击第10次无效 alibaba#893
Browse files Browse the repository at this point in the history
优化:当Interceptor的process未回调onContinue或者onInterrupt时,框架默认让拦截链继续下去。防止CountDownLatch始终未到0,线程必须等待300s超时,防止线程池等待队列满掉。
  • Loading branch information
yongjun310 committed Jan 21, 2021
1 parent 38c0eea commit 5c9b33d
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public void run() {
private static void _execute(final int index, final CancelableCountDownLatch counter, final Postcard postcard) {
if (index < Warehouse.interceptors.size()) {
IInterceptor iInterceptor = Warehouse.interceptors.get(index);
long curCount = counter.getCount();
iInterceptor.process(postcard, new InterceptorCallback() {
@Override
public void onContinue(Postcard postcard) {
// Last interceptor excute over with no exception.
counter.countDown();
_execute(index + 1, counter, postcard); // When counter is down, it will be execute continue ,but index bigger than interceptors size, then U know.
countDownAndContinue(index, counter, postcard);
}

@Override
Expand All @@ -96,9 +96,24 @@ public void onInterrupt(Throwable exception) {
// }
}
});
if (curCount == counter.getCount()) {
countDownAndContinue(index, counter, postcard);
}
}
}

/**
* continue execute interceptor
*
* @param index current interceptor index
* @param counter interceptor counter
* @param postcard routeMeta
*/
private static void countDownAndContinue(int index, CancelableCountDownLatch counter, Postcard postcard) {
counter.countDown();
_execute(index + 1, counter, postcard); // When counter is down, it will be execute continue ,but index bigger than interceptors size, then U know.
}

@Override
public void init(final Context context) {
LogisticsCenter.executor.execute(new Runnable() {
Expand Down

0 comments on commit 5c9b33d

Please sign in to comment.