@Override publicbooleancanPass(Node node, int acquireCount, boolean prioritized) { //获取当前node节点的线程数或者请求通过的qps总数 // 获取当前时间窗已经统计的数据 intcurCount= avgUsedTokens(node); //当前请求数(请求的令牌)+申请总数是否(已经消耗的令牌)>该资源配置的总数(阈值) // 以前的数据+新的数据 if (curCount + acquireCount > count) { if (prioritized && grade == RuleConstant.FLOW_GRADE_QPS) { long currentTime; long waitInMs; currentTime = TimeUtil.currentTimeMillis(); waitInMs = node.tryOccupyNext(currentTime, acquireCount, count); if (waitInMs < OccupyTimeoutProperty.getOccupyTimeout()) { node.addWaitingRequest(currentTime + waitInMs, acquireCount); node.addOccupiedPass(acquireCount); sleep(waitInMs);
// PriorityWaitException indicates that the request will pass after waiting for {@link @waitInMs}. thrownewPriorityWaitException(waitInMs); } } returnfalse; } returntrue; }