Camel - DefaultAsyncProcessorAwaitManager

DefaultAsyncProcessorAwaitManager

主要用于路由异步处理时,等待另一个线程处理结束后,继续后续处理。

等待过程中,会择机执行积压任务。

如果当前任务一直被阻塞,会记录阻塞信息,并记录阻塞时间、总阻塞时间、最短阻塞时间、最长阻塞时间,阻塞中位数等信息。

AsyncProcessAwaitManager utilization[blocked=%s, interrupted=%s, total=%s min=%s, max=%s, mean=%s]

org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager#await

public void await(Exchange exchange, CountDownLatch latch) {
 ReactiveExecutor reactiveExecutor = exchange.getContext().adapt(ExtendedCamelContext.class).getReactiveExecutor();
 // Early exit for pending reactive queued work
 do {
     if (latch.getCount() <= 0) {
         return;
     }
 } while (reactiveExecutor.executeFromQueue());

 if (LOG.isTraceEnabled()) {
     LOG.trace("Waiting for asynchronous callback before continuing for exchangeId: {} -> {}",
             exchange.getExchangeId(), exchange);
 }
 try {
     if (statistics.isStatisticsEnabled()) {
         blockedCounter.incrementAndGet();
     }
     inflight.put(exchange, new AwaitThreadEntry(Thread.currentThread(), exchange, latch));
     latch.await();
     if (LOG.isTraceEnabled()) {
         LOG.trace("Asynchronous callback received, will continue routing exchangeId: {} -> {}",
                 exchange.getExchangeId(), exchange);
     }

 } catch (InterruptedException e) {
     if (LOG.isTraceEnabled()) {
         LOG.trace("Interrupted while waiting for callback, will continue routing exchangeId: {} -> {}",
                 exchange.getExchangeId(), exchange);
     }
     exchange.setException(e);
 } finally {
     AwaitThread thread = inflight.remove(exchange);

     if (statistics.isStatisticsEnabled() && thread != null) {
         long time = thread.getWaitDuration();
         long total = totalDuration.get() + time;
         totalDuration.set(total);

         if (time < minDuration.get()) {
             minDuration.set(time);
         } else if (time > maxDuration.get()) {
             maxDuration.set(time);
         }

         // update mean
         long count = blockedCounter.get();
         long mean = count > 0 ? total / count : 0;
         meanDuration.set(mean);
     }
 }
}

参考

AsyncProcessorAwaitManager

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值