001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel;
018
019import java.util.Queue;
020
021/**
022 * A consumer of a batch of message exchanges from an {@link Endpoint}
023 *
024 * @version 
025 */
026public interface BatchConsumer extends Consumer {
027
028    /**
029     * Sets a maximum number of messages as a limit to poll at each polling.
030     * <p/>
031     * Can be used to limit e.g. to 100 to avoid reading thousands or more 
032     * messages within the first polling at startup.
033     * <p/>
034     * Is default unlimited, but use 0 or negative number to disable it as unlimited.
035     *
036     * @param maxMessagesPerPoll  maximum messages to poll.
037     */
038    void setMaxMessagesPerPoll(int maxMessagesPerPoll);
039
040    /**
041     * Processes the list of {@link org.apache.camel.Exchange} objects in a batch. 
042     * <p/>
043     * Each message exchange will be processed individually but the batch
044     * consumer will add properties with the current index and total in the batch.
045     * The items in the Queue may actually be Holder objects that store other 
046     * data alongside the Exchange.
047     *
048     * @param exchanges list of items in this batch
049     * @return number of messages actually processed
050     * @throws Exception if an internal processing error has occurred.
051     */
052    int processBatch(Queue<Object> exchanges) throws Exception;
053
054    /**
055     * Whether processing the batch is still allowed.
056     * <p/>
057     * This is used during shutdown to indicate whether to complete the pending
058     * exchanges or stop after the current exchange has been processed.
059     *
060     * @return <tt>true</tt> to continue processing from the batch, or <tt>false</tt> to stop.
061     * @see org.apache.camel.ShutdownRunningTask
062     */
063    boolean isBatchAllowed();
064}