001    /**
002     *
003     * Licensed to the Apache Software Foundation (ASF) under one or more
004     * contributor license agreements.  See the NOTICE file distributed with
005     * this work for additional information regarding copyright ownership.
006     * The ASF licenses this file to You under the Apache License, Version 2.0
007     * (the "License"); you may not use this file except in compliance with
008     * the License.  You may obtain a copy of the License at
009     *
010     * http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    package org.apache.camel;
019    
020    /**
021     * Represents a <a href="http://activemq.apache.org/camel/polling-consumer.html">Polling Consumer</a> where the caller
022     * polls for messages when it is ready.
023     * 
024     * @version $Revision: 1.1 $
025     */
026    public interface PollingConsumer<E extends Exchange> extends Consumer<E> {
027        
028        /**
029         * Waits until a message is available and then returns it. Warning that this method
030         * could block indefinitely if no messages are available.
031         *
032         * @return the message exchange received.
033         */
034        E receive();
035    
036        /**
037         * Attempts to receive a message exchange immediately without waiting
038         * and returning null if a message exchange is not available yet.
039         *
040         * @return the message exchange if one is immediately available otherwise null
041         */
042        E receiveNoWait();
043    
044        /**
045         * Attempts to receive a message exchange, waiting up to the given timeout to expire
046         * if a message is not yet available
047         *
048         * @param timeout the amount of time in milliseconds to wait for a message before timing out and
049         * returning null
050         *
051         * @return the message exchange if one iwas available within the timeout period, or null if the timeout expired
052         */
053        E receive(long timeout);
054    
055    }