/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.impl;

import java.util.concurrent.ScheduledExecutorService;

import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.PollingConsumer;
import org.apache.camel.Processor;
import org.apache.camel.util.ServiceHelper;

/**
 * A default implementation of an event driven {@link org.apache.camel.Consumer} which uses the
 * {@link PollingConsumer}
 *
 * @version 
 */
public class DefaultScheduledPollConsumer extends ScheduledPollConsumer {
    private PollingConsumer pollingConsumer;

    public DefaultScheduledPollConsumer(DefaultEndpoint defaultEndpoint, Processor processor) {
        super(defaultEndpoint, processor);
    }

    public DefaultScheduledPollConsumer(Endpoint endpoint, Processor processor, ScheduledExecutorService executor) {
        super(endpoint, processor, executor);
    }

    protected int poll() throws Exception {
        int messagesPolled = 0;

        while (isPollAllowed()) {
            Exchange exchange = pollingConsumer.receiveNoWait();
            if (exchange == null) {
                break;
            }

            messagesPolled++;
            log.trace("Polled {} {}", messagesPolled, exchange);

            // if the result of the polled exchange has output we should create a new exchange and
            // use the output as input to the next processor
            if (exchange.hasOut()) {
                // lets create a new exchange
                Exchange newExchange = getEndpoint().createExchange();
                newExchange.getIn().copyFrom(exchange.getOut());
                exchange = newExchange;
            }
            getProcessor().process(exchange);
        }

        return messagesPolled;
    }

    @Override
    protected void doStart() throws Exception {
        pollingConsumer = getEndpoint().createPollingConsumer();
        ServiceHelper.startService(pollingConsumer);
        super.doStart();
    }

    @Override
    protected void doStop() throws Exception {
        ServiceHelper.stopService(pollingConsumer);
        super.doStop();
    }
}

@@ -1338,16 +1338,41 @@
 onsumer;
+%0A    private int timeout;
 %0A%0A    pu
@@ -1825,43 +1825,290 @@
 ange
- = pollingConsumer.receiveNoWait();
+;%0A            if (timeout == 0) %7B%0A                exchange = pollingConsumer.receiveNoWait();%0A            %7D else if (timeout %3C 0) %7B%0A                exchange = pollingConsumer.receive();%0A            %7D else %7B%0A                exchange = pollingConsumer.receive(timeout);%0A            %7D%0A
 %0A   
@@ -2756,32 +2756,32 @@
 ge);%0A        %7D%0A%0A
-
         return m
@@ -2794,32 +2794,602 @@
 sPolled;%0A    %7D%0A%0A
+    public int getTimeout() %7B%0A        return timeout;%0A    %7D%0A%0A    /**%0A     * Sets a timeout to use with %7B@link PollingConsumer%7D.%0A     * %3Cbr/%3E%0A     * %3Cbr/%3EUse %3Ctt%3Etimeout %3C 0%3C/tt%3E for %7B@link PollingConsumer#receive()%7D.%0A     * %3Cbr/%3EUse %3Ctt%3Etimeout == 0%3C/tt%3E for %7B@link PollingConsumer#receiveNoWait()%7D.%0A     * %3Cbr/%3EUse %3Ctt%3Etimeout %3E 0%3C/tt%3E for %7B@link PollingConsumer#receive(long)%7D%7D.%0A     * %3Cbr/%3E The default timeout value is %3Ctt%3E0%3C/tt%3E%0A     *%0A     * @param timeout the timeout value%0A     */%0A    public void setTimeout(int timeout) %7B%0A        this.timeout = timeout;%0A    %7D%0A%0A
     @Override%0A  

Allow component developers to set a timeout for default scheduled poll consumer