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 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 */ 031public interface PollingConsumer extends Consumer { 032 033 /** 034 * Waits until a message is available and then returns it. Warning that this 035 * method could block indefinitely if no messages are available. 036 * <p/> 037 * Will return <tt>null</tt> if the consumer is not started 038 * <p/> 039 * <b>Important: </b> See the class javadoc about the need for done the {@link org.apache.camel.spi.UnitOfWork} 040 * on the returned {@link Exchange} 041 * 042 * @return the message exchange received. 043 */ 044 Exchange receive(); 045 046 /** 047 * Attempts to receive a message exchange immediately without waiting and 048 * returning <tt>null</tt> if a message exchange is not available yet. 049 * <p/> 050 * <b>Important: </b> See the class javadoc about the need for done the {@link org.apache.camel.spi.UnitOfWork} 051 * on the returned {@link Exchange} 052 * 053 * @return the message exchange if one is immediately available otherwise 054 * <tt>null</tt> 055 */ 056 Exchange receiveNoWait(); 057 058 /** 059 * Attempts to receive a message exchange, waiting up to the given timeout 060 * to expire if a message is not yet available. 061 * <p/> 062 * <b>Important: </b> See the class javadoc about the need for done the {@link org.apache.camel.spi.UnitOfWork} 063 * on the returned {@link Exchange} 064 * 065 * @param timeout the amount of time in milliseconds to wait for a message 066 * before timing out and returning <tt>null</tt> 067 * 068 * @return the message exchange if one was available within the timeout 069 * period, or <tt>null</tt> if the timeout expired 070 */ 071 Exchange receive(long timeout); 072}