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 *
024 * @version $Revision: 738604 $
025 */
026 public interface PollingConsumer extends Consumer {
027
028 /**
029 * Waits until a message is available and then returns it. Warning that this
030 * method could block indefinitely if no messages are available.
031 * <p/>
032 * Will return <tt>null</tt> if the consumer is not started
033 *
034 * @return the message exchange received.
035 */
036 Exchange receive();
037
038 /**
039 * Attempts to receive a message exchange immediately without waiting and
040 * returning <tt>null</tt> if a message exchange is not available yet.
041 *
042 * @return the message exchange if one is immediately available otherwise
043 * <tt>null</tt>
044 */
045 Exchange receiveNoWait();
046
047 /**
048 * Attempts to receive a message exchange, waiting up to the given timeout
049 * to expire if a message is not yet available
050 *
051 * @param timeout the amount of time in milliseconds to wait for a message
052 * before timing out and returning <tt>null</tt>
053 *
054 * @return the message exchange if one iwas available within the timeout
055 * period, or <tt>null</tt> if the timeout expired
056 */
057 Exchange receive(long timeout);
058 }