View Javadoc

1   /*
2    * $Id: ContinuousPollingReceiverWorker.java 21563 2011-03-14 10:05:09Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport;
12  
13  
14  /**
15   * Bypass the regular scheduling mechanism in order to minimize latency and maximize
16   * throughput for transports which have low or no cost for performing a poll operation 
17   * (such as an in-memory queue).
18   */
19  public class ContinuousPollingReceiverWorker extends PollingReceiverWorker
20  {
21      public ContinuousPollingReceiverWorker(AbstractPollingMessageReceiver pollingMessageReceiver)
22      {
23          super(pollingMessageReceiver);
24      }
25  
26      @Override
27      protected void poll() throws Exception
28      {
29          /*
30           * We simply run our own polling loop all the time as long as the receiver is started. The
31           * blocking wait defined by Connector.getQueueTimeout() will prevent this worker's receiver
32           * thread from busy-waiting.
33           */
34          while (getReceiver().isStarted() && !getReceiver().isStopping())
35          {
36              super.poll();
37          }
38      }
39  }