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     */
017    package org.apache.camel;
018    
019    /**
020     * Represents a <a
021     * href="http://camel.apache.org/polling-consumer.html">Polling
022     * Consumer</a> where the caller polls for messages when it is ready.
023     * <p/>
024     * When you are done with the returned {@link Exchange} you must ensure to invoke
025     * {@link org.apache.camel.spi.UnitOfWork#done(Exchange)} to signal to Camel that the {@link Exchange} is done.
026     * <p/>
027     * This is needed to ensure any {@link org.apache.camel.spi.Synchronization} works is being executed.
028     * For example if you consumed from a file endpoint, then the consumed file is only moved/delete when
029     * you done the {@link Exchange}.
030     *
031     * @version 
032     */
033    public interface PollingConsumer extends Consumer {
034    
035        /**
036         * Waits until a message is available and then returns it. Warning that this
037         * method could block indefinitely if no messages are available.
038         * <p/>
039         * Will return <tt>null</tt> if the consumer is not started
040         * <p/>
041         * <b>Important: </b> See the class javadoc about the need for done the {@link org.apache.camel.spi.UnitOfWork}
042         * on the returned {@link Exchange}
043         *
044         * @return the message exchange received.
045         */
046        Exchange receive();
047    
048        /**
049         * Attempts to receive a message exchange immediately without waiting and
050         * returning <tt>null</tt> if a message exchange is not available yet.
051         * <p/>
052         * <b>Important: </b> See the class javadoc about the need for done the {@link org.apache.camel.spi.UnitOfWork}
053         * on the returned {@link Exchange}
054         *
055         * @return the message exchange if one is immediately available otherwise
056         *         <tt>null</tt>
057         */
058        Exchange receiveNoWait();
059    
060        /**
061         * Attempts to receive a message exchange, waiting up to the given timeout
062         * to expire if a message is not yet available.
063         * <p/>
064         * <b>Important: </b> See the class javadoc about the need for done the {@link org.apache.camel.spi.UnitOfWork}
065         * on the returned {@link Exchange}
066         * 
067         * @param timeout the amount of time in milliseconds to wait for a message
068         *                before timing out and returning <tt>null</tt>
069         * 
070         * @return the message exchange if one iwas available within the timeout
071         *         period, or <tt>null</tt> if the timeout expired
072         */
073        Exchange receive(long timeout);
074    }