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.spi;
018
019 import org.apache.camel.Consumer;
020 import org.apache.camel.Endpoint;
021
022 /**
023 * Strategy for a {@link org.apache.camel.PollingConsumer} when polling an {@link org.apache.camel.Endpoint}.
024 * <p/>
025 * This pluggable strategy allows to plugin different implementations what to do, most noticeable what to
026 * do in case the polling goes wrong. This can be handled in the
027 * {@link #rollback(org.apache.camel.Consumer , org.apache.camel.Endpoint , int, Exception) rollback} method.
028 *
029 * @version $Revision: 830197 $
030 */
031 public interface PollingConsumerPollStrategy {
032
033 /**
034 * Called when poll is about to begin
035 *
036 * @param consumer the consumer
037 * @param endpoint the endpoint being consumed
038 */
039 void begin(Consumer consumer, Endpoint endpoint);
040
041 /**
042 * Called when poll is completed successfully
043 *
044 * @param consumer the consumer
045 * @param endpoint the endpoint being consumed
046 */
047 void commit(Consumer consumer, Endpoint endpoint);
048
049 /**
050 * Called when poll failed
051 *
052 * @param consumer the consumer
053 * @param endpoint the endpoint being consumed
054 * @param retryCounter current retry attempt, starting from 0.
055 * @param cause the caused exception
056 * @throws Exception can be used to rethrow the caused exception. Notice that thrown an exception will
057 * terminate the scheduler and thus Camel will not trigger again. So if you want to let the scheduler
058 * to continue to run then do <b>not</b> throw any exception from this method.
059 * @return whether to retry immediately or not. Return <tt>false</tt> to ignore the problem,
060 * <tt>true</tt> to try immediately again
061 */
062 boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception cause) throws Exception;
063
064 }