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://activemq.apache.org/camel/polling-consumer.html">Polling
022 * Consumer</a> where the caller polls for messages when it is ready.
023 *
024 * @version $Revision: 630591 $
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
030 * method 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 and
038 * returning null if a message exchange is not available yet.
039 *
040 * @return the message exchange if one is immediately available otherwise
041 * null
042 */
043 E receiveNoWait();
044
045 /**
046 * Attempts to receive a message exchange, waiting up to the given timeout
047 * to expire if a message is not yet available
048 *
049 * @param timeout the amount of time in milliseconds to wait for a message
050 * before timing out and returning null
051 *
052 * @return the message exchange if one iwas available within the timeout
053 * period, or null if the timeout expired
054 */
055 E receive(long timeout);
056
057 }